Browse Source

Fix issue comparing to wrong image in encode paletted color tiff tests

pull/1457/head
Brian Popow 5 years ago
parent
commit
01c7cd8194
  1. 3
      src/ImageSharp/Formats/Tiff/README.md
  2. 15
      tests/ImageSharp.Tests/Formats/Tiff/TiffEncoderTests.cs
  3. 10
      tests/ImageSharp.Tests/Formats/Tiff/TiffTestUtils.cs

3
src/ImageSharp/Formats/Tiff/README.md

@ -31,9 +31,6 @@ Decoder:
- Decoding HUffman RLE for `Calliphora_huffman_rle.tiff` has 4 pixels difference to the reference decoder. Al those are at the very edge of the image (reason unknown so far).
- Decoding compressed images with HorizontalPrediction: Works for deflate, but not for lzw.
Encoder:
- Encoding image with a palette have a difference of 0.0043% to the ReferenceDecoder (ImageMagick)
### Deviations from the TIFF spec (to be fixed)
- Decoder

15
tests/ImageSharp.Tests/Formats/Tiff/TiffEncoderTests.cs

@ -84,7 +84,6 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff
// Because a quantizer is used to create the palette (and therefore changes to the original are expected),
// we do not compare the encoded image against the original:
// Instead we load the encoded image with a reference decoder and compare against that image.
// TODO: There is a difference of 0,0043%
using Image<TPixel> image = provider.GetImage();
using var memStream = new MemoryStream();
var encoder = new TiffEncoder { Mode = TiffEncodingMode.ColorPalette, Compression = TiffEncoderCompression.None };
@ -93,8 +92,8 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff
memStream.Position = 0;
using var encodedImage = (Image<TPixel>)Image.Load(memStream);
provider.Utility.SaveTestOutputFile(encodedImage, "tiff", encoder);
TiffTestUtils.CompareWithReferenceDecoder(provider, encodedImage);
var encodedImagePath = provider.Utility.SaveTestOutputFile(encodedImage, "tiff", encoder);
TiffTestUtils.CompareWithReferenceDecoder(encodedImagePath, encodedImage);
}
[Theory]
@ -102,7 +101,6 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff
public void TiffEncoder_EncodeColorPalette_WithDeflateCompression_Works<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
// TODO: There is a difference of 0,0043%
using Image<TPixel> image = provider.GetImage();
using var memStream = new MemoryStream();
var encoder = new TiffEncoder { Mode = TiffEncodingMode.ColorPalette, Compression = TiffEncoderCompression.Deflate };
@ -111,8 +109,8 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff
memStream.Position = 0;
using var encodedImage = (Image<TPixel>)Image.Load(memStream);
provider.Utility.SaveTestOutputFile(encodedImage, "tiff", encoder);
TiffTestUtils.CompareWithReferenceDecoder(provider, encodedImage);
var encodedImagePath = provider.Utility.SaveTestOutputFile(encodedImage, "tiff", encoder);
TiffTestUtils.CompareWithReferenceDecoder(encodedImagePath, encodedImage);
}
[Theory]
@ -120,7 +118,6 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff
public void TiffEncoder_EncodeColorPalette_WithPackBitsCompression_Works<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
// TODO: There is a difference of 0,0043%
using Image<TPixel> image = provider.GetImage();
using var memStream = new MemoryStream();
var encoder = new TiffEncoder { Mode = TiffEncodingMode.ColorPalette, Compression = TiffEncoderCompression.PackBits };
@ -129,8 +126,8 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff
memStream.Position = 0;
using var encodedImage = (Image<TPixel>)Image.Load(memStream);
provider.Utility.SaveTestOutputFile(encodedImage, "tiff", encoder);
TiffTestUtils.CompareWithReferenceDecoder(provider, encodedImage);
var encodedImagePath = provider.Utility.SaveTestOutputFile(encodedImage, "tiff", encoder);
TiffTestUtils.CompareWithReferenceDecoder(encodedImagePath, encodedImage);
}
[Theory]

10
tests/ImageSharp.Tests/Formats/Tiff/TiffTestUtils.cs

@ -15,19 +15,13 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff
public static class TiffTestUtils
{
public static void CompareWithReferenceDecoder<TPixel>(
TestImageProvider<TPixel> provider,
string encodedImagePath,
Image<TPixel> image,
bool useExactComparer = true,
float compareTolerance = 0.01f)
where TPixel : unmanaged, ImageSharp.PixelFormats.IPixel<TPixel>
{
string path = TestImageProvider<TPixel>.GetFilePathOrNull(provider);
if (path == null)
{
throw new InvalidOperationException("CompareToOriginal() works only with file providers!");
}
var testFile = TestFile.Create(path);
var testFile = TestFile.Create(encodedImagePath);
Image<Rgba32> magickImage = DecodeWithMagick<Rgba32>(Configuration.Default, new FileInfo(testFile.FullPath));
if (useExactComparer)
{

Loading…
Cancel
Save