Browse Source

Add tests with and without avx

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

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

@ -587,8 +587,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
return (byte)lower; return (byte)lower;
} }
else
{
// upper is closer to residual than lower. // upper is closer to residual than lower.
if (residual <= boundaryResidual && upper > boundaryResidual) if (residual <= boundaryResidual && upper > boundaryResidual)
{ {
@ -600,7 +599,6 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
return (byte)(upper & 0xff); return (byte)(upper & 0xff);
} }
}
/// <summary> /// <summary>
/// Converts pixels of the image to residuals with respect to predictions. /// Converts pixels of the image to residuals with respect to predictions.
@ -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) private static void CollectColorRedTransforms(Span<uint> bgra, int stride, int tileWidth, int tileHeight, int greenToRed, Span<int> histo)
{ {
#if SUPPORTS_RUNTIME_INTRINSICS #if SUPPORTS_RUNTIME_INTRINSICS
if (Avx2.IsSupported && tileWidth > 16) if (Avx2.IsSupported && tileWidth >= 16)
{ {
var multsg = Vector256.Create(LosslessUtils.Cst5b(greenToRed)); var multsg = Vector256.Create(LosslessUtils.Cst5b(greenToRed));
const int span = 16; 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) 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 SUPPORTS_RUNTIME_INTRINSICS
if (Avx2.IsSupported && tileWidth > 16) if (Avx2.IsSupported && tileWidth >= 16)
{ {
const int span = 16; const int span = 16;
Span<ushort> values = stackalloc ushort[span]; Span<ushort> values = stackalloc ushort[span];
@ -1219,6 +1217,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
++histo[values[i]]; ++histo[values[i]];
} }
} }
}
int leftOver = tileWidth & (span - 1); int leftOver = tileWidth & (span - 1);
if (leftOver > 0) if (leftOver > 0)
@ -1226,7 +1225,6 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
CollectColorBlueTransformsNoneVectorized(bgra.Slice(tileWidth - leftOver), stride, leftOver, tileHeight, greenToBlue, redToBlue, histo); CollectColorBlueTransformsNoneVectorized(bgra.Slice(tileWidth - leftOver), stride, leftOver, tileHeight, greenToBlue, redToBlue, histo);
} }
} }
}
else if (Sse41.IsSupported) else if (Sse41.IsSupported)
{ {
const int span = 8; const int span = 8;

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

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

Loading…
Cancel
Save