private static IList <RasterLayerChunk> CountRasterChunks(BufferedBinaryReader reader, int layerCount, ushort majorVersion) { List <RasterLayerChunk> rasterChunks = new List <RasterLayerChunk>(layerCount); int index = 0; while (index < layerCount) { uint head = reader.ReadUInt32(); if (head != PSPConstants.blockIdentifier) { throw new FormatException(Properties.Resources.InvalidBlockSignature); } PSPBlockID blockID = (PSPBlockID)reader.ReadUInt16(); #pragma warning disable IDE0059 // Value assigned to symbol is never used uint initialBlockLength = majorVersion <= PSPConstants.majorVersion5 ? reader.ReadUInt32() : 0; #pragma warning restore IDE0059 // Value assigned to symbol is never used uint blockLength = reader.ReadUInt32(); if (blockID == PSPBlockID.Layer) { index++; long endOffset = reader.Position + blockLength; LayerInfoChunk chunk = new LayerInfoChunk(reader, majorVersion); long currentOffset = reader.Position; switch (chunk.type) { case PSPLayerType.Raster: case PSPLayerType.FloatingRasterSelection: if (majorVersion >= PSPConstants.majorVersion12) { // Paint Shop Pro X2 and later insert an unknown block (0x21) before the start of the LayerBitmapInfo chunk. bool ok = false; if (reader.ReadUInt32() == PSPConstants.blockIdentifier) { ushort block = reader.ReadUInt16(); uint length = reader.ReadUInt32(); if (block == 0x21) { reader.Position += length; if (reader.ReadUInt32() == LayerBitmapInfoChunk.HeaderSize) { reader.Position -= 4L; currentOffset = reader.Position; ok = true; } } } if (!ok) { throw new FormatException(Properties.Resources.UnsupportedFormatVersion); } } rasterChunks.Add(new RasterLayerChunk(chunk, currentOffset)); break; } reader.Position += (endOffset - currentOffset); } else { reader.Position += blockLength; } } return(rasterChunks); }
public RasterLayerChunk(LayerInfoChunk info, long offset) { this.layerInfo = info; this.bitmapInfoOffset = offset; }