Fix early exit bug in palette builder and change to far more conservative threshold

This commit is contained in:
tznind
2024-09-23 20:41:26 +01:00
parent f07ab92dca
commit 2378570015
2 changed files with 2 additions and 3 deletions

View File

@@ -28,7 +28,7 @@ public class ColorQuantizer
/// <summary>
/// Gets or sets the algorithm used to build the <see cref="Palette"/>.
/// </summary>
public IPaletteBuilder PaletteBuildingAlgorithm { get; set; } = new PopularityPaletteWithThreshold (new EuclideanColorDistance (),50) ;
public IPaletteBuilder PaletteBuildingAlgorithm { get; set; } = new PopularityPaletteWithThreshold (new EuclideanColorDistance (),5) ;
public void BuildPalette (Color [,] pixels)
{

View File

@@ -93,9 +93,8 @@ public class PopularityPaletteWithThreshold : IPaletteBuilder
mergedHistogram [currentColor] = entry.Value;
}
// Early exit if we've reduced the colors to the maxColors limit
if (mergedHistogram.Count <= maxColors)
if (mergedHistogram.Count >= maxColors)
{
return mergedHistogram;
}