public static bool Saturation(ref Bitmap bmp, double percent) { double level = 1.0 + percent / 100; double baseF = 1.0 - level; double rF = 0.3086 * baseF; double gF = 0.6094 * baseF; double bF = 0.0820 * baseF; P2PFunc func = new P2PFunc(SaturationFunc); return P2PCore(ref bmp, func, rF, gF, bF, level, 0, 0, 0); }
public static bool Luminance(ref Bitmap bmp, int percent) { double ll = 255d * percent / 100; P2PFunc func = new P2PFunc(LuminanceFunc); return P2PCore(ref bmp, func, ll); }
public static bool P2PCore(ref Bitmap bmp, P2PFunc func, params double[] param) { if (bmp.PixelFormat != PixelFormat.Format24bppRgb) return false; int w = bmp.Width; int h = bmp.Height; byte r, g, b; int ir; BmpProc24 bd = new BmpProc24(bmp); for (int y = 0; y < h; y++) for (int x = 0; x < w; x++) { ir = bd.IndexR(x, y); r = bd[ir]; g = bd[ir - 1]; b = bd[ir - 2]; func(ref r, ref g, ref b, param); bd[ir] = r; bd[ir - 1] = g; bd[ir - 2] = b; } bd.Dispose(); return true; }
public static bool Hue(ref Bitmap bmp, int angle) { if ((angle < -359) | (angle > 359)) return false; P2PFunc func = new P2PFunc(HueFunc); return P2PCore(ref bmp, func, angle); }
public static bool Invert(ref Bitmap bmp) { P2PFunc func = new P2PFunc(InvertFunc); return P2PCore(ref bmp, func); }
public static bool GrayScale24(ref Bitmap bmp) { P2PFunc func = new P2PFunc(GrayScale24Func); return P2PCore(ref bmp, func); }
public static bool Gamma(ref Bitmap bmp, double dGamma) { double[] gammaf = new double[256]; for (int i = 0; i < 256; i++) gammaf[i] = Math.Min(255.0, Math.Pow((double)(i / 255.0), (1.0 / dGamma)) * 255 + 0.5); P2PFunc func = new P2PFunc(GammaFunc); return P2PCore(ref bmp, func, gammaf); }
public static bool Contrast(ref Bitmap bmp, double factor) { if ((factor > 1) || (factor < -1)) return false; double value = (1 + factor) * (1 + factor); double[] d = new double[256]; for (int i = 0; i < 256; i++) d[i] = AdjustByte((i - 127.5) * value + 127.5); P2PFunc func = new P2PFunc(ContrastFunc); return P2PCore(ref bmp, func, d); }
public static bool ColorFilter(ref Bitmap bmp, double fRed, double fGreen, double fBlue) { P2PFunc func = new P2PFunc(ColorFilterFunc); return P2PCore(ref bmp, func, fRed, fGreen, fBlue); }
public static bool Brightness(ref Bitmap bmp, double factor) { if ((factor < 0) || (factor > 2)) return false; factor = (factor - 1) * 255; P2PFunc func = new P2PFunc(BrightnessFunc); return P2PCore(ref bmp, func, factor); }