Ejemplo n.º 1
0
        //////////////////////////////////////////////////////////////////

        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 + Length;

            ImageCompression = (ImageCompression)reader.ReadInt16();
            var longDataLength = Length - 2;

            Util.CheckByteArrayLength(longDataLength);
            var dataLength = (Int32)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 = (Int32)(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, {0}",
                              ID, Layer.Name);
            Debug.Assert(reader.BaseStream.Position == endPosition,
                         "Pixel data was not fully read in.");
        }
Ejemplo n.º 2
0
 public RawImageResource(PsdBinaryReader reader, String signature,
                         ResourceID resourceId, String name, Int32 numBytes)
     : base(name)
 {
     this.Signature = signature;
     this._id       = resourceId;
     Data           = reader.ReadBytes(numBytes);
 }
Ejemplo n.º 3
0
        public RawLayerInfo(PsdBinaryReader reader, String signature, String key,
                            Int64 dataLength)
        {
            _signature = signature;
            _key       = key;

            Util.CheckByteArrayLength(dataLength);
            Data = reader.ReadBytes((Int32)dataLength);
        }
Ejemplo n.º 4
0
        private void LoadColorModeData(PsdBinaryReader reader)
        {
            Util.DebugMessage(reader.BaseStream, "Load, Begin, ColorModeData");

            var paletteLength = reader.ReadUInt32();

            if (paletteLength > 0)
            {
                ColorModeData = reader.ReadBytes((Int32)paletteLength);
            }

            Util.DebugMessage(reader.BaseStream, "Load, End, ColorModeData");
        }
Ejemplo n.º 5
0
        ///////////////////////////////////////////////////////////////////////////

        public BlendingRanges(PsdBinaryReader reader, Layer layer)
        {
            Util.DebugMessage(reader.BaseStream, "Load, Begin, BlendingRanges");

            Layer = layer;
            var dataLength = reader.ReadInt32();

            if (dataLength <= 0)
            {
                return;
            }

            Data = reader.ReadBytes(dataLength);

            Util.DebugMessage(reader.BaseStream, "Load, End, BlendingRanges");
        }
Ejemplo n.º 6
0
        private void LoadGlobalLayerMask(PsdBinaryReader reader)
        {
            Util.DebugMessage(reader.BaseStream, "Load, Begin, GlobalLayerMask");

            var maskLength = reader.ReadUInt32();

            if (maskLength <= 0)
            {
                Util.DebugMessage(reader.BaseStream, "Load, End, GlobalLayerMask");
                return;
            }

            _globalLayerMaskData = reader.ReadBytes((Int32)maskLength);

            Util.DebugMessage(reader.BaseStream, "Load, End, GlobalLayerMask");
        }
Ejemplo n.º 7
0
        private void LoadImage(PsdBinaryReader reader)
        {
            Util.DebugMessage(reader.BaseStream, "Load, Begin, Composite image");

            ImageCompression = (ImageCompression)reader.ReadInt16();

            // Create channels
            for (Int16 i = 0; i < ChannelCount; i++)
            {
                Util.DebugMessage(reader.BaseStream, "Load, Begin, Channel image data");

                var channel = new Channel(i, this.BaseLayer);
                channel.ImageCompression = ImageCompression;
                channel.Length           = this.RowCount
                                           * Util.BytesPerRow(BaseLayer.Rect.Size, BitDepth);

                // The composite image stores all RLE headers up-front, rather than
                // with each channel.
                if (ImageCompression == ImageCompression.Rle)
                {
                    channel.RleRowLengths = new RleRowLengths(reader, RowCount, IsLargeDocument);
                    channel.Length        = channel.RleRowLengths.Total;
                }

                BaseLayer.Channels.Add(channel);
                Util.DebugMessage(reader.BaseStream, "Load, End, Channel image data");
            }

            foreach (var channel in this.BaseLayer.Channels)
            {
                Util.DebugMessage(reader.BaseStream, "Load, Begin, Channel image data");
                Util.CheckByteArrayLength(channel.Length);
                channel.ImageDataRaw = reader.ReadBytes((Int32)channel.Length);
                Util.DebugMessage(reader.BaseStream, "Load, End, Channel image data");
            }

            // If there is exactly one more channel than we need, then it is the
            // alpha channel.
            if ((ColorMode != PsdColorMode.Multichannel) &&
                (ChannelCount == ColorMode.MinChannelCount() + 1))
            {
                var alphaChannel = BaseLayer.Channels.Last();
                alphaChannel.ID = -1;
            }

            Util.DebugMessage(reader.BaseStream, "Load, End, Composite image");
        }