Ejemplo n.º 1
0
        private (IEnumerable <int> indices, IList <Color> palette) QuantizeImage(Bitmap image, Size paddedSize, IProgressContext progress = null)
        {
            var imageSize = paddedSize.IsEmpty ? image.Size : paddedSize;

            // Decompose unswizzled image to colors
            var colors = image.ToColors(paddedSize);

            // Quantize unswizzled indices
            var(indices, palette) = _quantizer.Process(colors, imageSize, progress);

            // Swizzle indices to correct positions
            var swizzledIndices = SwizzleIndices(indices.ToArray(), imageSize, _swizzle?.Invoke(imageSize));

            return(swizzledIndices, palette);
        }
Ejemplo n.º 2
0
        private (IEnumerable <int> indices, IList <Color> palette) QuantizeImage(Bitmap image, Size paddedSize, IImageSwizzle swizzle, IProgressContext progress = null)
        {
            var finalSize   = GetFinalSize(paddedSize, swizzle);
            var colorShader = _shadeColorsFunc?.Invoke();

            // Decompose unswizzled image to colors
            var colors = image.ToColors(paddedSize);

            // Quantize unswizzled indices
            var(indices, palette) = _quantizer.Process(colors, finalSize, progress);

            // Apply color shader
            if (colorShader != null)
            {
                palette = palette.Select(colorShader.Write).ToArray();
            }

            // Delegate indices to correct positions
            var swizzledIndices = SwizzleIndices(indices.ToArray(), finalSize, swizzle);

            return(swizzledIndices, palette);
        }