diff --git a/src/ImageProcessorCore/Quantizers/Palette/PaletteQuantizer.cs b/src/ImageProcessorCore/Quantizers/Palette/PaletteQuantizer.cs
index 47f77a877..db2a4c59c 100644
--- a/src/ImageProcessorCore/Quantizers/Palette/PaletteQuantizer.cs
+++ b/src/ImageProcessorCore/Quantizers/Palette/PaletteQuantizer.cs
@@ -6,6 +6,7 @@
namespace ImageProcessorCore.Quantizers
{
using System;
+ using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
@@ -18,7 +19,7 @@ namespace ImageProcessorCore.Quantizers
///
/// A lookup table for colors
///
- private readonly Dictionary colorMap = new Dictionary();
+ private readonly ConcurrentDictionary colorMap = new ConcurrentDictionary();
///
/// List of all colors in the palette
@@ -58,7 +59,7 @@ namespace ImageProcessorCore.Quantizers
protected override byte QuantizePixel(Bgra32 pixel)
{
byte colorIndex = 0;
- int colorHash = pixel.Bgra;
+ string colorHash = pixel.ToString();
// Check if the color is in the lookup table
if (this.colorMap.ContainsKey(colorHash))
@@ -118,7 +119,7 @@ namespace ImageProcessorCore.Quantizers
}
// Now I have the color, pop it into the cache for next time
- this.colorMap[colorHash] = colorIndex;
+ this.colorMap.TryAdd(colorHash, colorIndex);
}
return colorIndex;
diff --git a/tests/ImageProcessorCore.Tests/Processors/Formats/EncoderDecoderTests.cs b/tests/ImageProcessorCore.Tests/Processors/Formats/EncoderDecoderTests.cs
index 9fbb7af35..f5cf32a4d 100644
--- a/tests/ImageProcessorCore.Tests/Processors/Formats/EncoderDecoderTests.cs
+++ b/tests/ImageProcessorCore.Tests/Processors/Formats/EncoderDecoderTests.cs
@@ -57,10 +57,27 @@
using (FileStream stream = File.OpenRead(file))
{
Image image = new Image(stream);
- IQuantizer quantizer = new OctreeQuantizer();
+
+ IQuantizer quantizer = new OctreeQuantizer();
QuantizedImage quantizedImage = quantizer.Quantize(image, 256);
- using (FileStream output = File.OpenWrite($"TestOutput/Quantize/{Path.GetFileName(file)}"))
+ using (FileStream output = File.OpenWrite($"TestOutput/Quantize/Octree-{Path.GetFileName(file)}"))
+ {
+ quantizedImage.ToImage().Save(output, image.CurrentImageFormat);
+ }
+
+ quantizer = new WuQuantizer();
+ quantizedImage = quantizer.Quantize(image, 256);
+
+ using (FileStream output = File.OpenWrite($"TestOutput/Quantize/Wu-{Path.GetFileName(file)}"))
+ {
+ quantizedImage.ToImage().Save(output, image.CurrentImageFormat);
+ }
+
+ quantizer = new PaletteQuantizer();
+ quantizedImage = quantizer.Quantize(image, 256);
+
+ using (FileStream output = File.OpenWrite($"TestOutput/Quantize/Palette-{Path.GetFileName(file)}"))
{
quantizedImage.ToImage().Save(output, image.CurrentImageFormat);
}
@@ -84,7 +101,7 @@
using (FileStream output = File.OpenWrite($"TestOutput/Indexed/{Path.GetFileNameWithoutExtension(file)}.png"))
{
- image.Quality = 255;
+ image.Quality = 256;
image.Save(output, new PngFormat());
}
}