Example #1
0
 public Header(BinaryPSDReader reader)
 {
     this.Version = reader.ReadUInt16();
     if (Version != 1)
         throw new Exception("Can not read .psd version " + Version);
     byte[] buf = new byte[256];
     reader.Read(buf, (int)reader.BaseStream.Position, 6); //6 bytes reserved
     this.Channels = reader.ReadInt16();
     this.Rows = reader.ReadUInt32();
     this.Columns = reader.ReadUInt32();
     this.BitsPerPixel = reader.ReadUInt16();
     this.ColorMode = (ColorModes)reader.ReadInt16();
 }
Example #2
0
 public Header(BinaryPSDReader reader)
 {
     this.Version = reader.ReadUInt16();
     if (Version != 1)
     {
         throw new Exception("Can not read .psd version " + Version);
     }
     byte[] buf = new byte[256];
     reader.Read(buf, (int)reader.BaseStream.Position, 6); //6 bytes reserved
     this.Channels     = reader.ReadInt16();
     this.Rows         = reader.ReadUInt32();
     this.Columns      = reader.ReadUInt32();
     this.BitsPerPixel = reader.ReadUInt16();
     this.ColorMode    = (ColorModes)reader.ReadInt16();
 }
Example #3
0
        public byte[] ReadPixels(BinaryPSDReader reader, Compression compression)
        {
            int bytesPerPixelPerChannel = this._bitsPerPixel / 8; // psd.Header.Depth / 8;

            if (bytesPerPixelPerChannel < 1)
            {
                bytesPerPixelPerChannel = 1;
            }

            int bytesPerRow = this._width * bytesPerPixelPerChannel;
            int totalBytes  = bytesPerRow * this._height;

            byte[] pData = new byte[totalBytes];

            switch (compression)
            {
            case Compression.None:
                reader.Read(pData, 0, totalBytes);
                break;

            case Compression.Rle:
                for (int i = 0; i < this._height; i++)
                {
                    int offset          = i * this._width;
                    int numDecodedBytes = 0;
                    int numChunks       = 0;
                    while (numDecodedBytes < this._width)
                    {
                        numDecodedBytes += Endogine.Serialization.RleCodec.DecodeChunk(reader.BaseStream, pData, offset + numDecodedBytes);
                        numChunks++;
                    }
                }
                break;

            case Compression.ZipNoPrediction:
                throw (new Exception("ZIP without prediction, no specification"));

            case Compression.ZipPrediction:
                throw (new Exception("ZIP with prediction, no specification"));

            default:
                throw (new Exception("Compression not defined: " + compression));
            }

            return(pData);
        }
Example #4
0
        public byte[] ReadPixels(BinaryPSDReader reader, Compression compression)
        {
            int bytesPerPixelPerChannel = this._bitsPerPixel / 8; // psd.Header.Depth / 8;
            if (bytesPerPixelPerChannel < 1)
                bytesPerPixelPerChannel = 1;

            int bytesPerRow = this._width * bytesPerPixelPerChannel;
            int totalBytes = bytesPerRow * this._height;

            byte[] pData = new byte[totalBytes];

            switch (compression)
            {
                case Compression.None:
                    reader.Read(pData, 0, totalBytes);
                    break;

                case Compression.Rle:
                    for (int i = 0; i < this._height; i++)
                    {
                        int offset = i * this._width;
                        int numDecodedBytes = 0;
                        int numChunks = 0;
                        while (numDecodedBytes < this._width)
                        {
                            numDecodedBytes += Endogine.Serialization.RleCodec.DecodeChunk(reader.BaseStream, pData, offset + numDecodedBytes);
                            numChunks++;
                        }
                    }
                    break;

                case Compression.ZipNoPrediction:
                    throw (new Exception("ZIP without prediction, no specification"));

                case Compression.ZipPrediction:
                    throw (new Exception("ZIP with prediction, no specification"));

                default:
                    throw (new Exception("Compression not defined: " + compression));
            }

            return pData;
        }