diff --git a/src/ImageSharp/Image/PixelArea{TPixel}.cs b/src/ImageSharp/Image/PixelArea{TPixel}.cs index e9924f8235..1c7256455e 100644 --- a/src/ImageSharp/Image/PixelArea{TPixel}.cs +++ b/src/ImageSharp/Image/PixelArea{TPixel}.cs @@ -30,7 +30,7 @@ namespace SixLabors.ImageSharp /// /// The underlying buffer containing the raw pixel data. /// - private Buffer byteBuffer; + private readonly Buffer byteBuffer; /// /// Initializes a new instance of the class. @@ -116,7 +116,7 @@ namespace SixLabors.ImageSharp this.RowStride = (width * GetComponentCount(componentOrder)) + padding; this.Length = this.RowStride * height; - this.byteBuffer = new Buffer(this.Length); + this.byteBuffer = Buffer.CreateClean(this.Length); } /// diff --git a/tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs index cd78add758..a4a27bd839 100644 --- a/tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs @@ -10,12 +10,15 @@ using Xunit; // ReSharper disable InconsistentNaming namespace SixLabors.ImageSharp.Tests { + using SixLabors.ImageSharp.Advanced; + public class GifDecoderTests { private const PixelTypes PixelTypes = Tests.PixelTypes.Rgba32 | Tests.PixelTypes.RgbaVector | Tests.PixelTypes.Argb32; public static readonly string[] TestFiles = { TestImages.Gif.Giphy, TestImages.Gif.Rings, TestImages.Gif.Trans }; + [Theory] [WithFileCollection(nameof(TestFiles), PixelTypes)] public void DecodeAndReSave(TestImageProvider imageProvider) @@ -113,5 +116,21 @@ namespace SixLabors.ImageSharp.Tests Assert.True(image.Frames.Count > 1); } } + + [Fact] + public void CanDecodeIntermingledImages() + { + using (var kumin1 = Image.Load(TestFile.Create(TestImages.Gif.Kumin).Bytes)) + using (var icon = Image.Load(TestFile.Create(TestImages.Png.Icon).Bytes)) + using (var kumin2 = Image.Load(TestFile.Create(TestImages.Gif.Kumin).Bytes)) + { + for (int i = 0; i < kumin1.Frames.Count; i++) + { + ImageFrame first = kumin1.Frames[i]; + ImageFrame second = kumin2.Frames[i]; + first.ComparePixelBufferTo(second.GetPixelSpan()); + } + } + } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs index f342542395..ac4fe09e68 100644 --- a/tests/ImageSharp.Tests/TestImages.cs +++ b/tests/ImageSharp.Tests/TestImages.cs @@ -31,6 +31,7 @@ namespace SixLabors.ImageSharp.Tests public const string BikeGrayscale = "Png/BikeGrayscale.png"; public const string Rgb48BppInterlaced = "Png/rgb-48bpp-interlaced.png"; public const string SnakeGame = "Png/SnakeGame.png"; + public const string Icon = "Png/icon.png"; // Filtered test images from http://www.schaik.com/pngsuite/pngsuite_fil_png.html public const string Filter0 = "Png/filter0.png"; @@ -153,8 +154,9 @@ namespace SixLabors.ImageSharp.Tests public const string Giphy = "Gif/giphy.gif"; public const string Cheers = "Gif/cheers.gif"; public const string Trans = "Gif/trans.gif"; + public const string Kumin = "Gif/kumin.gif"; - public static readonly string[] All = { Rings, Giphy, Cheers, Trans }; + public static readonly string[] All = { Rings, Giphy, Cheers, Trans, Kumin }; } } } diff --git a/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs b/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs index 505cdc1729..2b3cb1bcc3 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs @@ -29,7 +29,6 @@ namespace SixLabors.ImageSharp.Tests /// The image provider /// Details to be concatenated to the test output file, describing the parameters of the test. /// The extension - /// A boolean indicating whether we should save a smaller in size. /// A boolean indicating whether to append the pixel type to the output file name. public static Image DebugSave( this Image image, diff --git a/tests/Images/Input/Gif/kumin.gif b/tests/Images/Input/Gif/kumin.gif new file mode 100644 index 0000000000..31efda7d8c --- /dev/null +++ b/tests/Images/Input/Gif/kumin.gif @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:345556b9a0e064412acc3b2ee87a9226113eb65c0a1791c2f855ac3fa1e6b7ad +size 868269 diff --git a/tests/Images/Input/Png/icon.png b/tests/Images/Input/Png/icon.png new file mode 100644 index 0000000000..bc355712b5 --- /dev/null +++ b/tests/Images/Input/Png/icon.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:18f1eb7c5019153f4a0b2de90e7e0f0521193f003fabd6ac31c2f58c2562ae42 +size 4040