Browse Source

Add tests with and without avx

pull/1824/head
Brian Popow 4 years ago
parent
commit
0e3eda9840
  1. 34
      src/ImageSharp/Formats/Webp/Lossless/PredictorEncoder.cs
  2. 6
      tests/ImageSharp.Tests/Formats/WebP/PredictorEncoderTests.cs

34
src/ImageSharp/Formats/Webp/Lossless/PredictorEncoder.cs

@ -587,19 +587,17 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
return (byte)lower;
}
else
{
// upper is closer to residual than lower.
if (residual <= boundaryResidual && upper > boundaryResidual)
{
// Halve quantization step to avoid crossing boundary. This midpoint is
// on the same side of boundary as residual because midpoint <= residual
// (since upper is closer than lower) and residual is below the boundary.
return (byte)(lower + (quantization >> 1));
}
return (byte)(upper & 0xff);
// upper is closer to residual than lower.
if (residual <= boundaryResidual && upper > boundaryResidual)
{
// Halve quantization step to avoid crossing boundary. This midpoint is
// on the same side of boundary as residual because midpoint <= residual
// (since upper is closer than lower) and residual is below the boundary.
return (byte)(lower + (quantization >> 1));
}
return (byte)(upper & 0xff);
}
/// <summary>
@ -1075,7 +1073,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
private static void CollectColorRedTransforms(Span<uint> bgra, int stride, int tileWidth, int tileHeight, int greenToRed, Span<int> histo)
{
#if SUPPORTS_RUNTIME_INTRINSICS
if (Avx2.IsSupported && tileWidth > 16)
if (Avx2.IsSupported && tileWidth >= 16)
{
var multsg = Vector256.Create(LosslessUtils.Cst5b(greenToRed));
const int span = 16;
@ -1182,7 +1180,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
private static void CollectColorBlueTransforms(Span<uint> bgra, int stride, int tileWidth, int tileHeight, int greenToBlue, int redToBlue, Span<int> histo)
{
#if SUPPORTS_RUNTIME_INTRINSICS
if (Avx2.IsSupported && tileWidth > 16)
if (Avx2.IsSupported && tileWidth >= 16)
{
const int span = 16;
Span<ushort> values = stackalloc ushort[span];
@ -1219,12 +1217,12 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
++histo[values[i]];
}
}
}
int leftOver = tileWidth & (span - 1);
if (leftOver > 0)
{
CollectColorBlueTransformsNoneVectorized(bgra.Slice(tileWidth - leftOver), stride, leftOver, tileHeight, greenToBlue, redToBlue, histo);
}
int leftOver = tileWidth & (span - 1);
if (leftOver > 0)
{
CollectColorBlueTransformsNoneVectorized(bgra.Slice(tileWidth - leftOver), stride, leftOver, tileHeight, greenToBlue, redToBlue, histo);
}
}
else if (Sse41.IsSupported)

6
tests/ImageSharp.Tests/Formats/WebP/PredictorEncoderTests.cs

@ -40,8 +40,13 @@ namespace SixLabors.ImageSharp.Tests.Formats.Webp
[Fact]
public void ColorSpaceTransform_WithBikeImage_WithoutSSE41_Works()
=> FeatureTestRunner.RunWithHwIntrinsicsFeature(ColorSpaceTransform_WithBikeImage_ProducesExpectedData, HwIntrinsics.DisableSSE41);
[Fact]
public void ColorSpaceTransform_WithBikeImage_WithoutAvx2_Works()
=> FeatureTestRunner.RunWithHwIntrinsicsFeature(ColorSpaceTransform_WithBikeImage_ProducesExpectedData, HwIntrinsics.DisableAVX2);
#endif
// Test image: Input\Webp\peak.png
private static void RunColorSpaceTransformTestWithPeakImage()
{
// arrange
@ -99,6 +104,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Webp
Assert.Equal(expectedData, transformData);
}
// Test image: Input\Png\Bike.png
private static void RunColorSpaceTransformTestWithBikeImage()
{
// arrange

Loading…
Cancel
Save