// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // using ImageProcessorCore.Quantizers; namespace ImageProcessorCore { /// /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Applies quantization to the image. /// /// The pixel format. /// The packed format. long, float. /// The image this method extends. /// The quantization mode to apply to perform the operation. /// The maximum number of colors to return. Defaults to 256. /// The . public static Image Quantize(this Image source, Quantization mode = Quantization.Octree, int maxColors = 256) where T : IPackedVector where TP : struct { IQuantizer quantizer; switch (mode) { case Quantization.Wu: quantizer = new WuQuantizer(); break; case Quantization.Palette: quantizer = new PaletteQuantizer(); break; default: quantizer = new OctreeQuantizer(); break; } return Quantize(source, quantizer, maxColors); } /// /// Applies quantization to the image. /// /// The pixel format. /// The packed format. long, float. /// The image this method extends. /// The quantizer to apply to perform the operation. /// The maximum number of colors to return. /// The . public static Image Quantize(this Image source, IQuantizer quantizer, int maxColors) where T : IPackedVector where TP : struct { QuantizedImage quantizedImage = quantizer.Quantize(source, maxColors); source.SetPixels(source.Width, source.Height, quantizedImage.ToImage().Pixels); return source; } } }