Browse Source

Fix local color table encoding.

pull/693/head
James Jackson-South 8 years ago
parent
commit
6bc07e6a6d
  1. 3
      src/ImageSharp/Formats/Gif/GifEncoderCore.cs
  2. 2
      src/ImageSharp/Formats/Gif/Sections/GifImageDescriptor.cs
  3. 14
      tests/ImageSharp.Tests/Formats/Gif/Sections/GifImageDescriptorTests.cs

3
src/ImageSharp/Formats/Gif/GifEncoderCore.cs

@ -71,6 +71,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
this.textEncoding = options.TextEncoding ?? GifConstants.DefaultEncoding;
this.quantizer = options.Quantizer;
this.ignoreMetadata = options.IgnoreMetadata;
this.colorTableMode = options.ColorTableMode;
}
/// <summary>
@ -246,7 +247,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
private void WriteLogicalScreenDescriptor<TPixel>(Image<TPixel> image, int transparencyIndex, bool useGlobalTable, Stream stream)
where TPixel : struct, IPixel<TPixel>
{
byte packedValue = GifLogicalScreenDescriptor.GetPackedValue(useGlobalTable, this.bitDepth, false, this.bitDepth - 1);
byte packedValue = GifLogicalScreenDescriptor.GetPackedValue(useGlobalTable, this.bitDepth - 1, false, this.bitDepth - 1);
// The Pixel Aspect Ratio is defined to be the quotient of the pixel's
// width over its height. The value range in this field allows

2
src/ImageSharp/Formats/Gif/Sections/GifImageDescriptor.cs

@ -108,7 +108,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
value |= 1 << 5;
}
value |= (byte)(localColorTableSize - 1);
value |= (byte)localColorTableSize;
return value;
}

14
tests/ImageSharp.Tests/Formats/Gif/Sections/GifImageDescriptorTests.cs

@ -12,13 +12,13 @@ namespace SixLabors.ImageSharp.Tests.Formats.Gif
[Fact]
public void TestPackedValue()
{
Assert.Equal(128, GifImageDescriptor.GetPackedValue(true, false, false, 1)); // localColorTable
Assert.Equal(64, GifImageDescriptor.GetPackedValue(false, true, false, 1)); // interfaceFlag
Assert.Equal(32, GifImageDescriptor.GetPackedValue(false, false, true, 1)); // sortFlag
Assert.Equal(224, GifImageDescriptor.GetPackedValue(true, true, true, 1)); // all
Assert.Equal(7, GifImageDescriptor.GetPackedValue(false, false, false, 8));
Assert.Equal(227, GifImageDescriptor.GetPackedValue(true, true, true, 4));
Assert.Equal(231, GifImageDescriptor.GetPackedValue(true, true, true, 8));
Assert.Equal(129, GifImageDescriptor.GetPackedValue(true, false, false, 1)); // localColorTable
Assert.Equal(65, GifImageDescriptor.GetPackedValue(false, true, false, 1)); // interfaceFlag
Assert.Equal(33, GifImageDescriptor.GetPackedValue(false, false, true, 1)); // sortFlag
Assert.Equal(225, GifImageDescriptor.GetPackedValue(true, true, true, 1)); // all
Assert.Equal(8, GifImageDescriptor.GetPackedValue(false, false, false, 8));
Assert.Equal(228, GifImageDescriptor.GetPackedValue(true, true, true, 4));
Assert.Equal(232, GifImageDescriptor.GetPackedValue(true, true, true, 8));
}
}
}
Loading…
Cancel
Save