diff --git a/src/ImageProcessor/Formats/Bmp/BmpEncoder.cs b/src/ImageProcessor/Formats/Bmp/BmpEncoder.cs index b563e81830..c94037feeb 100644 --- a/src/ImageProcessor/Formats/Bmp/BmpEncoder.cs +++ b/src/ImageProcessor/Formats/Bmp/BmpEncoder.cs @@ -108,6 +108,7 @@ namespace ImageProcessor.Formats /// private static void WriteImage(BinaryWriter writer, ImageBase image) { + // TODO: Check this as Bitmaps can have an alpha channel. int amount = (image.Width * 3) % 4; if (amount != 0) { diff --git a/src/ImageProcessor/Formats/Gif/Quantizer/OctreeQuantizer.cs b/src/ImageProcessor/Formats/Gif/Quantizer/OctreeQuantizer.cs index 368e5ace9d..5844e3d878 100644 --- a/src/ImageProcessor/Formats/Gif/Quantizer/OctreeQuantizer.cs +++ b/src/ImageProcessor/Formats/Gif/Quantizer/OctreeQuantizer.cs @@ -114,7 +114,7 @@ namespace ImageProcessor.Formats protected override List GetPalette() { // First off convert the Octree to maxColors colors - List palette = this.octree.Palletize(this.maxColors - 1); + List palette = this.octree.Palletize(Math.Max(this.maxColors - 1, 1)); // Add empty color for transparency palette.Add(Bgra.Empty); diff --git a/src/ImageProcessor/Formats/Gif/Quantizer/QuantizedImage.cs b/src/ImageProcessor/Formats/Gif/Quantizer/QuantizedImage.cs index a463057a08..e29a310e54 100644 --- a/src/ImageProcessor/Formats/Gif/Quantizer/QuantizedImage.cs +++ b/src/ImageProcessor/Formats/Gif/Quantizer/QuantizedImage.cs @@ -60,11 +60,12 @@ namespace ImageProcessor.Formats /// public Image ToImage() { + // TODO: Something is going wrong here. We have a palette. Image image = new Image(); int pixelCount = Pixels.Length; byte[] bgraPixels = new byte[pixelCount * 4]; - for (int i = 0; i < pixelCount; i++) + for (int i = 0; i < pixelCount; i += 4) { Bgra color = Palette[Pixels[i]]; bgraPixels[i + 0] = color.B; diff --git a/src/ImageProcessor/Formats/Gif/Quantizer/Quantizer.cs b/src/ImageProcessor/Formats/Gif/Quantizer/Quantizer.cs index 7970687903..ec00bf5081 100644 --- a/src/ImageProcessor/Formats/Gif/Quantizer/Quantizer.cs +++ b/src/ImageProcessor/Formats/Gif/Quantizer/Quantizer.cs @@ -11,7 +11,6 @@ namespace ImageProcessor.Formats { using System.Collections.Generic; - using System.Linq; /// /// Encapsulates methods to calculate the color palette of an image. @@ -55,16 +54,16 @@ namespace ImageProcessor.Formats // Call the FirstPass function if not a single pass algorithm. // For something like an Octree quantizer, this will run through // all image pixels, build a data structure, and create a palette. - if (!singlePass) + if (!this.singlePass) { - FirstPass(imageBase, width, height); + this.FirstPass(imageBase, width, height); } byte[] quantizedPixels = new byte[width * height]; - SecondPass(imageBase, quantizedPixels, width, height); + this.SecondPass(imageBase, quantizedPixels, width, height); - return new QuantizedImage(width, height, GetPalette().ToArray(), quantizedPixels); + return new QuantizedImage(width, height, this.GetPalette().ToArray(), quantizedPixels); } /// @@ -100,7 +99,7 @@ namespace ImageProcessor.Formats // Convert the first pixel, so that I have values going into the loop Bgra previousPixel = source[0, 0]; - byte pixelValue = QuantizePixel(previousPixel); + byte pixelValue = this.QuantizePixel(previousPixel); output[0] = pixelValue; @@ -115,7 +114,7 @@ namespace ImageProcessor.Formats if (sourcePixel != previousPixel) { // Quantize the pixel - pixelValue = QuantizePixel(sourcePixel); + pixelValue = this.QuantizePixel(sourcePixel); // And setup the previous pointer previousPixel = sourcePixel; diff --git a/tests/ImageProcessor.Tests/Formats/EncoderDecoderTests.cs b/tests/ImageProcessor.Tests/Formats/EncoderDecoderTests.cs index fe9133b0f7..5c0c5bf0c5 100644 --- a/tests/ImageProcessor.Tests/Formats/EncoderDecoderTests.cs +++ b/tests/ImageProcessor.Tests/Formats/EncoderDecoderTests.cs @@ -59,7 +59,9 @@ } [Theory] + [InlineData("../../TestImages/Formats/Jpg/Backdrop.jpg")] [InlineData("../../TestImages/Formats/Bmp/Car.bmp")] + [InlineData("../../TestImages/Formats/Png/cmyk.png")] public void QuantizedImageShouldPreserveMaximumColorPrecision(string filename) { if (!Directory.Exists("Quantized"))