public static DoubleColor Lighter( this DoubleColor c, double coff = 0.25 ) { AHSL hsl = ColorExt.ToAHSL(c); hsl.Luminance = MathEx.Lerp(hsl.Luminance, 1, coff); return(ColorExt.Double(hsl)); }
public static DoubleColor Double( this AHSL hsl ) { double h = hsl.HueDegree; double s = hsl.Saturation; double l = hsl.Luminance; double a = hsl.Alpha; DoubleColor ret; if (s == 0) { // achromatic color (gray scale) ret = new DoubleColor(a * 255.0, l * 255.0, l * 255.0, l * 255.0); } else { double q = (l < 0.5) ? (l * (1.0 + s)) : (l + s - (l * s)); double p = (2.0 * l) - q; double Hk = h / 360.0; double[] T = new double[3]; T[0] = Hk + (1.0 / 3.0); // Tr T[1] = Hk; // Tb T[2] = Hk - (1.0 / 3.0); // Tg for (int i = 0; i < 3; i++) { if (T[i] < 0) { T[i] += 1.0; } if (T[i] > 1) { T[i] -= 1.0; } if ((T[i] * 6) < 1) { T[i] = p + ((q - p) * 6.0 * T[i]); } else if ((T[i] * 2.0) < 1) // (1.0 / 6.0) <= T[i] && T[i] < 0.5 { T[i] = q; } else if ((T[i] * 3.0) < 2) // 0.5 <= T[i] && T[i] < (2.0/3.0) { T[i] = p + (q - p) * ((2.0 / 3.0) - T[i]) * 6.0; } else { T[i] = p; } } ret = new DoubleColor(a * 255.0, T[0] * 255.0, T[1] * 255.0, T[2] * 255.0); } // // this will preserve hue for gray colors, and saturation for black // ret.HueDegree = h; ret.Saturation = s; return(ret); }