diff --git a/src/ImageSharp/Formats/WebP/ColorCache.cs b/src/ImageSharp/Formats/WebP/ColorCache.cs index d5579cbf1e..d5834a4c80 100644 --- a/src/ImageSharp/Formats/WebP/ColorCache.cs +++ b/src/ImageSharp/Formats/WebP/ColorCache.cs @@ -8,7 +8,7 @@ namespace SixLabors.ImageSharp.Formats.WebP /// internal class ColorCache { - private const uint KHashMul = 0x1e35a7bdu; + private const uint HashMul = 0x1e35a7bdu; /// /// Gets the color entries. @@ -54,7 +54,7 @@ namespace SixLabors.ImageSharp.Formats.WebP private int HashPix(uint argb, int shift) { - return (int)((argb * KHashMul) >> shift); + return (int)((argb * HashMul) >> shift); } } } diff --git a/src/ImageSharp/Formats/WebP/Vp8LBitReader.cs b/src/ImageSharp/Formats/WebP/Vp8LBitReader.cs index 8938124728..97a1c242f1 100644 --- a/src/ImageSharp/Formats/WebP/Vp8LBitReader.cs +++ b/src/ImageSharp/Formats/WebP/Vp8LBitReader.cs @@ -27,7 +27,7 @@ namespace SixLabors.ImageSharp.Formats.WebP /// private const int Vp8LWbits = 32; - private readonly uint[] kBitMask = + private readonly uint[] BitMask = { 0, 0x000001, 0x000003, 0x000007, 0x00000f, @@ -106,7 +106,7 @@ namespace SixLabors.ImageSharp.Formats.WebP if (!this.eos && nBits <= Vp8LMaxNumBitRead) { - ulong val = this.PrefetchBits() & this.kBitMask[nBits]; + ulong val = this.PrefetchBits() & this.BitMask[nBits]; int newBits = this.bitPos + nBits; this.bitPos = newBits; this.ShiftBytes(); diff --git a/src/ImageSharp/Formats/WebP/Vp8QuantMatrix.cs b/src/ImageSharp/Formats/WebP/Vp8QuantMatrix.cs index aaca802851..a5d718a483 100644 --- a/src/ImageSharp/Formats/WebP/Vp8QuantMatrix.cs +++ b/src/ImageSharp/Formats/WebP/Vp8QuantMatrix.cs @@ -9,7 +9,7 @@ namespace SixLabors.ImageSharp.Formats.WebP public int[] Y2Mat { get; set; } - public int[] UVMat { get; set; } + public int[] UvMat { get; set; } /// /// Gets or sets the U/V quantizer value. diff --git a/src/ImageSharp/Formats/WebP/WebPConstants.cs b/src/ImageSharp/Formats/WebP/WebPConstants.cs index 19babc4a34..fe9d93308a 100644 --- a/src/ImageSharp/Formats/WebP/WebPConstants.cs +++ b/src/ImageSharp/Formats/WebP/WebPConstants.cs @@ -90,15 +90,15 @@ namespace SixLabors.ImageSharp.Formats.WebP public const int LengthTableBits = 7; - public const uint KCodeLengthLiterals = 16; + public const uint CodeLengthLiterals = 16; - public const int KCodeLengthRepeatCode = 16; + public const int CodeLengthRepeatCode = 16; - public static readonly int[] KCodeLengthExtraBits = { 2, 3, 7 }; + public static readonly int[] CodeLengthExtraBits = { 2, 3, 7 }; - public static readonly int[] KCodeLengthRepeatOffsets = { 3, 3, 11 }; + public static readonly int[] CodeLengthRepeatOffsets = { 3, 3, 11 }; - public static readonly int[] KAlphabetSize = + public static readonly int[] AlphabetSize = { NumLiteralCodes + NumLengthCodes, NumLiteralCodes, NumLiteralCodes, NumLiteralCodes, @@ -131,6 +131,7 @@ namespace SixLabors.ImageSharp.Formats.WebP 138, 140, 143, 145, 148, 151, 154, 157 }; + // Paragraph 14.1 public static readonly int[] AcTable = { 4, 5, 6, 7, 8, 9, 10, 11, @@ -150,5 +151,11 @@ namespace SixLabors.ImageSharp.Formats.WebP 213, 217, 221, 225, 229, 234, 239, 245, 249, 254, 259, 264, 269, 274, 279, 284 }; + + // Paragraph 9.9 + public static readonly int[] Bands = + { + 0, 1, 2, 3, 6, 4, 5, 6, 6, 6, 6, 6, 6, 6, 6, 7, 0 + }; } } diff --git a/src/ImageSharp/Formats/WebP/WebPDecoderCore.cs b/src/ImageSharp/Formats/WebP/WebPDecoderCore.cs index 8de4c350a9..35eed2ed72 100644 --- a/src/ImageSharp/Formats/WebP/WebPDecoderCore.cs +++ b/src/ImageSharp/Formats/WebP/WebPDecoderCore.cs @@ -492,8 +492,8 @@ namespace SixLabors.ImageSharp.Formats.WebP m.Y2Mat[1] = 8; } - m.UVMat[0] = WebPConstants.DcTable[this.Clip(q + dquvDc, 117)]; - m.UVMat[1] = WebPConstants.AcTable[this.Clip(q + dquvAc, 127)]; + m.UvMat[0] = WebPConstants.DcTable[this.Clip(q + dquvDc, 117)]; + m.UvMat[1] = WebPConstants.AcTable[this.Clip(q + dquvAc, 127)]; // For dithering strength evaluation. m.UvQuant = q + dquvAc; diff --git a/src/ImageSharp/Formats/WebP/WebPLosslessDecoder.cs b/src/ImageSharp/Formats/WebP/WebPLosslessDecoder.cs index ab4dd63069..86fd34bae8 100644 --- a/src/ImageSharp/Formats/WebP/WebPLosslessDecoder.cs +++ b/src/ImageSharp/Formats/WebP/WebPLosslessDecoder.cs @@ -380,7 +380,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.AlphabetSize[j]; if (j == 0 && colorCacheBits > 0) { alphabetSize += 1 << colorCacheBits; @@ -406,7 +406,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.AlphabetSize[j]; if (j == 0 && colorCacheBits > 0) { alphabetSize += 1 << colorCacheBits; @@ -560,7 +560,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.CodeLengthLiterals) { codeLengths[symbol++] = (int)codeLen; if (codeLen != 0) @@ -570,10 +570,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.CodeLengthRepeatCode; + uint slot = codeLen - WebPConstants.CodeLengthLiterals; + int extraBits = WebPConstants.CodeLengthExtraBits[slot]; + int repeatOffset = WebPConstants.CodeLengthRepeatOffsets[slot]; int repeat = (int)(this.bitReader.ReadValue(extraBits) + repeatOffset); if (symbol + repeat > numSymbols) {