public override void Add(ColorD c) { m_r += c.R; m_g += c.G; m_b += c.B; m_count++; }
public override void Add(ColorD c) { c = c.FromGamma(2.2); m_r += c.R; m_g += c.G; m_b += c.B; m_count++; }
public override ColorD GetAvg48() { if (m_count == 0) { return new ColorD(); } else { ColorD ret = new ColorD(m_r / ((double)m_count), m_g / ((double)m_count), m_b / ((double)m_count)); ret = ret.ToGamma(2.2); return ret; } }
public override Color GetAvg() { if (m_count == 0) { return Color.FromArgb(0, 0, 0); } else { ColorD ret = new ColorD(m_r / ((double)m_count), m_g / ((double)m_count), m_b / ((double)m_count)); ret = ret.ToGamma(2.2); return Utils.Dither(ret); } }
public static Color Dither(ColorD color) { double r = color.R; double g = color.G; double b = color.B; r = r * 255.0 + Rnd.NextDouble(); g = g * 255.0 + Rnd.NextDouble(); b = b * 255.0 + Rnd.NextDouble(); return Color.FromArgb( Math.Min(255, Math.Max(0, (int)r)), Math.Min(255, Math.Max(0, (int)g)), Math.Min(255, Math.Max(0, (int)b))); }
public unsafe void Set(int x, int y, Color c, ColorD for48) { if (x < 0 || x >= m_width || y < 0 || y >= m_height || m_r == null) { throw new Exception(); } ((int*)m_data.Scan0)[x + y * m_data.Stride / 4] = c.ToArgb(); m_r[x, y] = (UInt16)(Math.Max(0.0, Math.Min(1.0, for48.R)) * ((double)UInt16.MaxValue)); m_g[x, y] = (UInt16)(Math.Max(0.0, Math.Min(1.0, for48.G)) * ((double)UInt16.MaxValue)); m_b[x, y] = (UInt16)(Math.Max(0.0, Math.Min(1.0, for48.B)) * ((double)UInt16.MaxValue)); }
public ColorD(double A, ColorD color) { m_R = color.R; m_G = color.G; m_B = color.B; m_A = A; }
public static ColorYUV FromColorD(ColorD from) { return new ColorYUV(from.A, 0.299 * from.R + 0.587 * from.G + 0.114 * from.B, -0.14713 * from.R - 0.28886 * from.G + 0.436 * from.B, 0.615 * from.R - 0.51499 * from.G - 0.10001 * from.B); }
public static ColorCMYK FromColorD(ColorD from) { double c = 1.0 - from.R; double m = 1.0 - from.G; double y = 1.0 - from.B; double k = (double)Math.Min(c, Math.Min(m, y)); if (k == 1.0) { return new ColorCMYK(from.A, 0, 0, 0, 1); } else { return new ColorCMYK(from.A, (c - k) / (1 - k), (m - k) / (1 - k), (y - k) / (1 - k), k); } }
static PointD ColorToXY(ColorD color) { PointD ptR = new PointD(1.0, 0.0); PointD ptG = new PointD(0.0, 1.0); PointD ptB = new PointD(0.0, 0.0); double r = color.R > 0.04045 ? Math.Pow((color.R + 0.055) / 1.055, 2.4000000953674316) : color.R / 12.92; double g = color.G > 0.04045 ? Math.Pow((color.G + 0.055) / 1.055, 2.4000000953674316) : color.G / 12.92; double b = color.B > 0.04045 ? Math.Pow((color.B + 0.055) / 1.055, 2.4000000953674316) : color.B / 12.92; double x = r * 0.664511 + g * 0.154324 + b * 0.162028; double y = r * 0.283881 + g * 0.668433 + b * 0.047685; double z = r * 0.000088 + g * 0.0723 + b * 0.986039; PointD xy = new PointD(x / (x + y + z), y / (x + y + z)); if (double.IsNaN(xy.X)) { xy.X = 0.0; } if (double.IsNaN(xy.Y)) { xy.Y = 0.0; } if (!IsInReach(xy, ptR, ptG, ptB)) { PointD pAB = PointD.ClosestPoint(ptR, ptG, xy); PointD pAC = PointD.ClosestPoint(ptB, ptR, xy); PointD pBC = PointD.ClosestPoint(ptG, ptB, xy); double dAB = PointD.Distance(xy, pAB); double dAC = PointD.Distance(xy, pAC); double dBC = PointD.Distance(xy, pBC); double lowest = dAB; PointD closestPoint = pAB; if (dAC < lowest) { lowest = dAC; closestPoint = pAC; } if (dBC < lowest) { lowest = dBC; closestPoint = pBC; } xy.X = closestPoint.X; xy.Y = closestPoint.Y; } return new PointD(xy.X, xy.Y); }
public static ColorXY FromColorD(ColorD from) { PointD pt = ColorToXY(from); return new ColorXY(from.A, pt.X, pt.Y); }
public static ColorHSL FromColorD(ColorD from) { double h = 0, s = 0, l = 0; double max = Math.Max(from.R, Math.Max(from.G, from.B)); double min = Math.Min(from.R, Math.Min(from.G, from.B)); if (max == min) { h = 0; } else if (max == from.R && from.G >= from.B) { h = 60.0 * (from.G - from.B) / (max - min); } else if (max == from.R && from.G < from.B) { h = 60.0 * (from.G - from.B) / (max - min) + 360.0; } else if (max == from.G) { h = 60.0 * (from.B - from.R) / (max - min) + 120.0; } else if (max == from.B) { h = 60.0 * (from.R - from.G) / (max - min) + 240.0; } l = (max + min) / 2.0; if (l == 0 || max == min) { s = 0; } else if (0 < l && l <= 0.5) { s = (max - min) / (max + min); } else if (l > 0.5) { s = (max - min) / (2 - (max + min)); } return new ColorHSL(from.A, h, s, l); }
public static ColorHSB FromColorD(ColorD from) { double max = Math.Max(from.R, Math.Max(from.G, from.B)); double min = Math.Min(from.R, Math.Min(from.G, from.B)); double h = 0.0; if (max == from.R && from.G >= from.B) { h = 60 * (from.G - from.B) / (max - min); } else if (max == from.R && from.G < from.B) { h = 60 * (from.G - from.B) / (max - min) + 360; } else if (max == from.G) { h = 60 * (from.B - from.R) / (max - min) + 120; } else if (max == from.B) { h = 60 * (from.R - from.G) / (max - min) + 240; } double s = (max == 0) ? 0.0 : (1.0 - (min / max)); return new ColorHSB(from.A, h, s, (double)max); }
public ColorD AlphaBlend(ColorD back) { return new ColorD(back.A, m_R * (m_A) + back.R * (1.0 - m_A), m_G * (m_A) + back.G * (1.0 - m_A), m_B * (m_A) + back.B * (1.0 - m_A)); }
public abstract void Add(ColorD c);