|
|
|
@ -1,6 +1,7 @@ |
|
|
|
// Copyright (c) Six Labors.
|
|
|
|
// Licensed under the Six Labors Split License.
|
|
|
|
|
|
|
|
using Microsoft.CodeAnalysis; |
|
|
|
using SixLabors.ImageSharp.Formats; |
|
|
|
using SixLabors.ImageSharp.Formats.Gif; |
|
|
|
using SixLabors.ImageSharp.Metadata; |
|
|
|
@ -30,7 +31,7 @@ public class GifMetadataTests |
|
|
|
[Fact] |
|
|
|
public void CloneIsDeep() |
|
|
|
{ |
|
|
|
var meta = new GifMetadata |
|
|
|
GifMetadata meta = new() |
|
|
|
{ |
|
|
|
RepeatCount = 1, |
|
|
|
ColorTableMode = GifColorTableMode.Global, |
|
|
|
@ -38,7 +39,7 @@ public class GifMetadataTests |
|
|
|
Comments = new List<string> { "Foo" } |
|
|
|
}; |
|
|
|
|
|
|
|
var clone = (GifMetadata)meta.DeepClone(); |
|
|
|
GifMetadata clone = (GifMetadata)meta.DeepClone(); |
|
|
|
|
|
|
|
clone.RepeatCount = 2; |
|
|
|
clone.ColorTableMode = GifColorTableMode.Local; |
|
|
|
@ -54,7 +55,7 @@ public class GifMetadataTests |
|
|
|
[Fact] |
|
|
|
public void Decode_IgnoreMetadataIsFalse_CommentsAreRead() |
|
|
|
{ |
|
|
|
var testFile = TestFile.Create(TestImages.Gif.Rings); |
|
|
|
TestFile testFile = TestFile.Create(TestImages.Gif.Rings); |
|
|
|
|
|
|
|
using Image<Rgba32> image = testFile.CreateRgba32Image(GifDecoder.Instance); |
|
|
|
GifMetadata metadata = image.Metadata.GetGifMetadata(); |
|
|
|
@ -70,7 +71,7 @@ public class GifMetadataTests |
|
|
|
SkipMetadata = true |
|
|
|
}; |
|
|
|
|
|
|
|
var testFile = TestFile.Create(TestImages.Gif.Rings); |
|
|
|
TestFile testFile = TestFile.Create(TestImages.Gif.Rings); |
|
|
|
|
|
|
|
using Image<Rgba32> image = testFile.CreateRgba32Image(GifDecoder.Instance, options); |
|
|
|
GifMetadata metadata = image.Metadata.GetGifMetadata(); |
|
|
|
@ -80,7 +81,7 @@ public class GifMetadataTests |
|
|
|
[Fact] |
|
|
|
public void Decode_CanDecodeLargeTextComment() |
|
|
|
{ |
|
|
|
var testFile = TestFile.Create(TestImages.Gif.LargeComment); |
|
|
|
TestFile testFile = TestFile.Create(TestImages.Gif.LargeComment); |
|
|
|
|
|
|
|
using Image<Rgba32> image = testFile.CreateRgba32Image(GifDecoder.Instance); |
|
|
|
GifMetadata metadata = image.Metadata.GetGifMetadata(); |
|
|
|
@ -92,11 +93,11 @@ public class GifMetadataTests |
|
|
|
[Fact] |
|
|
|
public void Encode_PreservesTextData() |
|
|
|
{ |
|
|
|
var decoder = GifDecoder.Instance; |
|
|
|
var testFile = TestFile.Create(TestImages.Gif.LargeComment); |
|
|
|
GifDecoder decoder = GifDecoder.Instance; |
|
|
|
TestFile testFile = TestFile.Create(TestImages.Gif.LargeComment); |
|
|
|
|
|
|
|
using Image<Rgba32> input = testFile.CreateRgba32Image(decoder); |
|
|
|
using var memoryStream = new MemoryStream(); |
|
|
|
using MemoryStream memoryStream = new(); |
|
|
|
input.Save(memoryStream, new GifEncoder()); |
|
|
|
memoryStream.Position = 0; |
|
|
|
|
|
|
|
@ -111,8 +112,8 @@ public class GifMetadataTests |
|
|
|
[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); |
|
|
|
TestFile testFile = TestFile.Create(imagePath); |
|
|
|
using MemoryStream stream = new(testFile.Bytes, false); |
|
|
|
ImageInfo image = GifDecoder.Instance.Identify(DecoderOptions.Default, stream); |
|
|
|
ImageMetadata meta = image.Metadata; |
|
|
|
Assert.Equal(xResolution, meta.HorizontalResolution); |
|
|
|
@ -124,8 +125,8 @@ public class GifMetadataTests |
|
|
|
[MemberData(nameof(RatioFiles))] |
|
|
|
public async Task Identify_VerifyRatioAsync(string imagePath, int xResolution, int yResolution, PixelResolutionUnit resolutionUnit) |
|
|
|
{ |
|
|
|
var testFile = TestFile.Create(imagePath); |
|
|
|
using var stream = new MemoryStream(testFile.Bytes, false); |
|
|
|
TestFile testFile = TestFile.Create(imagePath); |
|
|
|
using MemoryStream stream = new(testFile.Bytes, false); |
|
|
|
ImageInfo image = await GifDecoder.Instance.IdentifyAsync(DecoderOptions.Default, stream); |
|
|
|
ImageMetadata meta = image.Metadata; |
|
|
|
Assert.Equal(xResolution, meta.HorizontalResolution); |
|
|
|
@ -137,8 +138,8 @@ public class GifMetadataTests |
|
|
|
[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); |
|
|
|
TestFile testFile = TestFile.Create(imagePath); |
|
|
|
using MemoryStream stream = new(testFile.Bytes, false); |
|
|
|
using Image<Rgba32> image = GifDecoder.Instance.Decode<Rgba32>(DecoderOptions.Default, stream); |
|
|
|
ImageMetadata meta = image.Metadata; |
|
|
|
Assert.Equal(xResolution, meta.HorizontalResolution); |
|
|
|
@ -150,8 +151,8 @@ public class GifMetadataTests |
|
|
|
[MemberData(nameof(RatioFiles))] |
|
|
|
public async Task Decode_VerifyRatioAsync(string imagePath, int xResolution, int yResolution, PixelResolutionUnit resolutionUnit) |
|
|
|
{ |
|
|
|
var testFile = TestFile.Create(imagePath); |
|
|
|
using var stream = new MemoryStream(testFile.Bytes, false); |
|
|
|
TestFile testFile = TestFile.Create(imagePath); |
|
|
|
using MemoryStream stream = new(testFile.Bytes, false); |
|
|
|
using Image<Rgba32> image = await GifDecoder.Instance.DecodeAsync<Rgba32>(DecoderOptions.Default, stream); |
|
|
|
ImageMetadata meta = image.Metadata; |
|
|
|
Assert.Equal(xResolution, meta.HorizontalResolution); |
|
|
|
@ -163,8 +164,8 @@ public class GifMetadataTests |
|
|
|
[MemberData(nameof(RepeatFiles))] |
|
|
|
public void Identify_VerifyRepeatCount(string imagePath, uint repeatCount) |
|
|
|
{ |
|
|
|
var testFile = TestFile.Create(imagePath); |
|
|
|
using var stream = new MemoryStream(testFile.Bytes, false); |
|
|
|
TestFile testFile = TestFile.Create(imagePath); |
|
|
|
using MemoryStream stream = new(testFile.Bytes, false); |
|
|
|
ImageInfo image = GifDecoder.Instance.Identify(DecoderOptions.Default, stream); |
|
|
|
GifMetadata meta = image.Metadata.GetGifMetadata(); |
|
|
|
Assert.Equal(repeatCount, meta.RepeatCount); |
|
|
|
@ -174,10 +175,38 @@ public class GifMetadataTests |
|
|
|
[MemberData(nameof(RepeatFiles))] |
|
|
|
public void Decode_VerifyRepeatCount(string imagePath, uint repeatCount) |
|
|
|
{ |
|
|
|
var testFile = TestFile.Create(imagePath); |
|
|
|
using var stream = new MemoryStream(testFile.Bytes, false); |
|
|
|
TestFile testFile = TestFile.Create(imagePath); |
|
|
|
using MemoryStream stream = new(testFile.Bytes, false); |
|
|
|
using Image<Rgba32> image = GifDecoder.Instance.Decode<Rgba32>(DecoderOptions.Default, stream); |
|
|
|
GifMetadata meta = image.Metadata.GetGifMetadata(); |
|
|
|
Assert.Equal(repeatCount, meta.RepeatCount); |
|
|
|
} |
|
|
|
|
|
|
|
[Theory] |
|
|
|
[InlineData(TestImages.Gif.Cheers, 93, GifColorTableMode.Global, 256, 4, GifDisposalMethod.NotDispose)] |
|
|
|
public void Identify_Frames( |
|
|
|
string imagePath, |
|
|
|
int framesCount, |
|
|
|
GifColorTableMode colorTableMode, |
|
|
|
int globalColorTableLength, |
|
|
|
int frameDelay, |
|
|
|
GifDisposalMethod disposalMethod) |
|
|
|
{ |
|
|
|
TestFile testFile = TestFile.Create(imagePath); |
|
|
|
using MemoryStream stream = new(testFile.Bytes, false); |
|
|
|
|
|
|
|
ImageInfo imageInfo = Image.Identify(stream); |
|
|
|
|
|
|
|
Assert.NotNull(imageInfo); |
|
|
|
GifMetadata gifMetadata = imageInfo.Metadata.GetGifMetadata(); |
|
|
|
Assert.NotNull(gifMetadata); |
|
|
|
|
|
|
|
Assert.Equal(framesCount, imageInfo.FrameMetadataCollection.Count); |
|
|
|
GifFrameMetadata gifFrameMetadata = imageInfo.FrameMetadataCollection[imageInfo.FrameMetadataCollection.Count - 1].GetGifMetadata(); |
|
|
|
|
|
|
|
Assert.Equal(colorTableMode, gifFrameMetadata.ColorTableMode); |
|
|
|
Assert.Equal(globalColorTableLength, gifFrameMetadata.ColorTableLength); |
|
|
|
Assert.Equal(frameDelay, gifFrameMetadata.FrameDelay); |
|
|
|
Assert.Equal(disposalMethod, gifFrameMetadata.DisposalMethod); |
|
|
|
} |
|
|
|
} |
|
|
|
|