Example #1
0
        /// <summary>
        /// Applies quantization to the image.
        /// </summary>
        /// <typeparam name="T">The pixel format.</typeparam>
        /// <typeparam name="TP">The packed format. <example>long, float.</example></typeparam>
        /// <param name="source">The image this method extends.</param>
        /// <param name="quantizer">The quantizer to apply to perform the operation.</param>
        /// <param name="maxColors">The maximum number of colors to return.</param>
        /// <returns>The <see cref="Image{T,TP}"/>.</returns>
        public static Image <T, TP> Quantize <T, TP>(this Image <T, TP> source, IQuantizer <T, TP> quantizer, int maxColors)
            where T : IPackedVector <TP>
            where TP : struct
        {
            QuantizedImage <T, TP> quantizedImage = quantizer.Quantize(source, maxColors);

            source.SetPixels(source.Width, source.Height, quantizedImage.ToImage().Pixels);
            return(source);
        }