From 3a87134f3ed02f31066bbc78f1396649ea86880d Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Sat, 19 Mar 2016 16:50:49 +1100 Subject: [PATCH] Fix transparency allocation Former-commit-id: 85c4d5c0ccd92dce6265040068aeffe851604045 Former-commit-id: 5b59aa6bb210dcc113cee26d2986c172170a9d8e Former-commit-id: a048ee2bfc5bf0bdbdcbdd709c485ccb6c50d90d --- src/ImageProcessorCore/Formats/Gif/GifEncoder.cs | 5 +++-- src/ImageProcessorCore/Quantizers/Octree/Quantizer.cs | 2 +- src/ImageProcessorCore/Quantizers/Wu/WuQuantizer.cs | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ImageProcessorCore/Formats/Gif/GifEncoder.cs b/src/ImageProcessorCore/Formats/Gif/GifEncoder.cs index 877931772..5fb3e4b8e 100644 --- a/src/ImageProcessorCore/Formats/Gif/GifEncoder.cs +++ b/src/ImageProcessorCore/Formats/Gif/GifEncoder.cs @@ -131,7 +131,7 @@ namespace ImageProcessorCore.Formats private QuantizedImage WriteColorTable(ImageBase image, Stream stream, int quality, int bitDepth) { // Quantize the image returning a palette. - QuantizedImage quantizedImage = this.Quantizer.Quantize(image, quality.Clamp(1, 255)); + QuantizedImage quantizedImage = this.Quantizer.Quantize(image, quality); // Grab the palette and write it to the stream. Bgra32[] palette = quantizedImage.Palette; @@ -162,6 +162,7 @@ namespace ImageProcessorCore.Formats /// /// The to encode. /// The stream to write to. + /// The index of the color in the color palette to make transparent. private void WriteGraphicalControlExtension(ImageBase image, Stream stream, int transparencyIndex) { // TODO: Check transparency logic. @@ -189,7 +190,7 @@ namespace ImageProcessorCore.Formats this.WriteByte(stream, packed); this.WriteShort(stream, extension.DelayTime); - this.WriteByte(stream, extension.TransparencyIndex); + this.WriteByte(stream, extension.TransparencyIndex == -1 ? 255 : extension.TransparencyIndex); this.WriteByte(stream, GifConstants.Terminator); } diff --git a/src/ImageProcessorCore/Quantizers/Octree/Quantizer.cs b/src/ImageProcessorCore/Quantizers/Octree/Quantizer.cs index 5ee54d762..3c66cc944 100644 --- a/src/ImageProcessorCore/Quantizers/Octree/Quantizer.cs +++ b/src/ImageProcessorCore/Quantizers/Octree/Quantizer.cs @@ -37,7 +37,7 @@ namespace ImageProcessorCore.Quantizers /// /// Gets or sets the transparency index. /// - public int TransparentIndex { get; protected set; } + public int TransparentIndex { get; protected set; } = -1; /// public virtual QuantizedImage Quantize(ImageBase image, int maxColors) diff --git a/src/ImageProcessorCore/Quantizers/Wu/WuQuantizer.cs b/src/ImageProcessorCore/Quantizers/Wu/WuQuantizer.cs index 660e5e5af..9bb4e5f84 100644 --- a/src/ImageProcessorCore/Quantizers/Wu/WuQuantizer.cs +++ b/src/ImageProcessorCore/Quantizers/Wu/WuQuantizer.cs @@ -715,7 +715,7 @@ namespace ImageProcessorCore.Quantizers { List pallette = new List(); byte[] pixels = new byte[image.Width * image.Height]; - int transparentIndex = 0; + int transparentIndex = -1; for (int k = 0; k < colorCount; k++) {