diff --git a/src/ImageProcessor/Imaging/Quantizers/Quantizer.cs b/src/ImageProcessor/Imaging/Quantizers/Quantizer.cs
index 55bddb0a2..0c546d374 100644
--- a/src/ImageProcessor/Imaging/Quantizers/Quantizer.cs
+++ b/src/ImageProcessor/Imaging/Quantizers/Quantizer.cs
@@ -44,10 +44,10 @@ namespace ImageProcessor.Imaging.Quantizers
}
///
- /// Quantize an image and return the resulting output bitmap
+ /// Quantize an image and return the resulting output bitmap.
///
- /// The image to quantize
- /// A quantized version of the image
+ /// The image to quantize.
+ /// A quantized version of the image.
public Bitmap Quantize(Image source)
{
// Get the size of the source image
diff --git a/src/ImageProcessor/Imaging/Quantizers/WuQuantizer/ColorMoment.cs b/src/ImageProcessor/Imaging/Quantizers/WuQuantizer/ColorMoment.cs
index d69b590bd..67040e58b 100644
--- a/src/ImageProcessor/Imaging/Quantizers/WuQuantizer/ColorMoment.cs
+++ b/src/ImageProcessor/Imaging/Quantizers/WuQuantizer/ColorMoment.cs
@@ -12,23 +12,23 @@
namespace ImageProcessor.Imaging.Quantizers.WuQuantizer
{
///
- /// The color moment for holding pixel information.
+ /// The cumulative color moment for holding pixel information.
/// Adapted from
///
internal struct ColorMoment
{
///
- /// The alpha.
+ /// The alpha component.
///
public long Alpha;
///
- /// The blue.
+ /// The blue component.
///
public long Blue;
///
- /// The green.
+ /// The green component.
///
public long Green;
diff --git a/src/ImageProcessor/Imaging/Quantizers/WuQuantizer/WuQuantizerBase.cs b/src/ImageProcessor/Imaging/Quantizers/WuQuantizer/WuQuantizerBase.cs
index 4b49cf6ba..c34e9141d 100644
--- a/src/ImageProcessor/Imaging/Quantizers/WuQuantizer/WuQuantizerBase.cs
+++ b/src/ImageProcessor/Imaging/Quantizers/WuQuantizer/WuQuantizerBase.cs
@@ -1,32 +1,101 @@
-using System;
-using System.Drawing;
-using System.Linq;
-
-namespace ImageProcessor.Imaging.Quantizers.WuQuantizer
+namespace ImageProcessor.Imaging.Quantizers.WuQuantizer
{
+ using System;
+ using System.Drawing;
+ using System.Linq;
+
+ ///
+ /// Encapsulates methods to calculate the color palette of an image using
+ /// a Wu color quantizer .
+ /// Adapted from
+ ///
public abstract class WuQuantizerBase
{
+ ///
+ /// The alpha color component.
+ ///
protected const byte AlphaColor = 255;
+
+ ///
+ /// The position of the alpha component within a byte array.
+ ///
protected const int Alpha = 3;
+
+ ///
+ /// The position of the red component within a byte array.
+ ///
protected const int Red = 2;
+
+ ///
+ /// The position of the green component within a byte array.
+ ///
protected const int Green = 1;
+
+ ///
+ /// The position of the blue component within a byte array.
+ ///
protected const int Blue = 0;
+
+ ///
+ /// The size of a color cube side.
+ ///
private const int SideSize = 33;
+
+ ///
+ /// The maximum index within a color cube side
+ ///
private const int MaxSideIndex = 32;
- public Image QuantizeImage(Bitmap image)
+ ///
+ /// Quantize an image and return the resulting output bitmap
+ ///
+ ///
+ /// The 32 bit per pixel image to quantize.
+ ///
+ /// A quantized version of the image.
+ public Image QuantizeImage(Bitmap source)
{
- return QuantizeImage(image, 0, 1);
+ return this.QuantizeImage(source, 0, 1);
}
- public Image QuantizeImage(Bitmap image, int alphaThreshold, int alphaFader)
+ ///
+ /// Quantize an image and return the resulting output bitmap
+ ///
+ ///
+ /// The 32 bit per pixel image to quantize.
+ ///
+ /// All colors with an alpha value less than this will be considered fully transparent.
+ /// Alpha values will be normalized to the nearest multiple of this value.
+ /// A quantized version of the image.
+ public Image QuantizeImage(Bitmap source, int alphaThreshold, int alphaFader)
{
- return QuantizeImage(image, alphaThreshold, alphaFader, null, 256);
+ return this.QuantizeImage(source, alphaThreshold, alphaFader, null, 256);
}
- public Image QuantizeImage(Bitmap image, int alphaThreshold, int alphaFader, Histogram histogram, int maxColors)
+ ///
+ /// Quantize an image and return the resulting output bitmap
+ ///
+ ///
+ /// The 32 bit per pixel image to quantize.
+ ///
+ ///
+ /// All colors with an alpha value less than this will be considered fully transparent.
+ ///
+ ///
+ /// Alpha values will be normalized to the nearest multiple of this value.
+ ///
+ ///
+ /// The representing the distribution of color data.
+ ///
+ ///
+ /// The maximum number of colors apply to the image.
+ ///
+ ///
+ /// A quantized version of the image.
+ ///
+ public Image QuantizeImage(Bitmap source, int alphaThreshold, int alphaFader, Histogram histogram, int maxColors)
{
- var buffer = new ImageBuffer(image);
+ ImageBuffer buffer = new ImageBuffer(source);
if (histogram == null)
{
@@ -39,16 +108,31 @@ namespace ImageProcessor.Imaging.Quantizers.WuQuantizer
BuildHistogram(histogram, buffer, alphaThreshold, alphaFader);
CalculateMoments(histogram.Moments);
- var cubes = SplitData(ref maxColors, histogram.Moments);
- var lookups = BuildLookups(cubes, histogram.Moments);
+ Box[] cubes = SplitData(ref maxColors, histogram.Moments);
+ Pixel[] lookups = BuildLookups(cubes, histogram.Moments);
return this.GetQuantizedImage(buffer, maxColors, lookups, alphaThreshold);
}
- private static void BuildHistogram(Histogram histogram, ImageBuffer sourceImage, int alphaThreshold, int alphaFader)
+ ///
+ /// Builds a histogram from the current image.
+ ///
+ ///
+ /// The representing the distribution of color data.
+ ///
+ ///
+ /// The for storing pixel information.
+ ///
+ ///
+ /// All colors with an alpha value less than this will be considered fully transparent.
+ ///
+ ///
+ /// Alpha values will be normalized to the nearest multiple of this value.
+ ///
+ private static void BuildHistogram(Histogram histogram, ImageBuffer imageBuffer, int alphaThreshold, int alphaFader)
{
ColorMoment[,,,] moments = histogram.Moments;
- foreach (Pixel[] pixelLine in sourceImage.PixelLines)
+ foreach (Pixel[] pixelLine in imageBuffer.PixelLines)
{
foreach (Pixel pixel in pixelLine)
{