コード例 #1
0
        public Layer(BinaryReverseReader reader, PsdFile psdFile)
        {
            Debug.WriteLine("Layer started at " + reader.BaseStream.Position.ToString());

            PsdFile = psdFile;
            Rect = new Rectangle
                       {
                           Y = reader.ReadInt32(),
                           X = reader.ReadInt32(),
                           Height = reader.ReadInt32() - Rect.Y,
                           Width = reader.ReadInt32() - Rect.X
                       };

            //-----------------------------------------------------------------------

            int numberOfChannels = reader.ReadUInt16();
            _channels.Clear();
            for (var channel = 0; channel < numberOfChannels; channel++)
            {
                var ch = new Channel(reader, this);
                _channels.Add(ch);
                _sortedChannels.Add(ch.Id, ch);
            }

            //-----------------------------------------------------------------------

            var signature = new string(reader.ReadChars(4));
            if (signature != "8BIM")
                throw (new IOException("Layer Channelheader error!"));

            _blendModeKey = new string(reader.ReadChars(4));
            Opacity = reader.ReadByte();

            Clipping = reader.ReadByte() > 0;

            //-----------------------------------------------------------------------

            byte flags = reader.ReadByte();
            _flags = new BitVector32(flags);

            //-----------------------------------------------------------------------

            reader.ReadByte(); //padding

            //-----------------------------------------------------------------------

            Debug.WriteLine("Layer extraDataSize started at " + reader.BaseStream.Position.ToString());

            // this is the total size of the MaskData, the BlendingRangesData, the
            // Name and the AdjustmenLayerInfo
            uint extraDataSize = reader.ReadUInt32();

            // remember the start position for calculation of the
            // AdjustmenLayerInfo size
            long extraDataStartPosition = reader.BaseStream.Position;

            m_maskData = new Mask(reader, this);
            m_blendingRangesData = new BlendingRanges(reader, this);

            //-----------------------------------------------------------------------

            long namePosition = reader.BaseStream.Position;

            Name = reader.ReadPascalString();

            int paddingBytes = (int)((reader.BaseStream.Position - namePosition) % 4);

            Debug.Print("Layer {0} padding bytes after name", paddingBytes);
            reader.ReadBytes(paddingBytes);

            //-----------------------------------------------------------------------

            m_adjustmentInfo.Clear();

            long adjustmenLayerEndPos = extraDataStartPosition + extraDataSize;
            while (reader.BaseStream.Position < adjustmenLayerEndPos)
            {
                try
                {
                    m_adjustmentInfo.Add(new AdjusmentLayerInfo(reader, this));
                }
                catch
                {
                    reader.BaseStream.Position = adjustmenLayerEndPos;
                }
            }

            //-----------------------------------------------------------------------
            // make shure we are not on a wrong offset, so set the stream position
            // manually
            reader.BaseStream.Position = adjustmenLayerEndPos;
        }
コード例 #2
0
        //////////////////////////////////////////////////////////////////
        public ImageResource(BinaryReverseReader reader)
        {
            m_osType = new string(reader.ReadChars(4));
            if (m_osType != "8BIM" && m_osType != "MeSa")
            {
                throw new InvalidOperationException("Could not read an image resource");
            }

            m_id = reader.ReadInt16();
            m_name = reader.ReadPascalString();

            uint settingLength = reader.ReadUInt32();
            m_data = reader.ReadBytes((int)settingLength);

            if (reader.BaseStream.Position % 2 == 1)
                reader.ReadByte();
        }
コード例 #3
0
            public AdjusmentLayerInfo(BinaryReverseReader reader, Layer layer)
            {
                Debug.WriteLine("AdjusmentLayerInfo started at " + reader.BaseStream.Position.ToString());

                m_layer = layer;

                string signature = new string(reader.ReadChars(4));
                if (signature != "8BIM")
                {
                    throw new IOException("Could not read an image resource");
                }

                m_key = new string(reader.ReadChars(4));

                uint dataLength = reader.ReadUInt32();
                m_data = reader.ReadBytes((int)dataLength);
            }
コード例 #4
0
        ///////////////////////////////////////////////////////////////////////////
        private void LoadHeader(BinaryReverseReader reader)
        {
            Debug.WriteLine("LoadHeader started at " + reader.BaseStream.Position.ToString());

              string signature = new string(reader.ReadChars(4));
              if (signature != "8BPS")
            throw new IOException("The given stream is not a valid PSD file");

              m_version = reader.ReadInt16();
              if (m_version != 1)
            throw new IOException("The PSD file has an unkown version");

              //6 bytes reserved
              reader.BaseStream.Position += 6;

              m_channels = reader.ReadInt16();
              m_rows = reader.ReadInt32();
              m_columns = reader.ReadInt32();
              m_depth = reader.ReadInt16();
              m_colorMode = (ColorModes)reader.ReadInt16();
        }