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
This commit is contained in:
RKrom 2012-03-20 16:55:12 +00:00
parent b464480bf6
commit 519e5b8ab2
2 changed files with 11 additions and 4 deletions

View file

@ -106,8 +106,8 @@ namespace Greenshot.Helpers {
LOG.InfoFormat("Image with format {0} has {1} colors", imageToSave.PixelFormat, colorCount); LOG.InfoFormat("Image with format {0} has {1} colors", imageToSave.PixelFormat, colorCount);
if (reduceColors || colorCount < 256) { if (reduceColors || colorCount < 256) {
try { try {
LOG.Debug("Reducing colors on bitmap."); LOG.Info("Reducing colors on bitmap to 255.");
imageToSave = ImageHelper.Quantize((Bitmap)imageToSave, quantizer); imageToSave = ImageHelper.Quantize((Bitmap)imageToSave, quantizer, 255);
// Make sure the "new" image is disposed // Make sure the "new" image is disposed
disposeImage = true; disposeImage = true;
} catch(Exception e) { } catch(Exception e) {

View file

@ -29,6 +29,7 @@ using GreenshotPlugin.UnmanagedHelpers;
using GreenshotPlugin.Core; using GreenshotPlugin.Core;
using Greenshot.IniFile; using Greenshot.IniFile;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Collections;
namespace GreenshotPlugin.Core { namespace GreenshotPlugin.Core {
/// <summary> /// <summary>
@ -1024,9 +1025,15 @@ namespace GreenshotPlugin.Core {
return quantizer; return quantizer;
} }
public static Bitmap Quantize(Bitmap sourceBitmap, IColorQuantizer quantizer) { /// <summary>
/// Quantize the sourceBitmap with the Quantizer returned by PrepareQuantize
/// </summary>
/// <param name="sourceBitmap"></param>
/// <param name="quantizer"></param>
/// <returns>Quantized bitmap</returns>
public static Bitmap Quantize(Bitmap sourceBitmap, IColorQuantizer quantizer, int paletteSize) {
Bitmap result = new Bitmap(sourceBitmap.Width, sourceBitmap.Height, PixelFormat.Format8bppIndexed); Bitmap result = new Bitmap(sourceBitmap.Width, sourceBitmap.Height, PixelFormat.Format8bppIndexed);
List<Color> palette = quantizer.GetPalette(255); List<Color> palette = quantizer.GetPalette(paletteSize);
ColorPalette imagePalette = result.Palette; ColorPalette imagePalette = result.Palette;
// copies all color entries // copies all color entries
for (Int32 index = 0; index < palette.Count; index++) { for (Int32 index = 0; index < palette.Count; index++) {