private void Load(BufferedBinaryReader br)
        {
            this.chunkSize       = this.fileMajorVersion > PSPConstants.majorVersion5 ? br.ReadUInt32() : 0;
            this.width           = br.ReadInt32();
            this.height          = br.ReadInt32();
            this.resValue        = br.ReadDouble();
            this.resUnits        = (ResolutionMetric)br.ReadByte();
            this.compressionType = (PSPCompression)br.ReadUInt16();
            this.bitDepth        = br.ReadUInt16();
            this.planeCount      = br.ReadUInt16();
            this.colorCount      = br.ReadUInt32();
            this.grayScale       = br.ReadByte();
            this.totalImageSize  = br.ReadUInt32();
            this.activeLayer     = br.ReadInt32();
            this.layerCount      = br.ReadUInt16();

            if (this.fileMajorVersion > PSPConstants.majorVersion5)
            {
                this.graphicContents = (PSPGraphicContents)br.ReadUInt32();
            }
            else
            {
                this.graphicContents = PSPGraphicContents.None;
            }

            long minChunkSize = this.fileMajorVersion > PSPConstants.majorVersion5 ? Version6HeaderSize : Version5HeaderSize;
            long dif          = this.chunkSize - minChunkSize;

            if (dif > 0 && this.fileMajorVersion > PSPConstants.majorVersion5) // skip any unknown chunks
            {
                br.Position += dif;
            }
        }
Example #2
0
        public LayerBitmapInfoChunk(BufferedBinaryReader br, PSPCompression compression, ushort majorVersion)
        {
            long startOffset = br.Position;

            this.chunkSize    = br.ReadUInt32();
            this.bitmapCount  = br.ReadUInt16();
            this.channelCount = br.ReadUInt16();
            this.channels     = new ChannelSubBlock[this.channelCount];

            long dif = this.chunkSize - (br.Position - startOffset);

            if (dif > 0L)
            {
                br.Position += dif;
            }

            for (int i = 0; i < this.channelCount; i++)
            {
                uint head = br.ReadUInt32();
                if (head != PSPConstants.blockIdentifier)
                {
                    throw new FormatException(Properties.Resources.InvalidBlockSignature);
                }
                ushort blockID = br.ReadUInt16();
                PSPUtil.CheckBlockType(blockID, PSPBlockID.Channel);
#pragma warning disable IDE0059 // Value assigned to symbol is never used
                uint size = br.ReadUInt32();
#pragma warning restore IDE0059 // Value assigned to symbol is never used

                this.channels[i] = new ChannelSubBlock(br, compression, majorVersion);
            }
        }
Example #3
0
        public LayerBlock(BufferedBinaryReader br, GeneralImageAttributes imageAttributes, ushort majorVersion)
        {
            IList <RasterLayerChunk> raster = CountRasterChunks(br, imageAttributes.LayerCount, majorVersion);

            int layerCount = raster.Count;

            if (layerCount == 0)
            {
                throw new FormatException(Properties.Resources.RasterLayerNotFound);
            }

            this.layerInfoChunks = new LayerInfoChunk[layerCount];
            this.layerBitmapInfo = new LayerBitmapInfoChunk[layerCount];
            PSPCompression compression = imageAttributes.CompressionType;

            for (int i = 0; i < layerCount; i++)
            {
                RasterLayerChunk chunk = raster[i];
                this.layerInfoChunks[i] = chunk.layerInfo;

                if (!chunk.layerInfo.saveRect.IsEmpty)
                {
                    br.Position = chunk.bitmapInfoOffset;
                    if (majorVersion <= PSPConstants.majorVersion5)
                    {
                        this.layerBitmapInfo[i] = new LayerBitmapInfoChunk(br, compression, chunk.layerInfo.v5BitmapCount, chunk.layerInfo.v5ChannelCount);
                    }
                    else
                    {
                        this.layerBitmapInfo[i] = new LayerBitmapInfoChunk(br, compression, majorVersion);
                    }
                }
            }
        }
Example #4
0
        public ChannelSubBlock(BufferedBinaryReader br, PSPCompression compression, ushort majorVersion)
        {
            this.chunkSize = majorVersion > PSPConstants.majorVersion5 ? br.ReadUInt32() : 0U;
            this.compressedChannelLength   = br.ReadUInt32();
            this.uncompressedChannelLength = br.ReadUInt32();
            this.bitmapType  = (PSPDIBType)br.ReadUInt16();
            this.channelType = (PSPChannelType)br.ReadUInt16();
            this.channelData = null;

            long dif = (long)this.chunkSize - Version6HeaderSize;

            if (dif > 0 && majorVersion > PSPConstants.majorVersion5)
            {
                br.Position += dif;
            }

            if (this.compressedChannelLength > 0U)
            {
                switch (compression)
                {
                case PSPCompression.None:
                    this.channelData = br.ReadBytes((int)this.compressedChannelLength);
                    break;

                case PSPCompression.RLE:
                    this.channelData = RLE.Decompress(br.ReadBytes((int)this.compressedChannelLength), this.uncompressedChannelLength);
                    break;

                case PSPCompression.LZ77:

                    byte[] compressedData = br.ReadBytes((int)this.compressedChannelLength);
                    this.channelData = new byte[this.uncompressedChannelLength];

                    ZlibCodec codec = new ZlibCodec
                    {
                        AvailableBytesIn  = (int)this.compressedChannelLength,
                        AvailableBytesOut = (int)this.uncompressedChannelLength,
                        InputBuffer       = compressedData,
                        OutputBuffer      = this.channelData
                    };
                    codec.InitializeInflate();

                    int status = codec.Inflate(FlushType.Finish);

                    codec.EndInflate();

                    if (status != ZlibConstants.Z_OK && status != ZlibConstants.Z_STREAM_END)
                    {
                        throw new ZlibException(codec.Message);
                    }

                    break;
                }
            }
        }
 public ThumbnailBlock(int width, int height)
 {
     this.width             = width;
     this.height            = height;
     this.bitDepth          = 24;
     this.compressionType   = PSPCompression.LZ77;
     this.planeCount        = 1;
     this.colorCount        = (1 << 24);
     this.paletteEntryCount = 0;
     this.channelCount      = 3;
 }
Example #6
0
 public CompositeImageAttributesChunk(int width, int height, PSPCompositeImageType imageType, PSPCompression compression)
 {
     this.chunkSize          = HeaderSize;
     this.width              = width;
     this.height             = height;
     this.bitDepth           = 24;
     this.compressionType    = compression;
     this.planeCount         = 1;
     this.colorCount         = (1 << 24);
     this.compositeImageType = imageType;
 }
Example #7
0
        private static PSPCompression CompressionFromTokenFormat(CompressionFormats format)
        {
            PSPCompression comp = PSPCompression.None;

            switch (format)
            {
            case CompressionFormats.LZ77:
                comp = PSPCompression.LZ77;
                break;
            }

            return(comp);
        }
        public GeneralImageAttributes(int width, int height, PSPCompression compType, int activeLayer, int layerCount, ushort majorVersion)
        {
            this.chunkSize        = majorVersion > PSPConstants.majorVersion5 ? Version6HeaderSize : Version5HeaderSize;
            this.width            = width;
            this.height           = height;
            this.compressionType  = compType;
            this.activeLayer      = activeLayer;
            this.layerCount       = (ushort)layerCount;
            this.bitDepth         = 24;
            this.colorCount       = (1U << this.bitDepth);
            this.graphicContents |= PSPGraphicContents.RasterLayers;

            this.fileMajorVersion = majorVersion;
        }
Example #9
0
        public CompositeImageAttributesChunk(BufferedBinaryReader br)
        {
            this.chunkSize          = br.ReadUInt32();
            this.width              = br.ReadInt32();
            this.height             = br.ReadInt32();
            this.bitDepth           = br.ReadUInt16();
            this.compressionType    = (PSPCompression)br.ReadUInt16();
            this.planeCount         = br.ReadUInt16();
            this.colorCount         = br.ReadUInt32();
            this.compositeImageType = (PSPCompositeImageType)br.ReadUInt16();

            long dif = (long)this.chunkSize - HeaderSize;

            if (dif > 0)
            {
                br.Position += dif;
            }
        }
        public ThumbnailBlock(BufferedBinaryReader br)
        {
            this.width             = br.ReadInt32();
            this.height            = br.ReadInt32();
            this.bitDepth          = br.ReadUInt16();
            this.compressionType   = (PSPCompression)br.ReadUInt16();
            this.planeCount        = br.ReadUInt16();
            this.colorCount        = br.ReadUInt32();
            this.paletteEntryCount = br.ReadUInt32();
            this.channelCount      = br.ReadUInt16();

            this.channelBlocks = new ChannelSubBlock[this.channelCount];

            int index = 0;

            do
            {
                uint blockSig = br.ReadUInt32();
                if (blockSig != PSPConstants.blockIdentifier)
                {
                    throw new System.FormatException(Properties.Resources.InvalidBlockSignature);
                }
                PSPBlockID blockType = (PSPBlockID)br.ReadUInt16();
#pragma warning disable IDE0059 // Value assigned to symbol is never used
                uint chunkLength = br.ReadUInt32();
#pragma warning restore IDE0059 // Value assigned to symbol is never used

                switch (blockType)
                {
                case PSPBlockID.ColorPalette:
                    this.paletteSubBlock = new ColorPaletteBlock(br, PSPConstants.majorVersion5);
                    break;

                case PSPBlockID.Channel:
                    ChannelSubBlock block = new ChannelSubBlock(br, this.compressionType, PSPConstants.majorVersion5);
                    this.channelBlocks[index] = block;
                    index++;
                    break;
                }
            }while (index < this.channelCount);
        }