public void QuantizersPerformanceTest()
 {
     using var bmpRef = Icons.Information.ExtractBitmap(new Size(256, 256));
     new PerformanceTest {
         TestName = $"{bmpRef.Width}x{bmpRef.Height}@{bmpRef.GetColorCount()}", Iterations = 25, CpuAffinity = null
     }
     .AddCase(() =>
     {
         using var result = bmpRef.CloneBitmap();
         result.Quantize(PredefinedColorsQuantizer.SystemDefault8BppPalette());
     }, nameof(PredefinedColorsQuantizer.SystemDefault8BppPalette))
     .AddCase(() =>
     {
         using var result = bmpRef.CloneBitmap();
         result.Quantize(OptimizedPaletteQuantizer.Octree());
     }, nameof(OptimizedPaletteQuantizer.Octree))
     .AddCase(() =>
     {
         using var result = bmpRef.CloneBitmap();
         result.Quantize(OptimizedPaletteQuantizer.MedianCut());
     }, nameof(OptimizedPaletteQuantizer.MedianCut))
     .AddCase(() =>
     {
         using var result = bmpRef.CloneBitmap();
         result.Quantize(OptimizedPaletteQuantizer.Wu());
     }, nameof(OptimizedPaletteQuantizer.Wu))
     .DoTest()
     .DumpResults(Console.Out);
 }
        public void DitherPerformanceTest(bool errorDiffusion)
        {
            using var bmpRef = Icons.Information.ExtractBitmap(new Size(256, 256));
            IQuantizer quantizer = PredefinedColorsQuantizer.SystemDefault8BppPalette();
            IDitherer  ditherer  = errorDiffusion ? (IDitherer)ErrorDiffusionDitherer.FloydSteinberg : OrderedDitherer.Bayer8x8;

            new PerformanceTest {
                TestName = $"{bmpRef.Width}x{bmpRef.Height}@{bmpRef.GetColorCount()} {(errorDiffusion ? "Error Diffusion" : "Ordered")}", Iterations = 100, CpuAffinity = null
            }
            .AddCase(() =>
            {
                using var result = bmpRef.CloneBitmap();
                result.Dither(quantizer, ditherer);
            }, "BitmapExtensions.Dither")
            .AddCase(() =>
            {
                using var result = bmpRef.CloneBitmap();
                using (IBitmapDataInternal bitmapData = BitmapDataFactory.CreateBitmapData(result, ImageLockMode.ReadWrite))
                    using (IQuantizingSession quantizingSession = quantizer.Initialize(bitmapData))
                        using (IDitheringSession ditheringSession = ditherer.Initialize(bitmapData, quantizingSession))
                        {
                            var row   = bitmapData.DoGetRow(0);
                            int width = bitmapData.Width;
                            do
                            {
                                for (int x = 0; x < width; x++)
                                {
                                    row.DoSetColor32(x, ditheringSession.GetDitheredColor(row.DoGetColor32(x), x, row.Index));
                                }
                            } while (row.MoveNextRow());
                        }
            }, "Sequential dithering")
            .DoTest()
            .DumpResults(Console.Out);
        }
        public void QuantizePerformanceTest()
        {
            //using var bmpRef = new Bitmap(@"D:\Letolt\MYSTY8RQER62.jpg");
            using var bmpRef = Icons.Information.ExtractBitmap(new Size(256, 256));
            IQuantizer quantizer = PredefinedColorsQuantizer.SystemDefault8BppPalette();

            new PerformanceTest {
                TestName = $"{bmpRef.Width}x{bmpRef.Height}@{bmpRef.GetColorCount()}", Iterations = 100, CpuAffinity = null
            }
            .AddCase(() =>
            {
                using var result = bmpRef.CloneBitmap();
                result.Quantize(quantizer);
            }, "BitmapExtensions.Quantize")
            .AddCase(() =>
            {
                using var result = bmpRef.CloneBitmap();
                using (IBitmapDataInternal bitmapData = BitmapDataFactory.CreateBitmapData(result, ImageLockMode.ReadWrite))
                    using (IQuantizingSession session = quantizer.Initialize(bitmapData))
                    {
                        var row   = bitmapData.DoGetRow(0);
                        int width = bitmapData.Width;
                        do
                        {
                            for (int x = 0; x < width; x++)
                            {
                                row.DoSetColor32(x, session.GetQuantizedColor(row.DoGetColor32(x)));
                            }
                        } while (row.MoveNextRow());
                    }
            }, "Sequential quantization")
            .DoTest()
            .DumpResults(Console.Out);
        }