/// <summary> /// Initializes a new instance of the <see cref="AlphaDecoder"/> class. /// </summary> /// <param name="width">The width of the image.</param> /// <param name="height">The height of the image.</param> /// <param name="data">The (maybe compressed) alpha data.</param> /// <param name="alphaChunkHeader">The first byte of the alpha image stream contains information on how to decode the stream.</param> /// <param name="memoryAllocator">Used for allocating memory during decoding.</param> /// <param name="configuration">The configuration.</param> public AlphaDecoder(int width, int height, IMemoryOwner <byte> data, byte alphaChunkHeader, MemoryAllocator memoryAllocator, Configuration configuration) { this.Width = width; this.Height = height; this.Data = data; this.memoryAllocator = memoryAllocator; this.LastRow = 0; int totalPixels = width * height; var compression = (WebpAlphaCompressionMethod)(alphaChunkHeader & 0x03); if (compression is not WebpAlphaCompressionMethod.NoCompression and not WebpAlphaCompressionMethod.WebpLosslessCompression) { WebpThrowHelper.ThrowImageFormatException($"unexpected alpha compression method {compression} found"); } this.Compressed = compression == WebpAlphaCompressionMethod.WebpLosslessCompression; // The filtering method used. Only values between 0 and 3 are valid. int filter = (alphaChunkHeader >> 2) & 0x03; if (filter is < (int)WebpAlphaFilterType.None or > (int)WebpAlphaFilterType.Gradient) { WebpThrowHelper.ThrowImageFormatException($"unexpected alpha filter method {filter} found"); } this.Alpha = memoryAllocator.Allocate <byte>(totalPixels); this.AlphaFilterType = (WebpAlphaFilterType)filter; this.Vp8LDec = new Vp8LDecoder(width, height, memoryAllocator); if (this.Compressed) { var bitReader = new Vp8LBitReader(data); this.LosslessDecoder = new WebpLosslessDecoder(bitReader, memoryAllocator, configuration); this.LosslessDecoder.DecodeImageStream(this.Vp8LDec, width, height, true); this.Use8BDecode = this.Vp8LDec.Transforms.Count > 0 && Is8BOptimizable(this.Vp8LDec.Metadata); } }
/// <summary> /// Initializes a new instance of the <see cref="WebpLosslessDecoder"/> class. /// </summary> /// <param name="bitReader">Bitreader to read from the stream.</param> /// <param name="memoryAllocator">Used for allocating memory during processing operations.</param> /// <param name="configuration">The configuration.</param> public WebpLosslessDecoder(Vp8LBitReader bitReader, MemoryAllocator memoryAllocator, Configuration configuration) { this.bitReader = bitReader; this.memoryAllocator = memoryAllocator; this.configuration = configuration; }