diff --git a/src/ImageSharp/Formats/WebP/Vp8LTransform.cs b/src/ImageSharp/Formats/WebP/Vp8LTransform.cs
index 51863da5ff..b232f46885 100644
--- a/src/ImageSharp/Formats/WebP/Vp8LTransform.cs
+++ b/src/ImageSharp/Formats/WebP/Vp8LTransform.cs
@@ -8,12 +8,17 @@ namespace SixLabors.ImageSharp.Formats.WebP
///
internal class Vp8LTransform
{
- public Vp8LTransform(Vp8LTransformType transformType) => this.TransformType = transformType;
+ public Vp8LTransform(Vp8LTransformType transformType, int xSize, int ySize)
+ {
+ this.TransformType = transformType;
+ this.XSize = xSize;
+ this.YSize = ySize;
+ }
///
- /// Gets or sets the transform type.
+ /// Gets the transform type.
///
- public Vp8LTransformType TransformType { get; private set; }
+ public Vp8LTransformType TransformType { get; }
///
/// Subsampling bits defining transform window.
@@ -21,18 +26,18 @@ namespace SixLabors.ImageSharp.Formats.WebP
public int Bits { get; set; }
///
- /// Transform window X index.
+ /// Gets or sets the transform window X index.
///
public int XSize { get; set; }
///
- /// Transform window Y index.
+ /// Gets the transform window Y index.
///
- public int YSize { get; set; }
+ public int YSize { get; }
///
- /// Transform data.
+ /// Gets or sets the transform data.
///
- public int[] Data { get; set; }
+ public uint[] Data { get; set; }
}
}
diff --git a/src/ImageSharp/Formats/WebP/WebPLosslessDecoder.cs b/src/ImageSharp/Formats/WebP/WebPLosslessDecoder.cs
index e754ec6541..7a85889462 100644
--- a/src/ImageSharp/Formats/WebP/WebPLosslessDecoder.cs
+++ b/src/ImageSharp/Formats/WebP/WebPLosslessDecoder.cs
@@ -90,7 +90,7 @@ namespace SixLabors.ImageSharp.Formats.WebP
{
if (isLevel0)
{
- this.ReadTransformations(decoder);
+ this.ReadTransformations(xSize, ySize, decoder);
}
// Color cache.
@@ -571,7 +571,7 @@ namespace SixLabors.ImageSharp.Formats.WebP
/// Reads the transformations, if any are present.
///
/// Vp8LDecoder where the transformations will be stored.
- private void ReadTransformations(Vp8LDecoder decoder)
+ private void ReadTransformations(int xSize, int ySize, Vp8LDecoder decoder)
{
// Next bit indicates, if a transformation is present.
bool transformPresent = this.bitReader.ReadBit();
@@ -580,7 +580,7 @@ namespace SixLabors.ImageSharp.Formats.WebP
while (transformPresent)
{
var transformType = (Vp8LTransformType)this.bitReader.ReadBits(2);
- var transform = new Vp8LTransform(transformType);
+ var transform = new Vp8LTransform(transformType, xSize, ySize);
switch (transformType)
{
case Vp8LTransformType.SubtractGreen:
@@ -589,29 +589,23 @@ namespace SixLabors.ImageSharp.Formats.WebP
case Vp8LTransformType.ColorIndexingTransform:
// The transform data contains color table size and the entries in the color table.
// 8 bit value for color table size.
- uint colorTableSize = this.bitReader.ReadBits(8) + 1;
-
- // TODO: color table should follow here?
+ uint numColors = this.bitReader.ReadBits(8) + 1;
+ int bits = (numColors > 16) ? 0
+ : (numColors > 4) ? 1
+ : (numColors > 2) ? 2
+ : 3;
+ transform.XSize = LosslessUtils.SubSampleSize(transform.XSize, bits);
break;
case Vp8LTransformType.PredictorTransform:
- {
- // The first 3 bits of prediction data define the block width and height in number of bits.
- // The number of block columns, block_xsize, is used in indexing two-dimensionally.
- uint sizeBits = this.bitReader.ReadBits(3) + 2;
- int blockWidth = 1 << (int)sizeBits;
- int blockHeight = 1 << (int)sizeBits;
-
- break;
- }
-
case Vp8LTransformType.CrossColorTransform:
{
- // The first 3 bits of the color transform data contain the width and height of the image block in number of bits,
- // just like the predictor transform:
- uint sizeBits = this.bitReader.ReadBits(3) + 2;
- int blockWidth = 1 << (int)sizeBits;
- int blockHeight = 1 << (int)sizeBits;
+ transform.Bits = (int)this.bitReader.ReadBits(3) + 2;
+ transform.Data = this.DecodeImageStream(
+ decoder,
+ LosslessUtils.SubSampleSize(transform.XSize, transform.Bits),
+ LosslessUtils.SubSampleSize(transform.YSize, transform.Bits),
+ false);
break;
}
}