Browse Source

Fix warnings

pull/1552/head
Brian Popow 5 years ago
parent
commit
3c2cc0c52e
  1. 1
      src/ImageSharp/Formats/WebP/BitReader/BitReaderBase.cs
  2. 2
      src/ImageSharp/Formats/WebP/Lossless/BackwardReferenceEncoder.cs
  3. 211
      src/ImageSharp/Formats/WebP/Lossless/LosslessUtils.cs
  4. 4
      src/ImageSharp/Formats/WebP/Lossless/NearLosslessEnc.cs
  5. 10
      src/ImageSharp/Formats/WebP/Lossless/PredictorEncoder.cs
  6. 3
      src/ImageSharp/Formats/WebP/Lossless/WebpLosslessDecoder.cs
  7. 3
      src/ImageSharp/Formats/WebP/Lossy/Vp8EncIterator.cs
  8. 1
      src/ImageSharp/Formats/WebP/Lossy/Vp8Encoder.cs
  9. 1
      src/ImageSharp/Formats/WebP/Lossy/WebpLossyDecoder.cs
  10. 22
      src/ImageSharp/Formats/WebP/Lossy/YuvConversion.cs
  11. 1
      src/ImageSharp/Formats/WebP/WebpDecoder.cs
  12. 2
      src/ImageSharp/Formats/WebP/WebpLookupTables.cs
  13. 7
      tests/ImageSharp.Tests/Formats/WebP/WebpDecoderTests.cs

1
src/ImageSharp/Formats/WebP/BitReader/BitReaderBase.cs

@ -4,7 +4,6 @@
using System; using System;
using System.Buffers; using System.Buffers;
using System.IO; using System.IO;
using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Memory;
namespace SixLabors.ImageSharp.Formats.Webp.BitReader namespace SixLabors.ImageSharp.Formats.Webp.BitReader

2
src/ImageSharp/Formats/WebP/Lossless/BackwardReferenceEncoder.cs

@ -639,7 +639,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
{ {
// Figure out if we should use the offset/length from the previous pixel // Figure out if we should use the offset/length from the previous pixel
// as an initial guess and therefore only inspect the offsets in windowOffsetsNew[]. // as an initial guess and therefore only inspect the offsets in windowOffsetsNew[].
bool usePrev = bestLengthPrev > 1 && bestLengthPrev < MaxLength; bool usePrev = bestLengthPrev is > 1 and < MaxLength;
int numInd = usePrev ? windowOffsetsNewSize : windowOffsetsSize; int numInd = usePrev ? windowOffsetsNewSize : windowOffsetsSize;
bestLength = usePrev ? bestLengthPrev - 1 : 0; bestLength = usePrev ? bestLengthPrev - 1 : 0;
bestOffset = usePrev ? bestOffsetPrev : 0; bestOffset = usePrev ? bestOffsetPrev : 0;

211
src/ImageSharp/Formats/WebP/Lossless/LosslessUtils.cs

@ -5,7 +5,6 @@ using System;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Memory;
#if SUPPORTS_RUNTIME_INTRINSICS #if SUPPORTS_RUNTIME_INTRINSICS
using System.Runtime.Intrinsics; using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.X86; using System.Runtime.Intrinsics.X86;
@ -67,30 +66,26 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
{ {
if (distance < PrefixLookupIdxMax) if (distance < PrefixLookupIdxMax)
{ {
(int code, int extraBits) prefixCode = WebpLookupTables.PrefixEncodeCode[distance]; (int Code, int ExtraBits) prefixCode = WebpLookupTables.PrefixEncodeCode[distance];
extraBits = prefixCode.extraBits; extraBits = prefixCode.ExtraBits;
return prefixCode.code; return prefixCode.Code;
}
else
{
return PrefixEncodeBitsNoLut(distance, ref extraBits);
} }
return PrefixEncodeBitsNoLut(distance, ref extraBits);
} }
public static int PrefixEncode(int distance, ref int extraBits, ref int extraBitsValue) public static int PrefixEncode(int distance, ref int extraBits, ref int extraBitsValue)
{ {
if (distance < PrefixLookupIdxMax) if (distance < PrefixLookupIdxMax)
{ {
(int code, int extraBits) prefixCode = WebpLookupTables.PrefixEncodeCode[distance]; (int Code, int ExtraBits) prefixCode = WebpLookupTables.PrefixEncodeCode[distance];
extraBits = prefixCode.extraBits; extraBits = prefixCode.ExtraBits;
extraBitsValue = WebpLookupTables.PrefixEncodeExtraBitsValue[distance]; extraBitsValue = WebpLookupTables.PrefixEncodeExtraBitsValue[distance];
return prefixCode.code; return prefixCode.Code;
}
else
{
return PrefixEncodeNoLut(distance, ref extraBits, ref extraBitsValue);
} }
return PrefixEncodeNoLut(distance, ref extraBits, ref extraBitsValue);
} }
/// <summary> /// <summary>
@ -402,9 +397,9 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
var maskalphagreen = Vector128.Create(0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255); var maskalphagreen = Vector128.Create(0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255);
var maskredblue = Vector128.Create(255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0); var maskredblue = Vector128.Create(255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0);
byte shufflemask = SimdUtils.Shuffle.MmShuffle(2, 2, 0, 0); byte shufflemask = SimdUtils.Shuffle.MmShuffle(2, 2, 0, 0);
int idx;
fixed (uint* src = data) fixed (uint* src = data)
{ {
int idx;
for (idx = 0; idx + 4 <= numPixels; idx += 4) for (idx = 0; idx + 4 <= numPixels; idx += 4)
{ {
uint* pos = src + idx; uint* pos = src + idx;
@ -535,104 +530,106 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
Span<uint> outputSpan) Span<uint> outputSpan)
{ {
fixed (uint* inputFixed = pixelData) fixed (uint* inputFixed = pixelData)
fixed (uint* outputFixed = outputSpan)
{ {
uint* input = inputFixed; fixed (uint* outputFixed = outputSpan)
uint* output = outputFixed;
int width = transform.XSize;
Span<uint> transformData = transform.Data.GetSpan();
// First Row follows the L (mode=1) mode.
PredictorAdd0(input, 1, output);
PredictorAdd1(input + 1, width - 1, output + 1);
input += width;
output += width;
int y = 1;
int yEnd = transform.YSize;
int tileWidth = 1 << transform.Bits;
int mask = tileWidth - 1;
int tilesPerRow = SubSampleSize(width, transform.Bits);
int predictorModeIdxBase = (y >> transform.Bits) * tilesPerRow;
while (y < yEnd)
{ {
int predictorModeIdx = predictorModeIdxBase; uint* input = inputFixed;
int x = 1; uint* output = outputFixed;
// First pixel follows the T (mode=2) mode. int width = transform.XSize;
PredictorAdd2(input, output - width, 1, output); Span<uint> transformData = transform.Data.GetSpan();
// .. the rest: // First Row follows the L (mode=1) mode.
while (x < width) PredictorAdd0(input, 1, output);
PredictorAdd1(input + 1, width - 1, output + 1);
input += width;
output += width;
int y = 1;
int yEnd = transform.YSize;
int tileWidth = 1 << transform.Bits;
int mask = tileWidth - 1;
int tilesPerRow = SubSampleSize(width, transform.Bits);
int predictorModeIdxBase = (y >> transform.Bits) * tilesPerRow;
while (y < yEnd)
{ {
uint predictorMode = (transformData[predictorModeIdx++] >> 8) & 0xf; int predictorModeIdx = predictorModeIdxBase;
int xEnd = (x & ~mask) + tileWidth; int x = 1;
if (xEnd > width)
{ // First pixel follows the T (mode=2) mode.
xEnd = width; PredictorAdd2(input, output - width, 1, output);
}
// There are 14 different prediction modes. // .. the rest:
// In each prediction mode, the current pixel value is predicted from one while (x < width)
// or more neighboring pixels whose values are already known.
switch (predictorMode)
{ {
case 0: uint predictorMode = (transformData[predictorModeIdx++] >> 8) & 0xf;
PredictorAdd0(input + x, xEnd - x, output + x); int xEnd = (x & ~mask) + tileWidth;
break; if (xEnd > width)
case 1: {
PredictorAdd1(input + x, xEnd - x, output + x); xEnd = width;
break; }
case 2:
PredictorAdd2(input + x, output + x - width, xEnd - x, output + x); // There are 14 different prediction modes.
break; // In each prediction mode, the current pixel value is predicted from one
case 3: // or more neighboring pixels whose values are already known.
PredictorAdd3(input + x, output + x - width, xEnd - x, output + x); switch (predictorMode)
break; {
case 4: case 0:
PredictorAdd4(input + x, output + x - width, xEnd - x, output + x); PredictorAdd0(input + x, xEnd - x, output + x);
break; break;
case 5: case 1:
PredictorAdd5(input + x, output + x - width, xEnd - x, output + x); PredictorAdd1(input + x, xEnd - x, output + x);
break; break;
case 6: case 2:
PredictorAdd6(input + x, output + x - width, xEnd - x, output + x); PredictorAdd2(input + x, output + x - width, xEnd - x, output + x);
break; break;
case 7: case 3:
PredictorAdd7(input + x, output + x - width, xEnd - x, output + x); PredictorAdd3(input + x, output + x - width, xEnd - x, output + x);
break; break;
case 8: case 4:
PredictorAdd8(input + x, output + x - width, xEnd - x, output + x); PredictorAdd4(input + x, output + x - width, xEnd - x, output + x);
break; break;
case 9: case 5:
PredictorAdd9(input + x, output + x - width, xEnd - x, output + x); PredictorAdd5(input + x, output + x - width, xEnd - x, output + x);
break; break;
case 10: case 6:
PredictorAdd10(input + x, output + x - width, xEnd - x, output + x); PredictorAdd6(input + x, output + x - width, xEnd - x, output + x);
break; break;
case 11: case 7:
PredictorAdd11(input + x, output + x - width, xEnd - x, output + x); PredictorAdd7(input + x, output + x - width, xEnd - x, output + x);
break; break;
case 12: case 8:
PredictorAdd12(input + x, output + x - width, xEnd - x, output + x); PredictorAdd8(input + x, output + x - width, xEnd - x, output + x);
break; break;
case 13: case 9:
PredictorAdd13(input + x, output + x - width, xEnd - x, output + x); PredictorAdd9(input + x, output + x - width, xEnd - x, output + x);
break; break;
case 10:
PredictorAdd10(input + x, output + x - width, xEnd - x, output + x);
break;
case 11:
PredictorAdd11(input + x, output + x - width, xEnd - x, output + x);
break;
case 12:
PredictorAdd12(input + x, output + x - width, xEnd - x, output + x);
break;
case 13:
PredictorAdd13(input + x, output + x - width, xEnd - x, output + x);
break;
}
x = xEnd;
} }
x = xEnd; input += width;
} output += width;
++y;
input += width; if ((y & mask) == 0)
output += width; {
++y; // Use the same mask, since tiles are squares.
predictorModeIdxBase += tilesPerRow;
if ((y & mask) == 0) }
{
// Use the same mask, since tiles are squares.
predictorModeIdxBase += tilesPerRow;
} }
} }
} }
@ -839,10 +836,8 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
return (float)log2; return (float)log2;
} }
else
{ return (float)(Log2Reciprocal * Math.Log(v));
return (float)(Log2Reciprocal * Math.Log(v));
}
} }
/// <summary> /// <summary>

4
src/ImageSharp/Formats/WebP/Lossless/NearLosslessEnc.cs

@ -39,7 +39,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
// Adjusts pixel values of image with given maximum error. // Adjusts pixel values of image with given maximum error.
private static void NearLossless(int xSize, int ySize, Span<uint> argbSrc, int stride, int limitBits, Span<uint> copyBuffer, Span<uint> argbDst) private static void NearLossless(int xSize, int ySize, Span<uint> argbSrc, int stride, int limitBits, Span<uint> copyBuffer, Span<uint> argbDst)
{ {
int x, y; int y;
int limit = 1 << limitBits; int limit = 1 << limitBits;
Span<uint> prevRow = copyBuffer; Span<uint> prevRow = copyBuffer;
Span<uint> currRow = copyBuffer.Slice(xSize, xSize); Span<uint> currRow = copyBuffer.Slice(xSize, xSize);
@ -60,7 +60,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
argbSrc.Slice(srcOffset + stride, xSize).CopyTo(nextRow); argbSrc.Slice(srcOffset + stride, xSize).CopyTo(nextRow);
argbDst[dstOffset] = argbSrc[srcOffset]; argbDst[dstOffset] = argbSrc[srcOffset];
argbDst[dstOffset + xSize - 1] = argbSrc[srcOffset + xSize - 1]; argbDst[dstOffset + xSize - 1] = argbSrc[srcOffset + xSize - 1];
for (x = 1; x < xSize - 1; ++x) for (int x = 1; x < xSize - 1; ++x)
{ {
if (IsSmooth(prevRow, currRow, nextRow, x, limit)) if (IsSmooth(prevRow, currRow, nextRow, x, limit))
{ {

10
src/ImageSharp/Formats/WebP/Lossless/PredictorEncoder.cs

@ -341,6 +341,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
} }
else else
{ {
#pragma warning disable SA1503 // Braces should not be omitted
fixed (uint* currentRow = currentRowSpan) fixed (uint* currentRow = currentRowSpan)
fixed (uint* upperRow = upperRowSpan) fixed (uint* upperRow = upperRowSpan)
{ {
@ -454,6 +455,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
} }
} }
} }
#pragma warning restore SA1503 // Braces should not be omitted
/// <summary> /// <summary>
/// Quantize every component of the difference between the actual pixel value and /// Quantize every component of the difference between the actual pixel value and
@ -478,7 +480,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
quantization >>= 1; quantization >>= 1;
} }
if (value >> 24 == 0 || value >> 24 == 0xff) if (value >> 24 is 0 or 0xff)
{ {
// Preserve transparency of fully transparent or fully opaque pixels. // Preserve transparency of fully transparent or fully opaque pixels.
a = NearLosslessDiff((byte)((value >> 24) & 0xff), (byte)((predict >> 24) & 0xff)); a = NearLosslessDiff((byte)((value >> 24) & 0xff), (byte)((predict >> 24) & 0xff));
@ -649,6 +651,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
Span<uint> upperSpan, Span<uint> upperSpan,
Span<uint> outputSpan) Span<uint> outputSpan)
{ {
#pragma warning disable SA1503 // Braces should not be omitted
fixed (uint* current = currentSpan) fixed (uint* current = currentSpan)
fixed (uint* upper = upperSpan) fixed (uint* upper = upperSpan)
fixed (uint* outputFixed = outputSpan) fixed (uint* outputFixed = outputSpan)
@ -727,6 +730,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
} }
} }
} }
#pragma warning restore SA1503 // Braces should not be omitted
private static void MaxDiffsForRow(int width, int stride, Span<uint> argb, int offset, Span<byte> maxDiffs, bool usedSubtractGreen) private static void MaxDiffsForRow(int width, int stride, Span<uint> argb, int offset, Span<byte> maxDiffs, bool usedSubtractGreen)
{ {
@ -990,6 +994,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
for (int y = 0; y < tileHeight; ++y) for (int y = 0; y < tileHeight; ++y)
{ {
Span<uint> srcSpan = bgra.Slice(y * stride); Span<uint> srcSpan = bgra.Slice(y * stride);
#pragma warning disable SA1503 // Braces should not be omitted
fixed (uint* src = srcSpan) fixed (uint* src = srcSpan)
fixed (ushort* dst = values) fixed (ushort* dst = values)
{ {
@ -1016,6 +1021,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
} }
} }
} }
#pragma warning restore SA1503 // Braces should not be omitted
int leftOver = tileWidth & (span - 1); int leftOver = tileWidth & (span - 1);
if (leftOver > 0) if (leftOver > 0)
@ -1063,6 +1069,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
for (int y = 0; y < tileHeight; ++y) for (int y = 0; y < tileHeight; ++y)
{ {
Span<uint> srcSpan = bgra.Slice(y * stride); Span<uint> srcSpan = bgra.Slice(y * stride);
#pragma warning disable SA1503 // Braces should not be omitted
fixed (uint* src = srcSpan) fixed (uint* src = srcSpan)
fixed (ushort* dst = values) fixed (ushort* dst = values)
{ {
@ -1092,6 +1099,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
} }
} }
} }
#pragma warning restore SA1503 // Braces should not be omitted
int leftOver = tileWidth & (span - 1); int leftOver = tileWidth & (span - 1);
if (leftOver > 0) if (leftOver > 0)

3
src/ImageSharp/Formats/WebP/Lossless/WebpLosslessDecoder.cs

@ -6,7 +6,6 @@ using System.Buffers;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Formats.Webp.BitReader; using SixLabors.ImageSharp.Formats.Webp.BitReader;
using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
@ -147,7 +146,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
// Note: According to webpinfo color cache bits of 11 are valid, even though 10 is defined in the source code as maximum. // Note: According to webpinfo color cache bits of 11 are valid, even though 10 is defined in the source code as maximum.
// That is why 11 bits is also considered valid here. // That is why 11 bits is also considered valid here.
bool colorCacheBitsIsValid = colorCacheBits >= 1 && colorCacheBits <= WebpConstants.MaxColorCacheBits + 1; bool colorCacheBitsIsValid = colorCacheBits is >= 1 and <= WebpConstants.MaxColorCacheBits + 1;
if (!colorCacheBitsIsValid) if (!colorCacheBitsIsValid)
{ {
WebpThrowHelper.ThrowImageFormatException("Invalid color cache bits found"); WebpThrowHelper.ThrowImageFormatException("Invalid color cache bits found");

3
src/ImageSharp/Formats/WebP/Lossy/Vp8EncIterator.cs

@ -400,7 +400,6 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
{ {
byte[] modes = new byte[16]; byte[] modes = new byte[16];
int maxMode = MaxIntra4Mode; int maxMode = MaxIntra4Mode;
int i4Alpha;
var totalHisto = new Vp8Histogram(); var totalHisto = new Vp8Histogram();
int curHisto = 0; int curHisto = 0;
this.StartI4(); this.StartI4();
@ -433,7 +432,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
} }
while (this.RotateI4(this.YuvIn.AsSpan(YOffEnc))); // Note: we reuse the original samples for predictors. while (this.RotateI4(this.YuvIn.AsSpan(YOffEnc))); // Note: we reuse the original samples for predictors.
i4Alpha = totalHisto.GetAlpha(); var i4Alpha = totalHisto.GetAlpha();
if (i4Alpha > bestAlpha) if (i4Alpha > bestAlpha)
{ {
this.SetIntra4Mode(modes); this.SetIntra4Mode(modes);

1
src/ImageSharp/Formats/WebP/Lossy/Vp8Encoder.cs

@ -5,7 +5,6 @@ using System;
using System.Buffers; using System.Buffers;
using System.IO; using System.IO;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats.Webp.BitWriter; using SixLabors.ImageSharp.Formats.Webp.BitWriter;
using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;

1
src/ImageSharp/Formats/WebP/Lossy/WebpLossyDecoder.cs

@ -5,7 +5,6 @@ using System;
using System.Buffers; using System.Buffers;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Formats.Webp.BitReader; using SixLabors.ImageSharp.Formats.Webp.BitReader;
using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;

22
src/ImageSharp/Formats/WebP/Lossy/YuvConversion.cs

@ -140,17 +140,20 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
GammaToLinear(bgra0.R) + GammaToLinear(bgra0.R) +
GammaToLinear(bgra1.R) + GammaToLinear(bgra1.R) +
GammaToLinear(bgra2.R) + GammaToLinear(bgra2.R) +
GammaToLinear(bgra3.R), 0); GammaToLinear(bgra3.R),
0);
dst[dstIdx + 1] = (ushort)LinearToGamma( dst[dstIdx + 1] = (ushort)LinearToGamma(
GammaToLinear(bgra0.G) + GammaToLinear(bgra0.G) +
GammaToLinear(bgra1.G) + GammaToLinear(bgra1.G) +
GammaToLinear(bgra2.G) + GammaToLinear(bgra2.G) +
GammaToLinear(bgra3.G), 0); GammaToLinear(bgra3.G),
0);
dst[dstIdx + 2] = (ushort)LinearToGamma( dst[dstIdx + 2] = (ushort)LinearToGamma(
GammaToLinear(bgra0.B) + GammaToLinear(bgra0.B) +
GammaToLinear(bgra1.B) + GammaToLinear(bgra1.B) +
GammaToLinear(bgra2.B) + GammaToLinear(bgra2.B) +
GammaToLinear(bgra3.B), 0); GammaToLinear(bgra3.B),
0);
} }
if ((width & 1) != 0) if ((width & 1) != 0)
@ -178,23 +181,26 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
Bgra32 bgra3 = nextRowSpan[j + 1]; Bgra32 bgra3 = nextRowSpan[j + 1];
uint a = (uint)(bgra0.A + bgra1.A + bgra2.A + bgra3.A); uint a = (uint)(bgra0.A + bgra1.A + bgra2.A + bgra3.A);
int r, g, b; int r, g, b;
if (a == 4 * 0xff || a == 0) if (a is 4 * 0xff or 0)
{ {
r = (ushort)LinearToGamma( r = (ushort)LinearToGamma(
GammaToLinear(bgra0.R) + GammaToLinear(bgra0.R) +
GammaToLinear(bgra1.R) + GammaToLinear(bgra1.R) +
GammaToLinear(bgra2.R) + GammaToLinear(bgra2.R) +
GammaToLinear(bgra3.R), 0); GammaToLinear(bgra3.R),
0);
g = (ushort)LinearToGamma( g = (ushort)LinearToGamma(
GammaToLinear(bgra0.G) + GammaToLinear(bgra0.G) +
GammaToLinear(bgra1.G) + GammaToLinear(bgra1.G) +
GammaToLinear(bgra2.G) + GammaToLinear(bgra2.G) +
GammaToLinear(bgra3.G), 0); GammaToLinear(bgra3.G),
0);
b = (ushort)LinearToGamma( b = (ushort)LinearToGamma(
GammaToLinear(bgra0.B) + GammaToLinear(bgra0.B) +
GammaToLinear(bgra1.B) + GammaToLinear(bgra1.B) +
GammaToLinear(bgra2.B) + GammaToLinear(bgra2.B) +
GammaToLinear(bgra3.B), 0); GammaToLinear(bgra3.B),
0);
} }
else else
{ {
@ -215,7 +221,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
bgra1 = nextRowSpan[j]; bgra1 = nextRowSpan[j];
uint a = (uint)(2u * (bgra0.A + bgra1.A)); uint a = (uint)(2u * (bgra0.A + bgra1.A));
int r, g, b; int r, g, b;
if (a == 4 * 0xff || a == 0) if (a is 4 * 0xff or 0)
{ {
r = (ushort)LinearToGamma(GammaToLinear(bgra0.R) + GammaToLinear(bgra1.R), 1); r = (ushort)LinearToGamma(GammaToLinear(bgra0.R) + GammaToLinear(bgra1.R), 1);
g = (ushort)LinearToGamma(GammaToLinear(bgra0.G) + GammaToLinear(bgra1.G), 1); g = (ushort)LinearToGamma(GammaToLinear(bgra0.G) + GammaToLinear(bgra1.G), 1);

1
src/ImageSharp/Formats/WebP/WebpDecoder.cs

@ -4,7 +4,6 @@
using System.IO; using System.IO;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using SixLabors.ImageSharp.IO; using SixLabors.ImageSharp.IO;
using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;

2
src/ImageSharp/Formats/WebP/WebpLookupTables.cs

@ -974,7 +974,7 @@ namespace SixLabors.ImageSharp.Formats.Webp
} }
}; };
public static readonly (int code, int extraBits)[] PrefixEncodeCode = new (int code, int extraBits)[] public static readonly (int Code, int ExtraBits)[] PrefixEncodeCode =
{ {
(0, 0), (0, 0), (1, 0), (2, 0), (3, 0), (4, 1), (4, 1), (5, 1), (0, 0), (0, 0), (1, 0), (2, 0), (3, 0), (4, 1), (4, 1), (5, 1),
(5, 1), (6, 2), (6, 2), (6, 2), (6, 2), (7, 2), (7, 2), (7, 2), (5, 1), (6, 2), (6, 2), (6, 2), (6, 2), (7, 2), (7, 2), (7, 2),

7
tests/ImageSharp.Tests/Formats/WebP/WebpDecoderTests.cs

@ -2,13 +2,10 @@
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System.IO; using System.IO;
using SixLabors.ImageSharp.Formats.Webp; using SixLabors.ImageSharp.Formats.Webp;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs; using SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs;
using Xunit; using Xunit;
using static SixLabors.ImageSharp.Tests.TestImages.WebP; using static SixLabors.ImageSharp.Tests.TestImages.WebP;
// ReSharper disable InconsistentNaming // ReSharper disable InconsistentNaming
@ -18,9 +15,9 @@ namespace SixLabors.ImageSharp.Tests.Formats.Webp
[Trait("Format", "Webp")] [Trait("Format", "Webp")]
public class WebpDecoderTests public class WebpDecoderTests
{ {
private static WebpDecoder WebpDecoder => new WebpDecoder(); private static WebpDecoder WebpDecoder => new();
private static MagickReferenceDecoder ReferenceDecoder => new MagickReferenceDecoder(); private static MagickReferenceDecoder ReferenceDecoder => new();
[Theory] [Theory]
[InlineData(Lossless.GreenTransform1, 1000, 307, 32)] [InlineData(Lossless.GreenTransform1, 1000, 307, 32)]

Loading…
Cancel
Save