internal Channel(PsdBinaryReader reader, Layer layer) { Util.DebugMessage(reader.BaseStream, "Load, Begin, Channel"); ID = reader.ReadInt16(); Length = (layer.PsdFile.IsLargeDocument) ? reader.ReadInt64() : reader.ReadInt32(); Layer = layer; Util.DebugMessage(reader.BaseStream, $"Load, End, Channel, {ID}"); }
////////////////////////////////////////////////////////////////// internal void LoadPixelData(PsdBinaryReader reader) { Util.DebugMessage(reader.BaseStream, "Load, Begin, Channel image"); if (Length == 0) { ImageCompression = ImageCompression.Raw; ImageDataRaw = new byte[0]; return; } var endPosition = reader.BaseStream.Position + this.Length; ImageCompression = (ImageCompression)reader.ReadInt16(); var longDataLength = this.Length - 2; Util.CheckByteArrayLength(longDataLength); var dataLength = (int)longDataLength; switch (ImageCompression) { case ImageCompression.Raw: ImageDataRaw = reader.ReadBytes(dataLength); break; case ImageCompression.Rle: // RLE row lengths RleRowLengths = new RleRowLengths(reader, Rect.Height, Layer.PsdFile.IsLargeDocument); var rleDataLength = (int)(endPosition - reader.BaseStream.Position); Debug.Assert(rleDataLength == RleRowLengths.Total, "RLE row lengths do not sum to length of channel image data."); // The PSD specification states that rows are padded to even sizes. // However, Photoshop doesn't actually do this. RLE rows can have // odd lengths in the header, and there is no padding between rows. ImageDataRaw = reader.ReadBytes(rleDataLength); break; case ImageCompression.Zip: case ImageCompression.ZipPrediction: ImageDataRaw = reader.ReadBytes(dataLength); break; } Util.DebugMessage(reader.BaseStream, $"Load, End, Channel image, {ID}"); Debug.Assert(reader.BaseStream.Position == endPosition, "Pixel data was not fully read in."); }