protected override Pixel QuantizatePixel(int x, int y)
        {
            // Get nearest color from palette
            int colorIndex = nearestNeighbour.Search(labImg[y, x]);

            // Apply dithering algorithm for each channel
            LabColor oldPixel = labImg[y, x];
            LabColor newPixel = labPalette[colorIndex];

            this.Dithering.ApplyDithering(labImg.Data, x, y, 0, oldPixel.X - newPixel.X);
            this.Dithering.ApplyDithering(labImg.Data, x, y, 1, oldPixel.Y - newPixel.Y);
            this.Dithering.ApplyDithering(labImg.Data, x, y, 2, oldPixel.Z - newPixel.Z);

            // If it's a transparent color, set the first palette color
            Color rgbColor = this.rgbImg[y, x];

            if (rgbColor.Alpha == 0)
            {
                return(new Pixel(0, 0, true));
            }
            else
            {
                return(new Pixel((uint)colorIndex, (uint)rgbColor.Alpha, true));
            }
        }
Пример #2
0
        protected override Pixel QuantizatePixel(int x, int y)
        {
            // Get the color and add to the list
            Color color = image[y, x];

            int colorIndex;

            if (listColor.Count < this.MaxColors)
            {
                if (!listColor.Contains(color))
                {
                    listColor.Add(color);
                }
                colorIndex = listColor.IndexOf(color);
            }
            else
            {
                // Create the labpalette if so
                if (nearestNeighbour == null)
                {
                    LabColor[] labPalette = ColorConversion.ToLabPalette <Color>(listColor.ToArray());
                    nearestNeighbour = new ExhaustivePaletteSearch();
                    nearestNeighbour.Initialize(labPalette);
                }

                LabColor labNoTrans = ColorConversion.ToLabPalette <Color>(new Color[] { color })[0];
                colorIndex = nearestNeighbour.Search(labNoTrans);
            }

            return(new Pixel((uint)colorIndex, (uint)color.Alpha, true));
        }