public static SuperColor FromHSV(SuperColor hsv) { float Hd = 6 * hsv.R; int Hdi = ( int )Math.Floor(6 * hsv.R); float F = Hd - Hdi; float P = hsv.B * (1 - hsv.G); float Q = hsv.B * (1 - hsv.G * F); float T = hsv.B * (1 - hsv.G * (1 - F)); switch (Hdi) { case 0: return(new SuperColor(hsv.B, T, P)); case 1: return(new SuperColor(Q, hsv.B, P)); case 2: return(new SuperColor(P, hsv.B, T)); case 3: return(new SuperColor(P, Q, hsv.B)); case 4: return(new SuperColor(T, P, hsv.B)); case 5: return(new SuperColor(hsv.B, P, Q)); case 6: return(new SuperColor(hsv.B, T, P)); case -1: return(new SuperColor(hsv.B, P, Q)); default: throw new ArgumentException(); } }
public void MakeRGBFromHSV() { Parallel.For(0, Height, (y) => { for (int x = 0; x < Width; ++x) { colorMap [x, y] = SuperColor.FromHSV(colorMap [x, y]); } }); }
public ProcessImage(Bitmap bitmap) : this(bitmap.Width, bitmap.Height) { var bitmapData = bitmap.LockBits(new Rectangle(0, 0, Width, Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); Parallel.For(0, Height, (y) => { int wy = Width * y; for (int x = 0; x < Width; ++x) { colorMap [x, y] = new SuperColor(Marshal.ReadInt32(bitmapData.Scan0 + ((wy + x) * 4))); } }); bitmap.UnlockBits(bitmapData); }
public SuperColor FilterProcess(int x, int y, Filter filter) { int filterWidthCenter = x - filter.FilterHalfWidth; int filterHeightCenter = y - filter.FilterHalfHeight; SuperColor total = new SuperColor(); for (int ty = 0; ty < filter.FilterHeight; ++ty) { for (int tx = 0; tx < filter.FilterWidth; ++tx) { var c = this [filterWidthCenter + tx, filterHeightCenter + ty]; c.Multiply(filter.FilterData [tx, ty]); total.Add(ref c); } } total.Multiply(filter.Factor); return(total + filter.Bias); }
public void Add(ref SuperColor c) { R += c.R; G += c.G; B += c.B; }