} //end Load() /// <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(CultureInfo.InvariantCulture)); UInt32 layersInfoSectionLength = reader.ReadUInt32(); if (layersInfoSectionLength <= 0) return; Int64 startPosition = reader.BaseStream.Position; Int16 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); } _layers.Clear(); if (numberOfLayers == 0) return; for (Int32 i = 0; i < numberOfLayers; i++) { _layers.Add(new Layer(reader, this)); } foreach (Layer layer in Layers) { foreach (Layer.Channel channel in layer.Channels.Where(c => c.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; }
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; }