Exemplo n.º 1
0
        /// <summary>
        /// Compresses the image data.
        /// </summary>
        public void CompressImageData()
        {
            // Do not recompress if compressed data is already present.
            if (ImageDataRaw != null)
            {
                return;
            }

            if (ImageData == null)
            {
                return;
            }

            if (ImageCompression == ImageCompression.Rle)
            {
                RleRowLengths = new RleRowLengths(Rect.Height);
            }

            var compressor = ImageDataFactory.Create(this, null);

            compressor.Write(ImageData);
            ImageDataRaw = compressor.ReadCompressed();

            Length = 2 + ImageDataRaw.Length;
            if (ImageCompression == ImageCompression.Rle)
            {
                var rowLengthSize = Layer.PsdFile.IsLargeDocument ? 4 : 2;
                Length += rowLengthSize * Rect.Height;
            }
        }
Exemplo n.º 2
0
 public RleImage(byte[] rleData, RleRowLengths rleRowLengths,
                 Size size, int bitDepth)
     : base(size, bitDepth)
 {
     this.rleData       = rleData;
     this.rleRowLengths = rleRowLengths;
 }
Exemplo n.º 3
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 + 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.");
        }