コード例 #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;
            }
        }
コード例 #2
0
 public RleImage(Byte[] rleData, RleRowLengths rleRowLengths,
                 Size size, Int32 bitDepth)
     : base(size, bitDepth)
 {
     this._rleData       = rleData;
     this._rleRowLengths = rleRowLengths;
 }
コード例 #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 + 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.");
        }