Browse Source

Add test

pull/1686/head
Ildar Khayrutdinov 5 years ago
parent
commit
c661fd4bd8
  1. 2
      src/ImageSharp/Formats/Tiff/TiffEncoderCore.cs
  2. 2
      tests/ImageSharp.Tests/Formats/Tiff/TiffEncoderBaseTester.cs
  3. 37
      tests/ImageSharp.Tests/Formats/Tiff/TiffEncoderMultiframeTests.cs

2
src/ImageSharp/Formats/Tiff/TiffEncoderCore.cs

@ -155,7 +155,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff
Image<TPixel> metadataImage = image;
foreach (ImageFrame<TPixel> frame in image.Frames)
{
var subfileType = (TiffNewSubfileType)(frame.Metadata.ExifProfile.GetValue(ExifTag.SubfileType)?.Value ?? 0);
var subfileType = (TiffNewSubfileType)(frame.Metadata.ExifProfile?.GetValue(ExifTag.SubfileType)?.Value ?? (int)TiffNewSubfileType.FullImage);
if (subfileType != TiffNewSubfileType.FullImage)
{

2
tests/ImageSharp.Tests/Formats/Tiff/TiffEncoderBaseTester.cs

@ -18,7 +18,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff
[Trait("Format", "Tiff")]
public abstract class TiffEncoderBaseTester
{
private static readonly IImageDecoder ReferenceDecoder = new MagickReferenceDecoder();
protected static readonly IImageDecoder ReferenceDecoder = new MagickReferenceDecoder();
protected static void TestStripLength<TPixel>(
TestImageProvider<TPixel> provider,

37
tests/ImageSharp.Tests/Formats/Tiff/TiffEncoderMultiframeTests.cs

@ -2,10 +2,12 @@
// Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Formats.Tiff;
using SixLabors.ImageSharp.Formats.Tiff.Constants;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
using Xunit;
using static SixLabors.ImageSharp.Tests.TestImages.Tiff;
@ -13,6 +15,7 @@ using static SixLabors.ImageSharp.Tests.TestImages.Tiff;
namespace SixLabors.ImageSharp.Tests.Formats.Tiff
{
[Trait("Format", "Tiff")]
[Trait("Format", "Tiff.m")]
public class TiffEncoderMultiframeTests : TiffEncoderBaseTester
{
[Theory]
@ -21,10 +24,40 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff
where TPixel : unmanaged, IPixel<TPixel> => TestTiffEncoderCore(provider, TiffBitsPerPixel.Bit24, TiffPhotometricInterpretation.Rgb);
[Theory]
[WithFile(MultiframeDeflateWithPreview, PixelTypes.Rgba32)]
[WithFile(MultiframeDifferentSize, PixelTypes.Rgba32)]
[WithFile(MultiframeDifferentVariants, PixelTypes.Rgba32)]
public void TiffEncoder_EncodeMultiframe_NotSupport<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel> => Assert.Throws<NotSupportedException>(() => TestTiffEncoderCore(provider, TiffBitsPerPixel.Bit24, TiffPhotometricInterpretation.Rgb));
[Theory]
[WithFile(MultiframeDeflateWithPreview, PixelTypes.Rgba32)]
public void TiffEncoder_EncodeMultiframe_WithoutPreview_ProblemTest<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel> => Assert.Throws<ImagesSimilarityException>(() => TestTiffEncoderCore(provider, TiffBitsPerPixel.Bit24, TiffPhotometricInterpretation.Rgb));
[Theory]
[WithFile(RgbLzwNoPredictor, PixelTypes.Rgba32)]
public void TiffEncoder_EncodeMultiframe_Create<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using var image = provider.GetImage();
using var image2 = new Image<Rgba32>(image.Width, image.Height, Color.Green.ToRgba32());
image.Frames.AddFrame(image2.Frames.RootFrame);
TiffBitsPerPixel bitsPerPixel = TiffBitsPerPixel.Bit24;
var encoder = new TiffEncoder
{
PhotometricInterpretation = TiffPhotometricInterpretation.Rgb,
BitsPerPixel = bitsPerPixel,
Compression = TiffCompression.Deflate
};
image.VerifyEncoder(
provider,
"tiff",
bitsPerPixel,
encoder,
ImageComparer.Exact);
}
}
}

Loading…
Cancel
Save