Browse Source

Move corrupted images into separate test

pull/1147/head
Brian Popow 6 years ago
parent
commit
026e6589b9
  1. 4
      src/ImageSharp/Formats/WebP/LosslessUtils.cs
  2. 34
      tests/ImageSharp.Tests/Formats/WebP/WebPDecoderTests.cs
  3. 49
      tests/ImageSharp.Tests/TestImages.cs

4
src/ImageSharp/Formats/WebP/LosslessUtils.cs

@ -138,7 +138,6 @@ namespace SixLabors.ImageSharp.Formats.WebP
newBlue += ColorTransformDelta((sbyte)m.RedToBlue, (sbyte)newRed);
newBlue &= 0xff;
uint pixelValue = (uint)((argb & 0xff00ff00u) | (newRed << 16) | newBlue);
pixelData[i] = (uint)((argb & 0xff00ff00u) | (newRed << 16) | newBlue);
}
}
@ -269,7 +268,6 @@ namespace SixLabors.ImageSharp.Formats.WebP
output.AsSpan().CopyTo(pixelData);
}
// TODO: the predictor add methods should be generated
private static void PredictorAdd0(uint[] input, int startIdx, int numberOfPixels, uint[] output)
{
int endIdx = startIdx + numberOfPixels;
@ -614,7 +612,7 @@ namespace SixLabors.ImageSharp.Formats.WebP
private static int ColorTransformDelta(sbyte colorPred, sbyte color)
{
var delta = ((sbyte)colorPred * color) >> 5;
int delta = ((sbyte)colorPred * color) >> 5;
return ((int)colorPred * color) >> 5;
}

34
tests/ImageSharp.Tests/Formats/WebP/WebPDecoderTests.cs

@ -23,7 +23,11 @@ namespace SixLabors.ImageSharp.Tests.Formats.WebP
[InlineData(Lossy.Alpha.LossyAlpha1, 1000, 307, 24)]
[InlineData(Lossy.Alpha.LossyAlpha2, 1000, 307, 24)]
[InlineData(Animated.Animated1, 400, 400, 24)]
public void Identify_DetectsCorrectDimensions(string imagePath, int expectedWidth, int expectedHeight, int expectedBitsPerPixel)
public void Identify_DetectsCorrectDimensions(
string imagePath,
int expectedWidth,
int expectedHeight,
int expectedBitsPerPixel)
{
var testFile = TestFile.Create(imagePath);
using (var stream = new MemoryStream(testFile.Bytes, false))
@ -38,7 +42,11 @@ namespace SixLabors.ImageSharp.Tests.Formats.WebP
[Theory]
[InlineData(Lossy.Alpha.LossyAlpha1, 1000, 307, 24)]
public void DecodeLossyImage_Tmp(string imagePath, int expectedWidth, int expectedHeight, int expectedBitsPerPixel)
public void DecodeLossyImage_Tmp(
string imagePath,
int expectedWidth,
int expectedHeight,
int expectedBitsPerPixel)
{
var testFile = TestFile.Create(imagePath);
using (var stream = new MemoryStream(testFile.Bytes, false))
@ -67,9 +75,10 @@ namespace SixLabors.ImageSharp.Tests.Formats.WebP
[WithFile(Lossless.GreenTransform2, PixelTypes.Rgba32)]
[WithFile(Lossless.GreenTransform3, PixelTypes.Rgba32)]
[WithFile(Lossless.GreenTransform4, PixelTypes.Rgba32)]
// TODO: Reference decoder throws here MagickCorruptImageErrorException
//[WithFile(Lossless.GreenTransform5, PixelTypes.Rgba32)]
public void WebpDecoder_CanDecode_Lossless_WithSubstractGreenTransform<TPixel>(TestImageProvider<TPixel> provider)
// TODO: Reference decoder throws here MagickCorruptImageErrorException, webpinfo also indicates an error here, but decoding the image seems to work.
// [WithFile(Lossless.GreenTransform5, PixelTypes.Rgba32)]
public void WebpDecoder_CanDecode_Lossless_WithSubstractGreenTransform<TPixel>(
TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(new WebPDecoder()))
@ -135,9 +144,6 @@ namespace SixLabors.ImageSharp.Tests.Formats.WebP
[WithFile(Lossless.TwoTransforms11, PixelTypes.Rgba32)]
[WithFile(Lossless.TwoTransforms12, PixelTypes.Rgba32)]
[WithFile(Lossless.TwoTransforms13, PixelTypes.Rgba32)]
[WithFile(Lossless.TwoTransforms14, PixelTypes.Rgba32)]
[WithFile(Lossless.TwoTransforms15, PixelTypes.Rgba32)]
[WithFile(Lossless.TwoTransforms16, PixelTypes.Rgba32)]
public void WebpDecoder_CanDecode_Lossless_WithTwoTransforms<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
@ -156,7 +162,6 @@ namespace SixLabors.ImageSharp.Tests.Formats.WebP
[WithFile(Lossless.ThreeTransforms5, PixelTypes.Rgba32)]
[WithFile(Lossless.ThreeTransforms6, PixelTypes.Rgba32)]
[WithFile(Lossless.ThreeTransforms7, PixelTypes.Rgba32)]
[WithFile(Lossless.ThreeTransforms8, PixelTypes.Rgba32)]
public void WebpDecoder_CanDecode_Lossless_WithThreeTransforms<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
@ -166,5 +171,16 @@ namespace SixLabors.ImageSharp.Tests.Formats.WebP
image.CompareToOriginal(provider, new MagickReferenceDecoder());
}
}
[Theory]
[WithFile(Lossless.LossLessCorruptImage1, PixelTypes.Rgba32)]
[WithFile(Lossless.LossLessCorruptImage2, PixelTypes.Rgba32)]
[WithFile(Lossless.LossLessCorruptImage3, PixelTypes.Rgba32)]
[WithFile(Lossless.LossLessCorruptImage4, PixelTypes.Rgba32)]
public void WebpDecoder_ThrowImageFormatException_OnInvalidImages<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
Assert.Throws<ImageFormatException>(() => { using (provider.GetImage(new WebPDecoder())) { } });
}
}
}

49
tests/ImageSharp.Tests/TestImages.cs

@ -396,30 +396,33 @@ namespace SixLabors.ImageSharp.Tests
public const string ColorIndexTransform3 = "WebP/lossless_vec_1_5.webp";
public const string ColorIndexTransform4 = "WebP/lossless_vec_2_1.webp";
public const string ColorIndexTransform5 = "WebP/lossless_vec_2_5.webp";
public const string TwoTransforms1 = "Webp/lossless_color_transform.webp"; // cross_color, predictor
public const string TwoTransforms2 = "Webp/lossless_vec_1_10.webp"; // cross_color, predictor
public const string TwoTransforms3 = "Webp/lossless_vec_1_12.webp"; // cross_color, substract_green
public const string TwoTransforms4 = "Webp/lossless_vec_1_13.webp"; // color_indexing, cross_color
public const string TwoTransforms5 = "Webp/lossless_vec_1_3.webp"; // color_indexing, predictor
public const string TwoTransforms6 = "Webp/lossless_vec_1_6.webp"; // substract_green, predictor
public const string TwoTransforms7 = "Webp/lossless_vec_1_7.webp"; // color_indexing, predictor
public const string TwoTransforms8 = "Webp/lossless_vec_1_9.webp"; // color_indexing, cross_color
public const string TwoTransforms9 = "Webp/lossless_vec_2_10.webp"; // predictor, cross_color
public const string TwoTransforms10 = "Webp/lossless_vec_2_12.webp"; // substract_green, cross_color
public const string TwoTransforms11 = "Webp/lossless_vec_2_13.webp"; // color_indexing, cross_color
public const string TwoTransforms12 = "Webp/lossless_vec_2_3.webp"; // color_indexing, predictor
public const string TwoTransforms13 = "Webp/lossless_vec_2_6.webp"; // substract_green, predictor
public const string TwoTransforms14 = "Webp/lossless_vec_2_7.webp"; // color_indexing, predictor
public const string TwoTransforms15 = "Webp/lossless_vec_2_9.webp"; // color_indexing, predictor
public const string TwoTransforms16 = "Webp/near_lossless_75.webp"; // predictor, cross_color
public const string TwoTransforms1 = "Webp/lossless_vec_1_10.webp"; // cross_color, predictor
public const string TwoTransforms2 = "Webp/lossless_vec_1_12.webp"; // cross_color, substract_green
public const string TwoTransforms3 = "Webp/lossless_vec_1_13.webp"; // color_indexing, cross_color
public const string TwoTransforms4 = "Webp/lossless_vec_1_3.webp"; // color_indexing, predictor
public const string TwoTransforms5 = "Webp/lossless_vec_1_6.webp"; // substract_green, predictor
public const string TwoTransforms6 = "Webp/lossless_vec_1_7.webp"; // color_indexing, predictor
public const string TwoTransforms7 = "Webp/lossless_vec_1_9.webp"; // color_indexing, cross_color
public const string TwoTransforms8 = "Webp/lossless_vec_2_10.webp"; // predictor, cross_color
public const string TwoTransforms9 = "Webp/lossless_vec_2_12.webp"; // substract_green, cross_color
public const string TwoTransforms10 = "Webp/lossless_vec_2_13.webp"; // color_indexing, cross_color
public const string TwoTransforms11 = "Webp/lossless_vec_2_3.webp"; // color_indexing, predictor
public const string TwoTransforms12 = "Webp/lossless_vec_2_6.webp"; // substract_green, predictor
public const string TwoTransforms13 = "Webp/lossless_vec_2_9.webp"; // color_indexing, predictor
public const string ThreeTransforms1 = "Webp/color_cache_bits_11.webp"; // substract_green, predictor, cross_color
public const string ThreeTransforms2 = "Webp/lossless_big_random_alpha.webp"; // substract_green, predictor, cross_color
public const string ThreeTransforms3 = "Webp/lossless_vec_1_11.webp"; // color_indexing, predictor, cross_color
public const string ThreeTransforms4 = "Webp/lossless_vec_1_14.webp"; // substract_green, predictor, cross_color
public const string ThreeTransforms5 = "Webp/lossless_vec_1_15.webp"; // color_indexing, predictor, cross_color
public const string ThreeTransforms6 = "Webp/lossless_vec_2_11.webp"; // color_indexing, predictor, cross_color
public const string ThreeTransforms7 = "Webp/lossless_vec_2_14.webp"; // substract_green, predictor, cross_color
public const string ThreeTransforms8 = "Webp/lossless_vec_2_15.webp"; // color_indexing, predictor, cross_color
public const string ThreeTransforms2 = "Webp/lossless_vec_1_11.webp"; // color_indexing, predictor, cross_color
public const string ThreeTransforms3 = "Webp/lossless_vec_1_14.webp"; // substract_green, predictor, cross_color
public const string ThreeTransforms4 = "Webp/lossless_vec_1_15.webp"; // color_indexing, predictor, cross_color
public const string ThreeTransforms5 = "Webp/lossless_vec_2_11.webp"; // color_indexing, predictor, cross_color
public const string ThreeTransforms6 = "Webp/lossless_vec_2_14.webp"; // substract_green, predictor, cross_color
public const string ThreeTransforms7 = "Webp/lossless_vec_2_15.webp"; // color_indexing, predictor, cross_color
// Invalid / corrupted images
// Below images have errors according to webpinfo. The error message webpinfo gives is "Truncated data detected when parsing RIFF payload."
public const string LossLessCorruptImage1 = "Webp/lossless_big_random_alpha.webp"; // substract_green, predictor, cross_color.
public const string LossLessCorruptImage2 = "Webp/lossless_vec_2_7.webp"; // color_indexing, predictor.
public const string LossLessCorruptImage3 = "Webp/lossless_color_transform.webp"; // cross_color, predictor
public const string LossLessCorruptImage4 = "Webp/near_lossless_75.webp"; // predictor, cross_color.
}
public static class Lossy

Loading…
Cancel
Save