internal static IRgb ToColor(IHsv item) { var range = Convert.ToInt32(Math.Floor(item.H / 60.0)) % 6; var f = item.H / 60.0 - Math.Floor(item.H / 60.0); var v = item.V * 255.0; var p = v * (1 - item.S); var q = v * (1 - f * item.S); var t = v * (1 - (1 - f) * item.S); switch (range) { case 0: return(NewRgb(v, t, p)); case 1: return(NewRgb(q, v, p)); case 2: return(NewRgb(p, v, t)); case 3: return(NewRgb(p, q, v)); case 4: return(NewRgb(t, p, v)); } return(NewRgb(v, p, q)); }
internal static IRgb ToColor(IHsv item) { var range = Convert.ToInt32(Math.Floor(item.H / 60.0)) % 6; var f = item.H / 60.0 - Math.Floor(item.H / 60.0); var v = item.V * 255.0; var p = v * (1 - item.S); var q = v * (1 - f * item.S); var t = v * (1 - (1 - f) * item.S); switch (range) { case 0: return NewRgb(v, t, p); case 1: return NewRgb(q, v, p); case 2: return NewRgb(p, v, t); case 3: return NewRgb(p, q, v); case 4: return NewRgb(t, p, v); } return NewRgb(v, p, q); }
internal static void ToColorSpace(IRgb color, IHsv item) { var max = Max(color.R, Max(color.G, color.B)); var min = Min(color.R, Min(color.G, color.B)); if (Math.Abs(max - min) <= float.Epsilon) { item.H = 0d; } else { double diff = max - min; if (Math.Abs(max - color.R) <= float.Epsilon) { item.H = 60d * (color.G - color.B) / diff; } else if (Math.Abs(max - color.G) <= float.Epsilon) { item.H = 60d * (color.B - color.R) / diff + 120d; } else { item.H = 60d * (color.R - color.G) / diff + 240d; } if (item.H < 0d) { item.H += 360d; } } item.S = (max <= 0) ? 0 : 1d - (1d * min / max); item.V = max / 255d; }
protected static void ExpectedValuesForKnownColor(IColorSpace knownColor, IHsv expectedColor) { var target = knownColor.To <Hsv>(); Assert.IsTrue(CloseEnough(expectedColor.H, target.H), "(H)" + expectedColor.H + " != " + target.H); Assert.IsTrue(CloseEnough(expectedColor.S, target.S), "(S)" + expectedColor.S + " != " + target.S); Assert.IsTrue(CloseEnough(expectedColor.V, target.V), "(V)" + expectedColor.V + " != " + target.V); }
protected static void ExpectedValuesForKnownColor(IColorSpace knownColor, IHsv expectedColor) { var target = knownColor.To <Hsv>(); Assert.AreEqual(expectedColor.H, target.H, 1.8, "(H)" + expectedColor.H + " != " + target.H); Assert.AreEqual(expectedColor.S, target.S, 0.005, "(S)" + expectedColor.S + " != " + target.S); Assert.AreEqual(expectedColor.V, target.V, 0.005, "(V)" + expectedColor.V + " != " + target.V); }
internal static void ToColorSpace(IRgb color, IHsv item) { var max = Max(color.R, Max(color.G, color.B)); var min = Min(color.R, Min(color.G, color.B)); item.H = Color.FromArgb(255, (int)color.R, (int)color.G, (int)color.B).GetHue(); item.S = (max <= 0) ? 0 : 1d - (1d * min / max); item.V = max / 255d; }
internal static void ToColorSpace(IRgb color, IHsv item) { var result = ToColorSpace(color.R / 255d, color.G / 255d, color.B / 255d); item.H = result.H; item.S = result.S; item.V = result.V; //item.H = Color.FromArgb(255, (int)color.R, (int)color.G, (int)color.B).GetHue(); //item.S = (max <= 0) ? 0 : 1d - (1d * min / max); //item.V = max / 255d; }
internal static void ToColorSpace(IRgb color, IHsv item) { try { var max = Max(color.R, Max(color.G, color.B)); var min = Min(color.R, Min(color.G, color.B)); item.H = Color.FromArgb(255, (int)color.R, (int)color.G, (int)color.B).GetHue(); item.S = max <= 0 ? 0 : 1d - 1d * min / max; item.V = max / 255d; } catch (Exception) { var max = 255; var min = 0; item.H = 0; item.S = max <= 0 ? 0 : 1d - 1d * min / max; item.V = max / 255d; } }
protected static void ExpectedValuesForKnownColor(IColorSpace knownColor, IHsv expectedColor) { var target = knownColor.To<Hsv>(); Assert.IsTrue(CloseEnough(expectedColor.H,target.H),"(H)" + expectedColor.H + " != " + target.H); Assert.IsTrue(CloseEnough(expectedColor.S,target.S),"(S)" + expectedColor.S + " != " + target.S); Assert.IsTrue(CloseEnough(expectedColor.V,target.V),"(V)" + expectedColor.V + " != " + target.V); }
public CmyColor(IHsv hsv) { Initialize(hsv.ToRgb()); }
public HunterLabColor(IHsv hsv) { Initialize(hsv.ToRgb()); }
public HsvColor(IHsv hsv) { Ordinals = hsv.Ordinals; }