Browse Source

Swap best bitwriter and histo reference instead of cloning

pull/1552/head
Brian Popow 5 years ago
parent
commit
4265668072
  1. 9
      src/ImageSharp/Formats/WebP/Lossless/PredictorEncoder.cs
  2. 5
      src/ImageSharp/Formats/WebP/Lossless/Vp8LEncoder.cs
  3. 2
      src/ImageSharp/Formats/WebP/Lossy/Vp8EncIterator.cs
  4. 6
      tests/ImageSharp.Tests/Formats/WebP/WebpEncoderTests.cs
  5. 1
      tests/ImageSharp.Tests/TestImages.cs
  6. 3
      tests/Images/Input/WebP/rgb_pattern_80x80.png

9
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;
}

5
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;

2
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);
}
/// <summary>

6
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<TPixel>(TestImageProvider<TPixel> provider, int nearLosslessQuality)
where TPixel : unmanaged, IPixel<TPixel>

1
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.

3
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
Loading…
Cancel
Save