public ImageResource(BinaryReverseReader reverseReader) { Name = String.Empty; OSType = new String(reverseReader.ReadChars(4)); if (OSType != "8BIM" && OSType != "MeSa") { throw new InvalidOperationException("Could not read an image resource"); } ID = reverseReader.ReadInt16(); Name = reverseReader.ReadPascalString(); UInt32 settingLength = reverseReader.ReadUInt32(); Data = reverseReader.ReadBytes((Int32)settingLength); if (reverseReader.BaseStream.Position % 2 == 1) reverseReader.ReadByte(); }
public Layer(BinaryReverseReader reverseReader, PsdFile psdFile) { AdjustmentInfo = new List<AdjusmentLayerInfo>(); SortedChannels = new SortedList<Int16, Channel>(); Channels = new List<Channel>(); Debug.WriteLine("Layer started at " + reverseReader.BaseStream.Position.ToString(CultureInfo.InvariantCulture)); PsdFile = psdFile; Rectangle localRectangle = new Rectangle { Y = reverseReader.ReadInt32(), X = reverseReader.ReadInt32() }; localRectangle.Height = reverseReader.ReadInt32() - localRectangle.Y; localRectangle.Width = reverseReader.ReadInt32() - localRectangle.X; Rect = localRectangle; Int32 numberOfChannels = reverseReader.ReadUInt16(); Channels.Clear(); for (Int32 channel = 0; channel < numberOfChannels; channel++) { Channel ch = new Channel(reverseReader, this); Channels.Add(ch); SortedChannels.Add(ch.ID, ch); } String signature = new String(reverseReader.ReadChars(4)); if (signature != "8BIM") throw (new IOException("Layer Channelheader error")); _blendModeKeyStr = new String(reverseReader.ReadChars(4)); Opacity = reverseReader.ReadByte(); Clipping = reverseReader.ReadByte() > 0; Byte flags = reverseReader.ReadByte(); _flags = new BitVector32(flags); reverseReader.ReadByte(); //padding Debug.WriteLine("Layer extraDataSize started at " + reverseReader.BaseStream.Position.ToString(CultureInfo.InvariantCulture)); // this is the total size of the MaskData, the BlendingRangesData, the // Name and the AdjustmenLayerInfo UInt32 extraDataSize = reverseReader.ReadUInt32(); // remember the start position for calculation of the // AdjustmenLayerInfo size Int64 extraDataStartPosition = reverseReader.BaseStream.Position; MaskData = new Mask(reverseReader, this); BlendingRangesData = new BlendingRanges(reverseReader, this); Int64 namePosition = reverseReader.BaseStream.Position; Name = reverseReader.ReadPascalString(); Int32 paddingBytes = (Int32)((reverseReader.BaseStream.Position - namePosition) % 4); Debug.Print("Layer {0} padding bytes after name", paddingBytes); reverseReader.ReadBytes(paddingBytes); AdjustmentInfo.Clear(); Int64 adjustmenLayerEndPos = extraDataStartPosition + extraDataSize; while (reverseReader.BaseStream.Position < adjustmenLayerEndPos) { try { AdjustmentInfo.Add(new AdjusmentLayerInfo(reverseReader, this)); } catch { reverseReader.BaseStream.Position = adjustmenLayerEndPos; } } // make shure we are not on a wrong offset, so set the stream position // manually reverseReader.BaseStream.Position = adjustmenLayerEndPos; }