public ImageResource(BinaryPSDReader reader) { this.ID = reader.ReadUInt16(); this.Name = reader.ReadPascalString(); uint settingLength = reader.ReadUInt32(); this.Data = reader.ReadBytes((int)settingLength); if (reader.BaseStream.Position % 2 == 1) reader.ReadByte(); }
//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; } } }
//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; } }
public ImageResource(BinaryPSDReader reader) { this.ID = reader.ReadUInt16(); this.Name = reader.ReadPascalString(); uint settingLength = reader.ReadUInt32(); this.Data = reader.ReadBytes((int)settingLength); if (reader.BaseStream.Position % 2 == 1) reader.ReadByte(); }