diff --git a/src/ImageSharp/Formats/WebP/Lossless/PredictorEncoder.cs b/src/ImageSharp/Formats/WebP/Lossless/PredictorEncoder.cs index c705a6b2d9..0e36a6c450 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/PredictorEncoder.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/PredictorEncoder.cs @@ -294,12 +294,9 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless if (curDiff < bestDiff) { - // TODO: Consider swapping references - for (int i = 0; i < 4; i++) - { - histoArgb[i].AsSpan().CopyTo(bestHisto[i]); - } - + int[][] tmp = histoArgb; + histoArgb = bestHisto; + bestHisto = tmp; bestDiff = curDiff; bestMode = mode; } diff --git a/src/ImageSharp/Formats/WebP/Lossless/Vp8LEncoder.cs b/src/ImageSharp/Formats/WebP/Lossless/Vp8LEncoder.cs index e337881cf9..497a091483 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/Vp8LEncoder.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/Vp8LEncoder.cs @@ -613,8 +613,9 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless // Keep track of the smallest image so far. if (isFirstIteration || (bitWriterBest != null && this.bitWriter.NumBytes() < bitWriterBest.NumBytes())) { - // TODO: This was done in the reference by swapping references, this will be slower. - bitWriterBest = this.bitWriter.Clone(); + Vp8LBitWriter tmp = this.bitWriter; + this.bitWriter = bitWriterBest; + bitWriterBest = tmp; } isFirstIteration = false; diff --git a/src/ImageSharp/Formats/WebP/Lossy/Vp8EncIterator.cs b/src/ImageSharp/Formats/WebP/Lossy/Vp8EncIterator.cs index 0e1d84243b..63ed1f399b 100644 --- a/src/ImageSharp/Formats/WebP/Lossy/Vp8EncIterator.cs +++ b/src/ImageSharp/Formats/WebP/Lossy/Vp8EncIterator.cs @@ -885,7 +885,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy this.SetCountDown(this.mbw * this.mbh); this.InitTop(); - // TODO: memset(it->bit_count_, 0, sizeof(it->bit_count_)); + Array.Clear(this.BitCount, 0, this.BitCount.Length); } /// diff --git a/tests/ImageSharp.Tests/Formats/WebP/WebpEncoderTests.cs b/tests/ImageSharp.Tests/Formats/WebP/WebpEncoderTests.cs index 223f986292..8831e6054b 100644 --- a/tests/ImageSharp.Tests/Formats/WebP/WebpEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/WebP/WebpEncoderTests.cs @@ -83,9 +83,9 @@ namespace SixLabors.ImageSharp.Tests.Formats.Webp [Theory] [WithFile(RgbTestPattern100x100, PixelTypes.Rgba32, 85)] [WithFile(RgbTestPattern100x100, PixelTypes.Rgba32, 60)] - [WithFile(RgbTestPattern100x100, PixelTypes.Rgba32, 40)] - [WithFile(RgbTestPattern100x100, PixelTypes.Rgba32, 20)] - [WithFile(RgbTestPattern100x100, PixelTypes.Rgba32, 10)] + [WithFile(RgbTestPattern80x80, PixelTypes.Rgba32, 40)] + [WithFile(RgbTestPattern80x80, PixelTypes.Rgba32, 20)] + [WithFile(RgbTestPattern80x80, PixelTypes.Rgba32, 10)] [WithFile(RgbTestPattern63x63, PixelTypes.Rgba32, 40)] public void Encode_Lossless_WithNearLosslessFlag_Works(TestImageProvider provider, int nearLosslessQuality) where TPixel : unmanaged, IPixel diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs index 37ee5c1c20..1b624ae654 100644 --- a/tests/ImageSharp.Tests/TestImages.cs +++ b/tests/ImageSharp.Tests/TestImages.cs @@ -509,6 +509,7 @@ namespace SixLabors.ImageSharp.Tests public const string TestPatternOpaque = "WebP/testpattern_opaque.png"; public const string TestPatternOpaqueSmall = "WebP/testpattern_opaque_small.png"; public const string RgbTestPattern100x100 = "WebP/rgb_pattern_100x100.png"; + public const string RgbTestPattern80x80 = "WebP/rgb_pattern_80x80.png"; public const string RgbTestPattern63x63 = "WebP/rgb_pattern_63x63.png"; // Test image for encoding image with a palette. diff --git a/tests/Images/Input/WebP/rgb_pattern_80x80.png b/tests/Images/Input/WebP/rgb_pattern_80x80.png new file mode 100644 index 0000000000..d4722cfc13 --- /dev/null +++ b/tests/Images/Input/WebP/rgb_pattern_80x80.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f4e27705d23ff33dbac5bdfe8e7e75a6eeda359ff343594fb07feb29abbc2fb5 +size 19393