private void ChangeDitherer() { activeDitherer = dithererList[listDitherer.SelectedIndex]; }
public void Dither(ImageBuffer target, IColorDitherer ditherer, IColorQuantizer quantizer, Int32 colorCount, Int32 parallelTaskCount = 4) { // checks parameters Guard.CheckNull(target, "target"); Guard.CheckNull(ditherer, "ditherer"); Guard.CheckNull(quantizer, "quantizer"); // prepares ditherer for another round ditherer.Prepare(quantizer, colorCount, this, target); // processes the image via the ditherer IList<Point> path = ditherer.GetPointPath(Width, Height); TransformPerPixel(target, path, ditherer.ProcessPixel, parallelTaskCount); }
public void Quantize(ImageBuffer target, IColorQuantizer quantizer, IColorDitherer ditherer, Int32 colorCount, Int32 parallelTaskCount = 4) { // checks parameters Guard.CheckNull(target, "target"); Guard.CheckNull(quantizer, "quantizer"); // initializes quantization parameters Boolean isTargetIndexed = target.PixelFormat.IsIndexed(); // step 1 - prepares the palettes List<Color> targetPalette = isTargetIndexed ? SynthetizePalette(quantizer, colorCount, parallelTaskCount) : null; // step 2 - updates the bitmap palette target.bitmap.SetPalette(targetPalette); target.UpdatePalette(true); // step 3 - prepares ditherer (optional) if (ditherer != null) ditherer.Prepare(quantizer, colorCount, this, target); // step 4 - prepares the quantization function TransformPixelFunction quantize = (sourcePixel, targetPixel) => { // reads the pixel color Color color = GetColorFromPixel(sourcePixel); // converts alpha to solid color color = QuantizationHelper.ConvertAlpha(color); // quantizes the pixel SetColorToPixel(targetPixel, color, quantizer); // marks pixel as processed by default Boolean result = true; // preforms inplace dithering (optional) if (ditherer != null && ditherer.IsInplace) { result = ditherer.ProcessPixel(sourcePixel, targetPixel); } // returns the result return result; }; // step 5 - generates the target image IList<Point> path = quantizer.GetPointPath(Width, Height); TransformPerPixel(target, path, quantize, parallelTaskCount); // step 6 - preforms non-inplace dithering (optional) if (ditherer != null && !ditherer.IsInplace) { Dither(target, ditherer, quantizer, colorCount, 1); } // step 7 - finishes the dithering (optional) if (ditherer != null) ditherer.Finish(); // step 8 - clean-up quantizer.Finish(); }
public static Image QuantizeImage(ImageBuffer source, IColorQuantizer quantizer, IColorDitherer ditherer, Int32 colorCount, Int32 parallelTaskCount = 4) { // checks parameters Guard.CheckNull(source, "source"); // creates a target bitmap in an appropriate format PixelFormat targetPixelFormat = Extend.GetFormatByColorCount(colorCount); Image result = new Bitmap(source.Width, source.Height, targetPixelFormat); // lock mode ImageLockMode lockMode = ditherer == null ? ImageLockMode.WriteOnly : ImageLockMode.ReadWrite; // wraps target image to a buffer using (ImageBuffer target = new ImageBuffer(result, lockMode)) { source.Quantize(target, quantizer, ditherer, colorCount, parallelTaskCount); return result; } }
public static Image QuantizeImage(Image sourceImage, IColorQuantizer quantizer, IColorDitherer ditherer, Int32 colorCount, Int32 parallelTaskCount = 4) { // checks parameters Guard.CheckNull(sourceImage, "sourceImage"); // lock mode ImageLockMode lockMode = ditherer == null ? ImageLockMode.ReadOnly : ImageLockMode.ReadWrite; // wraps source image to a buffer using (ImageBuffer source = new ImageBuffer(sourceImage, lockMode)) { return QuantizeImage(source, quantizer, ditherer, colorCount, parallelTaskCount); } }
public static void DitherImage(Image sourceImage, Image targetImage, IColorDitherer ditherer, IColorQuantizer quantizer, Int32 colorCount, Int32 parallelTaskCount = 4) { // checks parameters Guard.CheckNull(sourceImage, "sourceImage"); Guard.CheckNull(targetImage, "targetImage"); // wraps source image to a buffer using (ImageBuffer source = new ImageBuffer(sourceImage, ImageLockMode.ReadOnly)) using (ImageBuffer target = new ImageBuffer(targetImage, ImageLockMode.ReadOnly)) { // use other override to calculate error source.Dither(target, ditherer, quantizer, colorCount, parallelTaskCount); } }
public static void DitherImage(ImageBuffer source, ImageBuffer target, IColorDitherer ditherer, IColorQuantizer quantizer, Int32 colorCount, Int32 parallelTaskCount = 4) { // checks parameters Guard.CheckNull(source, "source"); // use other override to calculate error source.Dither(target, ditherer, quantizer, colorCount, parallelTaskCount); }
public static Image QuantizeImage(Image sourceImage, IColorQuantizer quantizer, IColorDitherer ditherer, Int32 colorCount, Int32 parallelTaskCount = 4) { // checks parameters Guard.CheckNull(sourceImage, "sourceImage"); // lock mode ImageLockMode lockMode = ditherer == null ? ImageLockMode.ReadOnly : ImageLockMode.ReadWrite; // wraps source image to a buffer using (ImageBuffer source = new ImageBuffer(sourceImage, lockMode)) { return(QuantizeImage(source, quantizer, ditherer, colorCount, parallelTaskCount)); } }
public static Image QuantizeImage(ImageBuffer source, IColorQuantizer quantizer, IColorDitherer ditherer, Int32 colorCount, Int32 parallelTaskCount = 4) { // checks parameters Guard.CheckNull(source, "source"); // creates a target bitmap in an appropriate format PixelFormat targetPixelFormat = Extend.GetFormatByColorCount(colorCount); Image result = new Bitmap(source.Width, source.Height, targetPixelFormat); // lock mode ImageLockMode lockMode = ditherer == null ? ImageLockMode.WriteOnly : ImageLockMode.ReadWrite; // wraps target image to a buffer using (ImageBuffer target = new ImageBuffer(result, lockMode)) { source.Quantize(target, quantizer, ditherer, colorCount, parallelTaskCount); return(result); } }
public void Quantize(ImageBuffer target, IColorQuantizer quantizer, IColorDitherer ditherer, Int32 colorCount, Int32 parallelTaskCount = 4) { // checks parameters Guard.CheckNull(target, "target"); Guard.CheckNull(quantizer, "quantizer"); // initializes quantization parameters Boolean isTargetIndexed = target.PixelFormat.IsIndexed(); // step 1 - prepares the palettes List <Color> targetPalette = isTargetIndexed ? SynthetizePalette(quantizer, colorCount, parallelTaskCount) : null; // step 2 - updates the bitmap palette target.bitmap.SetPalette(targetPalette); target.UpdatePalette(true); // step 3 - prepares ditherer (optional) if (ditherer != null) { ditherer.Prepare(quantizer, colorCount, this, target); } // step 4 - prepares the quantization function TransformPixelFunction quantize = (sourcePixel, targetPixel) => { // reads the pixel color Color color = GetColorFromPixel(sourcePixel); // converts alpha to solid color color = QuantizationHelper.ConvertAlpha(color); // quantizes the pixel SetColorToPixel(targetPixel, color, quantizer); // marks pixel as processed by default Boolean result = true; // preforms inplace dithering (optional) if (ditherer != null && ditherer.IsInplace) { result = ditherer.ProcessPixel(sourcePixel, targetPixel); } // returns the result return(result); }; // step 5 - generates the target image IList <Point> path = quantizer.GetPointPath(Width, Height); TransformPerPixel(target, path, quantize, parallelTaskCount); // step 6 - preforms non-inplace dithering (optional) if (ditherer != null && !ditherer.IsInplace) { Dither(target, ditherer, quantizer, colorCount, 1); } // step 7 - finishes the dithering (optional) if (ditherer != null) { ditherer.Finish(); } // step 8 - clean-up quantizer.Finish(); }