Example #1
0
 public NoDithering(IColorSpaceComparison comparison, List <DominoColor> palette)
 {
     comp       = comparison;
     lab_colors = new List <Lab>();
     for (int i = 0; i < palette.Count; i++)
     {
         lab_colors.Add((new Rgb {
             R = palette[i].rgb.R, G = palette[i].rgb.G, B = palette[i].rgb.B
         }).To <Lab>());
     }
 }
        override public int[,] Dither(WriteableBitmap input, IColorSpaceComparison comparison, float threshold = Int32.MaxValue)
        {
            bitmap = input;
            IntPtr backBuffer = bitmap.BackBuffer;

            pbuff = (byte *)backBuffer.ToPointer();
            field = new int[input.PixelWidth, input.PixelHeight];
            input.Lock();
            int bwidth        = input.PixelWidth;
            int bheight       = input.PixelHeight;
            int stride        = input.BackBufferStride;
            int bytesPerPixel = (input.Format.BitsPerPixel + 7) / 8;

            unsafe
            {
                byte *ptr       = (byte *)input.BackBuffer;
                int   cRowStart = 0;
                int   cColStart = 0;
                for (int row = 0; row < bheight; row++)
                {
                    cColStart = cRowStart;
                    for (int col = 0; col < bwidth; col++)
                    {
                        byte *bPixel = ptr + cColStart;
                        Lab   lab    = (new Rgb {
                            R = bPixel[2], G = bPixel[1], B = bPixel[0]
                        }).To <Lab>();

                        int newp = Compare(lab, comparison, lab_colors);
                        System.Windows.Media.Color newpixel = palette[newp].rgb;
                        field[col, row] = newp;
                        cColStart      += bytesPerPixel;
                        DiffuseError(col, row, bPixel[2] - newpixel.R, bPixel[1] - newpixel.G, bPixel[0] - newpixel.B);
                    }
                    cRowStart += stride;
                }
            }
            input.Unlock();
            return(field);
        }
Example #3
0
        public static int Compare(Lab a, IColorSpaceComparison comp, List <Lab> cols, float threshold = Int32.MaxValue)
        {
            int Minimum = 0;

            double min  = comp.Compare(a, cols[0]);
            double temp = Int32.MaxValue;

            for (int z = 1; z < cols.Count; z++)
            {
                temp = comp.Compare(cols[z], a);
                if (min > temp)
                {
                    min     = temp;
                    Minimum = z;
                }
            }

            //if (min > threshold) MessageBox.Show("Der Grenzwert von " + threshold + "wurde überschritten (" + min + "). \nFarbwert im Originalbild: (" + original.R + "; " + original.G + "; " + original.B + "), "
            //    + "\nNächste Farbe: Farbname: " + farben.Einstellung[Minimum].Farbname + ", Farbwert: (" + farben.Einstellung[Minimum].RGBwert.R + "; " + farben.Einstellung[Minimum].RGBwert.G + "; " +
            //    farben.Einstellung[Minimum].RGBwert.B + ").");
            return(Minimum);
        }
Example #4
0
 /// <summary>
 /// Convienience method for comparing any IColorSpace
 /// </summary>
 /// <param name="compareToValue"></param>
 /// <param name="comparer"></param>
 /// <returns>Single number representing the difference between two colors</returns>
 public double Compare(IColorSpace compareToValue, IColorSpaceComparison comparer)
 {
     return(comparer.Compare(this, compareToValue));
 }
Example #5
0
 /// <summary>
 /// Convienience method for comparing any IColorSpace
 /// </summary>
 /// <param name="compareToValue"></param>
 /// <param name="comparer"></param>
 /// <returns>Single number representing the difference between two colors</returns>
 public double Compare(IColorSpace compareToValue, IColorSpaceComparison comparer)
 {
     return(comparer.Compare(this.To <Lab>(), compareToValue.To <Lab>()));
 }
Example #6
0
 public abstract int[,] Dither(WriteableBitmap input, IColorSpaceComparison comparison, float treshold = Int32.MaxValue);
Example #7
0
 /// <summary>
 /// Convienience method for comparing any IColorSpace
 /// </summary>
 /// <param name="compareToValue"></param>
 /// <param name="comparer"></param>
 /// <returns>Single number representing the difference between two colors</returns>
 public static double Compare(this IColorSpace space, IColorSpace compareToValue, IColorSpaceComparison comparer)
 {
     return(comparer.Compare(space, compareToValue));
 }
Example #8
0
 public ColorFilter(IEnumerable<PaletteTile> paletteTiles)
 {
     _comparer = new Cie1976Comparison();
     _tiles = paletteTiles.ToList();
 }
 public AvgColorSearcher()
 {
     TileContainer = new TileContainer();
     TileContainer.LoadContainer();
     _comparer = new Cie1976Comparison();
     _usedTiles = new List<int>();
 }