public static Bitmap DarkerImage(Bitmap source, int val) => source.LinearFilter(input => { var red = Max(0, input.R - val); var green = Max(0, input.G - val); var blue = Max(0, input.B - val); return Color.FromArgb(red, green, blue); });
public static Bitmap BrighterImage(Bitmap source, int val) => source.LinearFilter(input => { var red = Min(255, input.R + val); var green = Min(255, input.G + val); var blue = Min(255, input.B + val); return Color.FromArgb(red, green, blue); });
public static Bitmap Invert(Bitmap source) => source.LinearFilter(input => { var red = 255 - input.R; var green = 255 - input.G; var blue = 255 - input.B; return Color.FromArgb(red, green, blue); });
public static Bitmap SepiaTone(Bitmap source) => source.LinearFilter(input => { var red = (int)(input.R * 0.462); var green = (int)(input.G * 0.193); var blue = (int)(input.B * 0.1083); return Color.FromArgb(red, green, blue); });
// the linear filters are just functions f: Color -> Color to process every pixel in parallel public static Bitmap GrayScale(Bitmap source) => source.LinearFilter(input => { var avg = (input.R + input.G + input.B)/3; return Color.FromArgb(avg, avg, avg); });