コード例 #1
0
ファイル: AlphaChannels.cs プロジェクト: xiexin36/skimpt
        public AlphaChannels(ImageResource imgRes)
            : base(imgRes)
        {
            BinaryReverseReader reader = imgRes.DataReader;

            // the names are pascal strings without padding!!!
            while ((reader.BaseStream.Length - reader.BaseStream.Position) > 0)
            {
                byte   stringLength = reader.ReadByte();
                string s            = new string(reader.ReadChars(stringLength));
                if (s.Length > 0)
                {
                    m_channelNames.Add(s);
                }
            }
            reader.Close();
        }
コード例 #2
0
ファイル: ImageResource.cs プロジェクト: xiexin36/skimpt
        //////////////////////////////////////////////////////////////////

        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
ファイル: Layer.cs プロジェクト: SchwarzerLoewe/Paint
        public Layer(BinaryReverseReader reader, PsdFile psdFile)
        {
            Debug.WriteLine("Layer started at " + reader.BaseStream.Position.ToString());

            m_psdFile = psdFile;
            m_rect = new Rectangle();
            m_rect.Y = reader.ReadInt32();
            m_rect.X = reader.ReadInt32();
            m_rect.Height = reader.ReadInt32() - m_rect.Y;
            m_rect.Width = reader.ReadInt32() - m_rect.X;

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

            int numberOfChannels = reader.ReadUInt16();
            this.m_channels.Clear();
            for (int channel = 0; channel < numberOfChannels; channel++)
            {
                Channel ch = new Channel(reader, this);
                m_channels.Add(ch);
                m_sortedChannels.Add(ch.ID, ch);
            }

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

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

            m_blendModeKey = new string(reader.ReadChars(4));
            m_opacity = reader.ReadByte();

            m_clipping = reader.ReadByte() > 0;

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

            byte flags = reader.ReadByte();
            m_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;

            m_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;
        }
コード例 #4
0
ファイル: Layer.cs プロジェクト: SchwarzerLoewe/Paint
            internal Mask(BinaryReverseReader reader, Layer layer)
            {
                Debug.WriteLine("Mask started at " + reader.BaseStream.Position.ToString());

                m_layer = layer;

                uint maskLength = reader.ReadUInt32();

                if (maskLength <= 0)
                    return;

                long startPosition = reader.BaseStream.Position;

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

                m_rect = new Rectangle();
                m_rect.Y = reader.ReadInt32();
                m_rect.X = reader.ReadInt32();
                m_rect.Height = reader.ReadInt32() - m_rect.Y;
                m_rect.Width = reader.ReadInt32() - m_rect.X;

                m_defaultColor = reader.ReadByte();

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

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

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

                if (maskLength == 36)
                {
                    BitVector32 realFlags = new BitVector32(reader.ReadByte());

                    byte realUserMaskBackground = reader.ReadByte();

                    Rectangle rect = new Rectangle();
                    rect.Y = reader.ReadInt32();
                    rect.X = reader.ReadInt32();
                    rect.Height = reader.ReadInt32() - m_rect.Y;
                    rect.Width = reader.ReadInt32() - m_rect.X;
                }

                // there is other stuff following, but we will ignore this.
                reader.BaseStream.Position = startPosition + maskLength;
            }
コード例 #5
0
        public Layer(BinaryReverseReader reader, PsdFile psdFile)
        {
            Debug.WriteLine("Layer started at " + reader.BaseStream.Position.ToString());

            m_psdFile     = psdFile;
            m_rect        = new Rectangle();
            m_rect.Y      = reader.ReadInt32();
            m_rect.X      = reader.ReadInt32();
            m_rect.Height = reader.ReadInt32() - m_rect.Y;
            m_rect.Width  = reader.ReadInt32() - m_rect.X;

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

            int numberOfChannels = reader.ReadUInt16();

            this.m_channels.Clear();
            for (int channel = 0; channel < numberOfChannels; channel++)
            {
                Channel ch = new Channel(reader, this);
                m_channels.Add(ch);
                m_sortedChannels.Add(ch.ID, ch);
            }

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

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

            if (signature != "8BIM")
            {
                throw (new IOException("Layer Channelheader error!"));
            }

            m_blendModeKey = new string(reader.ReadChars(4));
            m_opacity      = reader.ReadByte();

            m_clipping = reader.ReadByte() > 0;

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

            byte flags = reader.ReadByte();

            m_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;

            m_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;
        }
コード例 #6
0
ファイル: ImageResource.cs プロジェクト: vantruc/skimpt
        //////////////////////////////////////////////////////////////////
        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();
        }
コード例 #7
0
ファイル: PSDFile.cs プロジェクト: SchwarzerLoewe/Paint
        /// <summary>Loads up the Layers of the supplied PSD file.</summary>      
        private void LoadLayers(BinaryReverseReader reader)
        {
            Debug.WriteLine("LoadLayers started at " + reader.BaseStream.Position.ToString());

            uint layersInfoSectionLength = reader.ReadUInt32();

            if (layersInfoSectionLength <= 0)
                return;

            long startPosition = reader.BaseStream.Position;

            short numberOfLayers = reader.ReadInt16();

            // If <0, then number of layers is absolute value,
            // and the first alpha channel contains the transparency data for
            // the merged result.
            if (numberOfLayers < 0)
            {
                AbsoluteAlpha = true;
                numberOfLayers = Math.Abs(numberOfLayers);
            }

            m_layers.Clear();

            if (numberOfLayers == 0)
                return;

            for (int i = 0; i < numberOfLayers; i++)
            {
                m_layers.Add(new Layer(reader, this));
            }

            foreach (Layer layer in m_layers)
            {
                foreach (Layer.Channel channel in layer.Channels)
                {
                    if (channel.ID != -2)
                        channel.LoadPixelData(reader);
                }
                layer.MaskData.LoadPixelData(reader);
            }

            if (reader.BaseStream.Position % 2 == 1)
                reader.ReadByte();

            // make sure we are not on a wrong offset, so set the stream position
            // manually
            reader.BaseStream.Position = startPosition + layersInfoSectionLength;
        }