// Given H,S,L in range of 0-1 // Returns a Color (RGB struct) in range of 0-255 public static ColorRGBBit HSL_To_RGB(double H, double S, double L) { double R, G, B; if (S == 0) //HSL from 0 to 1 { R = L * 255.0; //RGB results from 0 to 255 G = L * 255.0; B = L * 255.0; } else { double var_2 = (L < 0.5) ? L * (1 + S) : (L + S) - (S * L); double var_1 = 2 * L - var_2; R = 255 * Hue_2_RGB(var_1, var_2, H + (1.0 / 3.0)); G = 255 * Hue_2_RGB(var_1, var_2, H); B = 255 * Hue_2_RGB(var_1, var_2, H - (1.0 / 3.0)); } var rgb = new ColorRGBBit( Convert.ToByte(R), Convert.ToByte(G), Convert.ToByte(B) ); return(rgb); }
// Given H,S,L in range of 0-1 // Returns a Color (RGB struct) in range of 0-255 public static ColorRGBBit HSL_To_RGB(double H, double S, double L) { double R, G, B; if (S == 0) //HSL from 0 to 1 { R = L*255.0; //RGB results from 0 to 255 G = L*255.0; B = L*255.0; } else { double var_2 = (L < 0.5) ? L*(1 + S) : (L + S) - (S*L); double var_1 = 2*L - var_2; R = 255*Hue_2_RGB(var_1, var_2, H + (1.0/3.0)); G = 255*Hue_2_RGB(var_1, var_2, H); B = 255*Hue_2_RGB(var_1, var_2, H - (1.0/3.0)); } var rgb = new ColorRGBBit( Convert.ToByte(R), Convert.ToByte(G), Convert.ToByte(B) ); return rgb; }