|
|
@ -13,7 +13,7 @@ using SixLabors.ImageSharp.Advanced; |
|
|
namespace SixLabors.ImageSharp.Tests.Formats.Gif |
|
|
namespace SixLabors.ImageSharp.Tests.Formats.Gif |
|
|
{ |
|
|
{ |
|
|
using System.Collections.Generic; |
|
|
using System.Collections.Generic; |
|
|
|
|
|
using SixLabors.ImageSharp.MetaData; |
|
|
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; |
|
|
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; |
|
|
|
|
|
|
|
|
public class GifDecoderTests |
|
|
public class GifDecoderTests |
|
|
@ -21,31 +21,43 @@ namespace SixLabors.ImageSharp.Tests.Formats.Gif |
|
|
private const PixelTypes TestPixelTypes = PixelTypes.Rgba32 | PixelTypes.RgbaVector | PixelTypes.Argb32; |
|
|
private const PixelTypes TestPixelTypes = PixelTypes.Rgba32 | PixelTypes.RgbaVector | PixelTypes.Argb32; |
|
|
|
|
|
|
|
|
public static readonly string[] MultiFrameTestFiles = |
|
|
public static readonly string[] MultiFrameTestFiles = |
|
|
{ |
|
|
{ |
|
|
TestImages.Gif.Giphy, TestImages.Gif.Kumin |
|
|
TestImages.Gif.Giphy, TestImages.Gif.Kumin |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
public static readonly string[] BasicVerificationFiles = |
|
|
public static readonly string[] BasicVerificationFiles = |
|
|
{ |
|
|
{ |
|
|
TestImages.Gif.Cheers, |
|
|
TestImages.Gif.Cheers, |
|
|
TestImages.Gif.Rings, |
|
|
TestImages.Gif.Rings, |
|
|
|
|
|
|
|
|
// previously DecodeBadApplicationExtensionLength:
|
|
|
// previously DecodeBadApplicationExtensionLength:
|
|
|
TestImages.Gif.Issues.BadAppExtLength, |
|
|
TestImages.Gif.Issues.BadAppExtLength, |
|
|
TestImages.Gif.Issues.BadAppExtLength_2, |
|
|
TestImages.Gif.Issues.BadAppExtLength_2, |
|
|
|
|
|
|
|
|
// previously DecodeBadDescriptorDimensionsLength:
|
|
|
// previously DecodeBadDescriptorDimensionsLength:
|
|
|
TestImages.Gif.Issues.BadDescriptorWidth |
|
|
TestImages.Gif.Issues.BadDescriptorWidth |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
public static readonly TheoryData<string, int, int, PixelResolutionUnit> RatioFiles = |
|
|
|
|
|
new TheoryData<string, int, int, PixelResolutionUnit> |
|
|
|
|
|
{ |
|
|
|
|
|
{ TestImages.Gif.Rings, (int)ImageMetaData.DefaultHorizontalResolution, (int)ImageMetaData.DefaultVerticalResolution , PixelResolutionUnit.PixelsPerInch}, |
|
|
|
|
|
{ TestImages.Gif.Ratio1x4, 1, 4 , PixelResolutionUnit.AspectRatio}, |
|
|
|
|
|
{ TestImages.Gif.Ratio4x1, 4, 1, PixelResolutionUnit.AspectRatio } |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
private static readonly Dictionary<string, int> BasicVerificationFrameCount = |
|
|
private static readonly Dictionary<string, int> BasicVerificationFrameCount = |
|
|
new Dictionary<string, int> |
|
|
new Dictionary<string, int> |
|
|
{ |
|
|
{ |
|
|
[TestImages.Gif.Cheers] = 93, |
|
|
[TestImages.Gif.Cheers] = 93, |
|
|
[TestImages.Gif.Issues.BadDescriptorWidth] = 36, |
|
|
[TestImages.Gif.Issues.BadDescriptorWidth] = 36, |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
public static readonly string[] BadAppExtFiles = { TestImages.Gif.Issues.BadAppExtLength, TestImages.Gif.Issues.BadAppExtLength_2 }; |
|
|
public static readonly string[] BadAppExtFiles = |
|
|
|
|
|
{ |
|
|
|
|
|
TestImages.Gif.Issues.BadAppExtLength, |
|
|
|
|
|
TestImages.Gif.Issues.BadAppExtLength_2 |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
[Theory] |
|
|
[Theory] |
|
|
[WithFileCollection(nameof(MultiFrameTestFiles), PixelTypes.Rgba32)] |
|
|
[WithFileCollection(nameof(MultiFrameTestFiles), PixelTypes.Rgba32)] |
|
|
@ -59,6 +71,40 @@ namespace SixLabors.ImageSharp.Tests.Formats.Gif |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[Theory] |
|
|
|
|
|
[MemberData(nameof(RatioFiles))] |
|
|
|
|
|
public void Decode_VerifyRatio(string imagePath, int xResolution, int yResolution, PixelResolutionUnit resolutionUnit) |
|
|
|
|
|
{ |
|
|
|
|
|
var testFile = TestFile.Create(imagePath); |
|
|
|
|
|
using (var stream = new MemoryStream(testFile.Bytes, false)) |
|
|
|
|
|
{ |
|
|
|
|
|
var decoder = new GifDecoder(); |
|
|
|
|
|
using (Image<Rgba32> image = decoder.Decode<Rgba32>(Configuration.Default, stream)) |
|
|
|
|
|
{ |
|
|
|
|
|
ImageMetaData meta = image.MetaData; |
|
|
|
|
|
Assert.Equal(xResolution, meta.HorizontalResolution); |
|
|
|
|
|
Assert.Equal(yResolution, meta.VerticalResolution); |
|
|
|
|
|
Assert.Equal(resolutionUnit, meta.ResolutionUnits); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[Theory] |
|
|
|
|
|
[MemberData(nameof(RatioFiles))] |
|
|
|
|
|
public void Identify_VerifyRatio(string imagePath, int xResolution, int yResolution, PixelResolutionUnit resolutionUnit) |
|
|
|
|
|
{ |
|
|
|
|
|
var testFile = TestFile.Create(imagePath); |
|
|
|
|
|
using (var stream = new MemoryStream(testFile.Bytes, false)) |
|
|
|
|
|
{ |
|
|
|
|
|
var decoder = new GifDecoder(); |
|
|
|
|
|
IImageInfo image = decoder.Identify(Configuration.Default, stream); |
|
|
|
|
|
ImageMetaData meta = image.MetaData; |
|
|
|
|
|
Assert.Equal(xResolution, meta.HorizontalResolution); |
|
|
|
|
|
Assert.Equal(yResolution, meta.VerticalResolution); |
|
|
|
|
|
Assert.Equal(resolutionUnit, meta.ResolutionUnits); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
[Theory] |
|
|
[Theory] |
|
|
[WithFile(TestImages.Gif.Trans, TestPixelTypes)] |
|
|
[WithFile(TestImages.Gif.Trans, TestPixelTypes)] |
|
|
public void GifDecoder_IsNotBoundToSinglePixelType<TPixel>(TestImageProvider<TPixel> provider) |
|
|
public void GifDecoder_IsNotBoundToSinglePixelType<TPixel>(TestImageProvider<TPixel> provider) |
|
|
@ -88,7 +134,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Gif |
|
|
image.CompareFirstFrameToReferenceOutput(ImageComparer.Exact, provider); |
|
|
image.CompareFirstFrameToReferenceOutput(ImageComparer.Exact, provider); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
public void Decode_IgnoreMetadataIsFalse_CommentsAreRead() |
|
|
public void Decode_IgnoreMetadataIsFalse_CommentsAreRead() |
|
|
{ |
|
|
{ |
|
|
@ -169,7 +215,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Gif |
|
|
[InlineData(TestImages.Gif.Trans, 8)] |
|
|
[InlineData(TestImages.Gif.Trans, 8)] |
|
|
public void DetectPixelSize(string imagePath, int expectedPixelSize) |
|
|
public void DetectPixelSize(string imagePath, int expectedPixelSize) |
|
|
{ |
|
|
{ |
|
|
TestFile testFile = TestFile.Create(imagePath); |
|
|
var testFile = TestFile.Create(imagePath); |
|
|
using (var stream = new MemoryStream(testFile.Bytes, false)) |
|
|
using (var stream = new MemoryStream(testFile.Bytes, false)) |
|
|
{ |
|
|
{ |
|
|
Assert.Equal(expectedPixelSize, Image.Identify(stream)?.PixelType?.BitsPerPixel); |
|
|
Assert.Equal(expectedPixelSize, Image.Identify(stream)?.PixelType?.BitsPerPixel); |
|
|
|