From 519e5b8ab2d5ce5f7ed11299bffe07fdeefadfc9 Mon Sep 17 00:00:00 2001 From: RKrom Date: Tue, 20 Mar 2012 16:55:12 +0000 Subject: [PATCH] Fixed color count, the initially supplied code was only returning the amount of colors that was inputted which == width*height git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1713 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4 --- Greenshot/Helpers/ImageOutput.cs | 4 ++-- GreenshotPlugin/Core/ImageHelper.cs | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Greenshot/Helpers/ImageOutput.cs b/Greenshot/Helpers/ImageOutput.cs index 09405265d..a153ea201 100644 --- a/Greenshot/Helpers/ImageOutput.cs +++ b/Greenshot/Helpers/ImageOutput.cs @@ -106,8 +106,8 @@ namespace Greenshot.Helpers { LOG.InfoFormat("Image with format {0} has {1} colors", imageToSave.PixelFormat, colorCount); if (reduceColors || colorCount < 256) { try { - LOG.Debug("Reducing colors on bitmap."); - imageToSave = ImageHelper.Quantize((Bitmap)imageToSave, quantizer); + LOG.Info("Reducing colors on bitmap to 255."); + imageToSave = ImageHelper.Quantize((Bitmap)imageToSave, quantizer, 255); // Make sure the "new" image is disposed disposeImage = true; } catch(Exception e) { diff --git a/GreenshotPlugin/Core/ImageHelper.cs b/GreenshotPlugin/Core/ImageHelper.cs index 8946b1052..3e3f11a8a 100644 --- a/GreenshotPlugin/Core/ImageHelper.cs +++ b/GreenshotPlugin/Core/ImageHelper.cs @@ -29,6 +29,7 @@ using GreenshotPlugin.UnmanagedHelpers; using GreenshotPlugin.Core; using Greenshot.IniFile; using System.Runtime.InteropServices; +using System.Collections; namespace GreenshotPlugin.Core { /// @@ -1024,9 +1025,15 @@ namespace GreenshotPlugin.Core { return quantizer; } - public static Bitmap Quantize(Bitmap sourceBitmap, IColorQuantizer quantizer) { + /// + /// Quantize the sourceBitmap with the Quantizer returned by PrepareQuantize + /// + /// + /// + /// Quantized bitmap + public static Bitmap Quantize(Bitmap sourceBitmap, IColorQuantizer quantizer, int paletteSize) { Bitmap result = new Bitmap(sourceBitmap.Width, sourceBitmap.Height, PixelFormat.Format8bppIndexed); - List palette = quantizer.GetPalette(255); + List palette = quantizer.GetPalette(paletteSize); ColorPalette imagePalette = result.Palette; // copies all color entries for (Int32 index = 0; index < palette.Count; index++) {