Esempio n. 1
0
        static Bitmap FilterLite(Bitmap source, PixelFormat format)
        {
            var result = new PrecisionBitmap(TileBuffer(source));

            for (int y = 0; y < result.Height; y++)
            {
                for (int x = 0; x < result.Width; x++)
                {
                    PrecisionColor oldPixel = result.GetPixel(x, y);
                    PrecisionColor newPixel = ApproximatePixel(oldPixel, format);
                    PrecisionColor error    = oldPixel - newPixel;
                    result.SetPixel(x, y, newPixel);

                    int xP1 = GetActualPosition(x + 1, result.Width);
                    int xM1 = GetActualPosition(x - 1, result.Width);
                    int yP1 = GetActualPosition(y + 1, result.Height);

                    result.SetPixel(xP1, y, result.GetPixel(xP1, y) + error * 0.5);
                    result.SetPixel(xM1, yP1, result.GetPixel(xM1, yP1) + error * 0.25);
                    result.SetPixel(x, yP1, result.GetPixel(x, yP1) + error * 0.25);
                }
            }

            return(result.ToBitmap());
        }
Esempio n. 2
0
        static Bitmap Sierra3(Bitmap source, PixelFormat format)
        {
            var result = new PrecisionBitmap(TileBuffer(source));

            double weight2 = 2 / 32d;
            double weight3 = 3 / 32d;
            double weight4 = 4 / 32d;
            double weight5 = 5 / 32d;

            for (int y = 0; y < result.Height; y++)
            {
                for (int x = 0; x < result.Width; x++)
                {
                    PrecisionColor oldPixel = result.GetPixel(x, y);
                    PrecisionColor newPixel = ApproximatePixel(oldPixel, format);
                    PrecisionColor error    = oldPixel - newPixel;
                    result.SetPixel(x, y, newPixel);

                    int xP1 = GetActualPosition(x + 1, result.Width);
                    int xP2 = GetActualPosition(x + 2, result.Width);
                    int xM1 = GetActualPosition(x - 1, result.Width);
                    int xM2 = GetActualPosition(x - 2, result.Width);
                    int yP1 = GetActualPosition(y + 1, result.Height);
                    int yP2 = GetActualPosition(y + 2, result.Height);

                    result.SetPixel(xP1, y, result.GetPixel(xP1, y) + error * weight5);
                    result.SetPixel(xP2, y, result.GetPixel(xP2, y) + error * weight3);

                    result.SetPixel(xM2, yP1, result.GetPixel(xM2, yP1) + error * weight2);
                    result.SetPixel(xM1, yP1, result.GetPixel(xM1, yP1) + error * weight4);
                    result.SetPixel(x, yP1, result.GetPixel(x, yP1) + error * weight5);
                    result.SetPixel(xP1, yP1, result.GetPixel(xP1, yP1) + error * weight4);
                    result.SetPixel(xP2, yP1, result.GetPixel(xP2, yP1) + error * weight2);

                    result.SetPixel(xM1, yP2, result.GetPixel(xM1, yP2) + error * weight2);
                    result.SetPixel(x, yP2, result.GetPixel(x, yP2) + error * weight3);
                    result.SetPixel(xP1, yP2, result.GetPixel(xP1, yP2) + error * weight2);
                }
            }

            return(result.ToBitmap());
        }