diff --git a/src/ImageSharp/Formats/WebP/LosslessUtils.cs b/src/ImageSharp/Formats/WebP/LosslessUtils.cs
index 5eac30f1f..d6996dc9a 100644
--- a/src/ImageSharp/Formats/WebP/LosslessUtils.cs
+++ b/src/ImageSharp/Formats/WebP/LosslessUtils.cs
@@ -1,3 +1,6 @@
+// Copyright (c) Six Labors and contributors.
+// Licensed under the Apache License, Version 2.0.
+
using System;
using System.Runtime.InteropServices;
@@ -132,6 +135,7 @@ namespace SixLabors.ImageSharp.Formats.WebP
newBlue += ColorTransformDelta(m.GreenToBlue, (sbyte)green);
newBlue += ColorTransformDelta(m.RedToBlue, (sbyte)newRed);
newBlue &= 0xff;
+
// uint pixelValue = (uint)((argb & 0xff00ff00u) | (newRed << 16) | newBlue);
pixelData[i] = (uint)((argb & 0xff00ff00u) | (newRed << 16) | newBlue);
}
@@ -162,6 +166,28 @@ namespace SixLabors.ImageSharp.Formats.WebP
return newColorMap;
}
+ public static void PredictorInverseTransform(Vp8LTransform transform, uint[] pixelData)
+ {
+ int processedPixels = 0;
+ int yStart = 0;
+ int width = transform.XSize;
+
+ // PredictorAdd0(in, NULL, 1, out);
+ PredictorAdd1(pixelData, width - 1);
+ processedPixels += width;
+ yStart++;
+
+ int y = yStart;
+ int tileWidth = 1 << transform.Bits;
+ int mask = tileWidth - 1;
+ int tilesPerRow = SubSampleSize(width, transform.Bits);
+ }
+
+ private static uint Predictor0C(uint left, uint[] top)
+ {
+ return WebPConstants.ArgbBlack;
+ }
+
///
/// Computes sampled size of 'size' when sampling using 'sampling bits'.
///
diff --git a/src/ImageSharp/Formats/WebP/Vp8LBitReader.cs b/src/ImageSharp/Formats/WebP/Vp8LBitReader.cs
index cdcca61e9..0bb69311f 100644
--- a/src/ImageSharp/Formats/WebP/Vp8LBitReader.cs
+++ b/src/ImageSharp/Formats/WebP/Vp8LBitReader.cs
@@ -25,7 +25,7 @@ namespace SixLabors.ImageSharp.Formats.WebP
///
private const int VP8L_WBITS = 32;
- private uint[] kBitMask =
+ private readonly uint[] kBitMask =
{
0,
0x000001, 0x000003, 0x000007, 0x00000f,
@@ -80,7 +80,7 @@ namespace SixLabors.ImageSharp.Formats.WebP
///
/// Buffer length.
///
- private long len;
+ private readonly long len;
///
/// Byte position in buffer.
diff --git a/src/ImageSharp/Formats/WebP/WebPConstants.cs b/src/ImageSharp/Formats/WebP/WebPConstants.cs
index c54f72073..6f0c4618c 100644
--- a/src/ImageSharp/Formats/WebP/WebPConstants.cs
+++ b/src/ImageSharp/Formats/WebP/WebPConstants.cs
@@ -52,54 +52,57 @@ namespace SixLabors.ImageSharp.Formats.WebP
///
/// Signature byte which identifies a VP8L header.
///
- public static byte Vp8LMagicByte = 0x2F;
+ public const byte Vp8LMagicByte = 0x2F;
///
/// 3 bits reserved for version.
///
- public static int Vp8LVersionBits = 3;
+ public const int Vp8LVersionBits = 3;
///
/// Bits for width and height infos of a VPL8 image.
///
- public static int Vp8LImageSizeBits = 14;
+ public const int Vp8LImageSizeBits = 14;
///
/// Maximum number of color cache bits.
///
- public static int MaxColorCacheBits = 11;
+ public const int MaxColorCacheBits = 11;
///
/// The maximum number of allowed transforms in a bitstream.
///
- public static int MaxNumberOfTransforms = 4;
+ public const int MaxNumberOfTransforms = 4;
- public static int MaxAllowedCodeLength = 15;
+ public const int MaxAllowedCodeLength = 15;
- public static int DefaultCodeLength = 8;
+ public const int DefaultCodeLength = 8;
- public static int HuffmanCodesPerMetaCode = 5;
+ public const int HuffmanCodesPerMetaCode = 5;
- public static int NumLiteralCodes = 256;
+ public const uint ArgbBlack = 0xff000000;
- public static int NumLengthCodes = 24;
+ public const int NumLiteralCodes = 256;
- public static int NumDistanceCodes = 40;
+ public const int NumLengthCodes = 24;
- public static int LengthTableBits = 7;
+ public const int NumDistanceCodes = 40;
- public static uint kCodeLengthLiterals = 16;
+ public const int LengthTableBits = 7;
- public static int kCodeLengthRepeatCode = 16;
+ public const uint KCodeLengthLiterals = 16;
- public static int[] kCodeLengthExtraBits = { 2, 3, 7 };
+ public const int KCodeLengthRepeatCode = 16;
- public static int[] kCodeLengthRepeatOffsets = { 3, 3, 11 };
+ public static readonly int[] KCodeLengthExtraBits = { 2, 3, 7 };
- public static int[] kAlphabetSize = {
- NumLiteralCodes + NumLengthCodes,
- NumLiteralCodes, NumLiteralCodes, NumLiteralCodes,
- NumDistanceCodes
- };
+ public static readonly int[] KCodeLengthRepeatOffsets = { 3, 3, 11 };
+
+ public static readonly int[] KAlphabetSize =
+ {
+ NumLiteralCodes + NumLengthCodes,
+ NumLiteralCodes, NumLiteralCodes, NumLiteralCodes,
+ NumDistanceCodes
+ };
}
}
diff --git a/src/ImageSharp/Formats/WebP/WebPImageInfo.cs b/src/ImageSharp/Formats/WebP/WebPImageInfo.cs
index f68cc00b1..35e27f721 100644
--- a/src/ImageSharp/Formats/WebP/WebPImageInfo.cs
+++ b/src/ImageSharp/Formats/WebP/WebPImageInfo.cs
@@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Formats.WebP
public int Height { get; set; }
///
- /// Gets or sets whether this image uses a lossless compression.
+ /// Gets or sets a value indicating whether this image uses a lossless compression.
///
public bool IsLossLess { get; set; }
@@ -26,12 +26,11 @@ namespace SixLabors.ImageSharp.Formats.WebP
public WebPFeatures Features { get; set; }
///
- /// The bytes of the image payload.
+ /// Gets or sets the bytes of the image payload.
///
public uint ImageDataSize { get; set; }
- // TODO: not sure if the bitreader is in the right place here, but for the sake of simplicity it will stay here for now.
- // Will be refactored later.
+ // TODO: not sure if the bitreader is in the right place here, but for the sake of simplicity it will stay here for now. Will be refactored later.
public Vp8LBitReader Vp9LBitReader { get; set; }
}
}
diff --git a/src/ImageSharp/Formats/WebP/WebPLosslessDecoder.cs b/src/ImageSharp/Formats/WebP/WebPLosslessDecoder.cs
index 24104b494..21686d552 100644
--- a/src/ImageSharp/Formats/WebP/WebPLosslessDecoder.cs
+++ b/src/ImageSharp/Formats/WebP/WebPLosslessDecoder.cs
@@ -368,7 +368,7 @@ namespace SixLabors.ImageSharp.Formats.WebP
// Find maximum alphabet size for the hTree group.
for (int j = 0; j < WebPConstants.HuffmanCodesPerMetaCode; j++)
{
- int alphabetSize = WebPConstants.kAlphabetSize[j];
+ int alphabetSize = WebPConstants.KAlphabetSize[j];
if (j == 0 && colorCacheBits > 0)
{
alphabetSize += 1 << colorCacheBits;
@@ -394,7 +394,7 @@ namespace SixLabors.ImageSharp.Formats.WebP
var codeLengths = new int[maxAlphabetSize];
for (int j = 0; j < WebPConstants.HuffmanCodesPerMetaCode; j++)
{
- int alphabetSize = WebPConstants.kAlphabetSize[j];
+ int alphabetSize = WebPConstants.KAlphabetSize[j];
if (j == 0 && colorCacheBits > 0)
{
alphabetSize += 1 << colorCacheBits;
@@ -548,7 +548,7 @@ namespace SixLabors.ImageSharp.Formats.WebP
HuffmanCode huffmanCode = table[idx];
this.bitReader.AdvanceBitPosition(huffmanCode.BitsUsed);
uint codeLen = huffmanCode.Value;
- if (codeLen < WebPConstants.kCodeLengthLiterals)
+ if (codeLen < WebPConstants.KCodeLengthLiterals)
{
codeLengths[symbol++] = (int)codeLen;
if (codeLen != 0)
@@ -558,10 +558,10 @@ namespace SixLabors.ImageSharp.Formats.WebP
}
else
{
- bool usePrev = codeLen == WebPConstants.kCodeLengthRepeatCode;
- uint slot = codeLen - WebPConstants.kCodeLengthLiterals;
- int extraBits = WebPConstants.kCodeLengthExtraBits[slot];
- int repeatOffset = WebPConstants.kCodeLengthRepeatOffsets[slot];
+ bool usePrev = codeLen == WebPConstants.KCodeLengthRepeatCode;
+ uint slot = codeLen - WebPConstants.KCodeLengthLiterals;
+ int extraBits = WebPConstants.KCodeLengthExtraBits[slot];
+ int repeatOffset = WebPConstants.KCodeLengthRepeatOffsets[slot];
int repeat = (int)(this.bitReader.ReadBits(extraBits) + repeatOffset);
if (symbol + repeat > numSymbols)
{
@@ -637,7 +637,7 @@ namespace SixLabors.ImageSharp.Formats.WebP
switch (transformType)
{
case Vp8LTransformType.PredictorTransform:
- // LosslessUtils.PredictorInverseTransform(transforms[i], pixelData);
+ LosslessUtils.PredictorInverseTransform(transforms[i], pixelData);
break;
case Vp8LTransformType.SubtractGreen:
LosslessUtils.AddGreenToBlueAndRed(pixelData);
diff --git a/src/ImageSharp/Formats/WebP/WebPLossyDecoder.cs b/src/ImageSharp/Formats/WebP/WebPLossyDecoder.cs
index 47acbae70..cd8f98678 100644
--- a/src/ImageSharp/Formats/WebP/WebPLossyDecoder.cs
+++ b/src/ImageSharp/Formats/WebP/WebPLossyDecoder.cs
@@ -51,7 +51,7 @@ namespace SixLabors.ImageSharp.Formats.WebP
}
byte version = (byte)((bitReader.ReadBit() ? 2 : 0) | (bitReader.ReadBit() ? 1 : 0));
- (ReconstructionFilter rec, LoopFilter loop) = DecodeVersion(version);
+ (ReconstructionFilter rec, LoopFilter loop) = this.DecodeVersion(version);
bool isShowFrame = bitReader.ReadBit();
diff --git a/src/ImageSharp/Formats/WebP/WebPMetadata.cs b/src/ImageSharp/Formats/WebP/WebPMetadata.cs
index 69e9a43f4..65b09d5ec 100644
--- a/src/ImageSharp/Formats/WebP/WebPMetadata.cs
+++ b/src/ImageSharp/Formats/WebP/WebPMetadata.cs
@@ -1,7 +1,6 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
-using System.Collections;
using System.Collections.Generic;
namespace SixLabors.ImageSharp.Formats.WebP
@@ -28,9 +27,6 @@ namespace SixLabors.ImageSharp.Formats.WebP
this.Format = other.Format;
}
- ///
- public IDeepCloneable DeepClone() => new WebPMetadata(this);
-
///
/// The webp format used. Either lossless or lossy.
///
@@ -42,8 +38,11 @@ namespace SixLabors.ImageSharp.Formats.WebP
public Queue ChunkTypes { get; set; } = new Queue();
///
- /// Indicates, if the webp file contains a animation.
+ /// Gets or sets a value indicating whether the webp file contains a animation.
///
public bool Animated { get; set; } = false;
+
+ ///
+ public IDeepCloneable DeepClone() => new WebPMetadata(this);
}
}