From 9a12d09d7aaa1a0d4b2e528b27b2ea2ea58c387d Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Wed, 27 Jun 2018 18:06:51 +1000 Subject: [PATCH] Update tests --- src/ImageSharp/Formats/Gif/GifEncoderCore.cs | 2 +- .../Formats/Gif/GifEncoderTests.cs | 26 +++++++++++++++++++ tests/Images/External | 2 +- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs index baed04260..8a6415c3b 100644 --- a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs +++ b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs @@ -350,7 +350,7 @@ namespace SixLabors.ImageSharp.Formats.Gif localColorTableFlag: hasColorTable, interfaceFlag: false, sortFlag: false, - localColorTableSize: (byte)(this.bitDepth - 1)); // Note: we subtract 1 from the colorTableSize writing + localColorTableSize: (byte)this.bitDepth); var descriptor = new GifImageDescriptor( left: 0, diff --git a/tests/ImageSharp.Tests/Formats/Gif/GifEncoderTests.cs b/tests/ImageSharp.Tests/Formats/Gif/GifEncoderTests.cs index 918d39021..93cfaff7f 100644 --- a/tests/ImageSharp.Tests/Formats/Gif/GifEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Gif/GifEncoderTests.cs @@ -117,5 +117,31 @@ namespace SixLabors.ImageSharp.Tests.Formats.Gif } } } + + [Theory] + [WithFile(TestImages.Gif.Cheers, PixelTypes.Rgba32)] + public void EncodeGlobalPaletteReturnsSmallerFile(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + var encoder = new GifEncoder + { + ColorTableMode = GifColorTableMode.Global, + Quantizer = new OctreeQuantizer(false) + }; + + // Always save as we need to compare the encoded output. + provider.Utility.SaveTestOutputFile(image, "gif", encoder, "global"); + + encoder.ColorTableMode = GifColorTableMode.Local; + provider.Utility.SaveTestOutputFile(image, "gif", encoder, "local"); + + var fileInfoGlobal = new FileInfo(provider.Utility.GetTestOutputFileName("gif", "global")); + var fileInfoLocal = new FileInfo(provider.Utility.GetTestOutputFileName("gif", "local")); + + Assert.True(fileInfoGlobal.Length < fileInfoLocal.Length); + } + } } } diff --git a/tests/Images/External b/tests/Images/External index 6fcee2ccd..fa43e075a 160000 --- a/tests/Images/External +++ b/tests/Images/External @@ -1 +1 @@ -Subproject commit 6fcee2ccd5e8bac98a0290b467ad86bb02d00b6c +Subproject commit fa43e075a78d041c6fc7a52da96b23adf0e8775a