Example #1
0
        public Mask(BinaryPSDReader reader, Layer layer)
            : base(layer)
        {
            this._layer = layer;

            int nLength = (int)reader.ReadUInt32();
            if (nLength == 0)
                return;

            long nStart = reader.BaseStream.Position;

            this.Rectangle = reader.ReadPSDRectangle(); //new Rectangle(reader).ToERectangle();

            this._color = reader.ReadByte();

            this._flags = reader.ReadByte();

            if (nLength == 20)
                reader.ReadUInt16(); //padding
            else if (nLength == 36)
            {
                this._flags2 = reader.ReadByte();//same flags as above according to docs!?!?
                this._maskBg = reader.ReadByte(); //Real user mask background. Only 0 or 255 - ie bool?!?
                this._otherRectangle = reader.ReadPSDRectangle(); //new Rectangle(reader).ToERectangle(); //same as above rectangle according to docs?!?!
            }

            reader.BaseStream.Position = nStart + nLength;
        }
Example #2
0
        public Mask(BinaryPSDReader reader, Layer layer)
            : base(layer)
        {
            this._layer = layer;

            int nLength = (int)reader.ReadUInt32();

            if (nLength == 0)
            {
                return;
            }

            long nStart = reader.BaseStream.Position;

            this.Rectangle = reader.ReadPSDRectangle(); //new Rectangle(reader).ToERectangle();

            this._color = reader.ReadByte();

            this._flags = reader.ReadByte();

            if (nLength == 20)
            {
                reader.ReadUInt16(); //padding
            }
            else if (nLength == 36)
            {
                this._flags2         = reader.ReadByte();         //same flags as above according to docs!?!?
                this._maskBg         = reader.ReadByte();         //Real user mask background. Only 0 or 255 - ie bool?!?
                this._otherRectangle = reader.ReadPSDRectangle(); //new Rectangle(reader).ToERectangle(); //same as above rectangle according to docs?!?!
            }

            reader.BaseStream.Position = nStart + nLength;
        }
Example #3
0
        //public void AddChannel(Channel ch)
        //{
        //    this._channels.Add(ch.Usage, ch);
        //}

        public Layer(BinaryPSDReader reader, Document document)
        {
            this._document = document;

            this._rect = reader.ReadPSDRectangle();

            ushort numChannels = reader.ReadUInt16();

            this._channels = new Dictionary <int, Channel>();
            for (int channelNum = 0; channelNum < numChannels; channelNum++)
            {
                Channel ch = new Channel(reader, this);
                if (this._channels.ContainsKey(ch.Usage))
                {
                    continue; //TODO: !!
                }
                this._channels.Add(ch.Usage, ch);
            }

            string sHeader = new string(reader.ReadPSDChars(4));

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

            //'levl'=Levels 'curv'=Curves 'brit'=Brightness/contrast 'blnc'=Color balance 'hue '=Old Hue/saturation, Photoshop 4.0 'hue2'=New Hue/saturation, Photoshop 5.0 'selc'=Selective color 'thrs'=Threshold 'nvrt'=Invert 'post'=Posterize
            this.BlendKey = new string(reader.ReadPSDChars(4));
            int nBlend = -1;

            try
            {
                nBlend = (int)Enum.Parse(typeof(_blendKeysPsd), this.BlendKey);
            }
            catch
            {
                throw new Exception("Unknown blend key: " + this.BlendKey);
            }
            if (nBlend >= 0)
            {
                BlendKeys key = (BlendKeys)nBlend;
                this.BlendKey = Enum.GetName(typeof(BlendKeys), key);
            }

            this.Opacity  = reader.ReadByte();
            this.Clipping = reader.ReadByte();
            this.Flags    = reader.ReadByte();

            reader.ReadByte();     //padding


            uint extraDataSize  = reader.ReadUInt32();
            long nChannelEndPos = reader.BaseStream.Position + (long)extraDataSize;

            if (extraDataSize > 0)
            {
                uint nLength;

                this._mask = new Mask(reader, this);
                if (this._mask.Rectangle == null)
                {
                    this._mask = null;
                }

                //blending ranges
                this._blendRanges = new List <System.Drawing.Color>();
                nLength           = reader.ReadUInt32();
                //First come Composite gray blend source / destination; Contains 2 black values followed by 2 white values. Present but irrelevant for Lab & Grayscale.
                //Then 4+4 for each channel (source + destination colors)
                for (uint i = 0; i < nLength / 8; i++)
                {
                    this._blendRanges.Add(System.Drawing.Color.FromArgb((int)reader.ReadUInt32()));
                    this._blendRanges.Add(System.Drawing.Color.FromArgb((int)reader.ReadUInt32()));
                }

                //Name
                //nLength = (uint)reader.ReadByte();
                //reader.BaseStream.Position -= 1; //TODO: wtf did I do here?
                this.Name = reader.ReadPascalString();

                //TODO: sometimes there's a 2-byte padding here, but it's not 4-aligned... What is it?
                long posBefore = reader.BaseStream.Position;
                sHeader = new string(reader.ReadPSDChars(4));
                if (sHeader != "8BIM")
                {
                    reader.BaseStream.Position -= 2;
                    sHeader = new string(reader.ReadPSDChars(4));
                }
                if (sHeader != "8BIM")
                {
                    reader.BaseStream.Position = posBefore;
                }
                else
                {
                    reader.BaseStream.Position -= 4;
                    this._resources             = LayerResource.ReadLayerResources(reader, null);
                }
                if (reader.BaseStream.Position != nChannelEndPos)
                {
                    reader.BaseStream.Position = nChannelEndPos;
                }
            }
        }
Example #4
0
        //public void AddChannel(Channel ch)
        //{
        //    this._channels.Add(ch.Usage, ch);
        //}
        public Layer(BinaryPSDReader reader, Document document)
        {
            this._document = document;

            this._rect = reader.ReadPSDRectangle();

            ushort numChannels = reader.ReadUInt16();
            this._channels = new Dictionary<int, Channel>();
            for (int channelNum = 0; channelNum < numChannels; channelNum++)
            {
                Channel ch = new Channel(reader, this);
                if (this._channels.ContainsKey(ch.Usage))
                    continue; //TODO: !!
                this._channels.Add(ch.Usage, ch);
            }

            string sHeader = new string(reader.ReadPSDChars(4));
            if (sHeader != "8BIM")
                throw(new Exception("Layer Channelheader error!"));

            //'levl'=Levels 'curv'=Curves 'brit'=Brightness/contrast 'blnc'=Color balance 'hue '=Old Hue/saturation, Photoshop 4.0 'hue2'=New Hue/saturation, Photoshop 5.0 'selc'=Selective color 'thrs'=Threshold 'nvrt'=Invert 'post'=Posterize
            this.BlendKey = new string(reader.ReadPSDChars(4));
            int nBlend = -1;
            try
            {
                nBlend = (int)Enum.Parse(typeof(_blendKeysPsd), this.BlendKey);
            }
            catch
            {
                throw new Exception("Unknown blend key: " + this.BlendKey);
            }
            if (nBlend >= 0)
            {
                BlendKeys key = (BlendKeys)nBlend;
                this.BlendKey = Enum.GetName(typeof(BlendKeys), key);
            }

            this.Opacity = reader.ReadByte();
            this.Clipping = reader.ReadByte();
            this.Flags = reader.ReadByte();

            reader.ReadByte(); //padding

            uint extraDataSize = reader.ReadUInt32();
            long nChannelEndPos = reader.BaseStream.Position + (long)extraDataSize;
            if (extraDataSize > 0)
            {
                uint nLength;

                this._mask = new Mask(reader, this);
                if (this._mask.Rectangle == null)
                    this._mask = null;

                //blending ranges
                this._blendRanges = new List<System.Drawing.Color>();
                nLength = reader.ReadUInt32();
                //First come Composite gray blend source / destination; Contains 2 black values followed by 2 white values. Present but irrelevant for Lab & Grayscale.
                //Then 4+4 for each channel (source + destination colors)
                for (uint i = 0; i < nLength/8; i++)
                {
                    this._blendRanges.Add(System.Drawing.Color.FromArgb((int)reader.ReadUInt32()));
                    this._blendRanges.Add(System.Drawing.Color.FromArgb((int)reader.ReadUInt32()));
                }

                //Name
                //nLength = (uint)reader.ReadByte();
                //reader.BaseStream.Position -= 1; //TODO: wtf did I do here?
                this.Name = reader.ReadPascalString();

                //TODO: sometimes there's a 2-byte padding here, but it's not 4-aligned... What is it?
                long posBefore = reader.BaseStream.Position;
                sHeader = new string(reader.ReadPSDChars(4));
                if (sHeader != "8BIM")
                {
                    reader.BaseStream.Position-=2;
                    sHeader = new string(reader.ReadPSDChars(4));
                }
                if (sHeader != "8BIM")
                    reader.BaseStream.Position = posBefore;
                else
                {
                    reader.BaseStream.Position -= 4;
                    this._resources = LayerResource.ReadLayerResources(reader, null);
                }
                if (reader.BaseStream.Position != nChannelEndPos)
                    reader.BaseStream.Position = nChannelEndPos;
            }
        }