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()); }
static Bitmap Sierra2(Bitmap source, PixelFormat format) { var result = new PrecisionBitmap(TileBuffer(source)); double weight1 = 1 / 16d; double weight2 = 2 / 16d; double weight3 = 3 / 16d; double weight4 = 4 / 16d; 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); result.SetPixel(xP1, y, result.GetPixel(xP1, y) + error * weight4); result.SetPixel(xP2, y, result.GetPixel(xP2, y) + error * weight3); result.SetPixel(xM2, yP1, result.GetPixel(xM2, yP1) + error * weight1); result.SetPixel(xM1, yP1, result.GetPixel(xM1, yP1) + error * weight2); result.SetPixel(x, yP1, result.GetPixel(x, yP1) + error * weight3); result.SetPixel(xP1, yP1, result.GetPixel(xP1, yP1) + error * weight2); result.SetPixel(xP2, yP1, result.GetPixel(xP2, yP1) + error * weight1); } } return(result.ToBitmap()); }