List of utility methods to do HSL Color Convert
int | HSLtoRGB(float h, float s, float l) HS Lto RGB float m2 = (l <= 0.5f) ? (l * (s + 1)) : (l + s - l * s); float m1 = 2 * l - m2; int r = (int) (255 * HUEtoRGB(m1, m2, h + (1f / 3))); int g = (int) (255 * HUEtoRGB(m1, m2, h)); int b = (int) (255 * HUEtoRGB(m1, m2, h - (1f / 3))); return (((r << 8) | g) << 8) | b; |
float[] | HslToRgb(float h, float s, float l, float a) Hsl To Rgb float[] result = new float[4]; if (s == 0) { result[0] = l; result[1] = l; result[2] = l; result[3] = a; } else { float q = (l < 0.5f) ? (l * (1.0f + s)) : (l + s - (l * s)); ... |
int | HSLtoRGB(float hue, float sat, float lum) all in [0,1] ! float v; float red, green, blue; float m; float sv; int sextant; float fract, vsf, mid1, mid2; red = lum; green = lum; ... |
float[] | hslToRgb(float[] hsl) Converts an HSL color value to RGB. float r, g, b; float h, s, l; h = hsl[0]; s = hsl[1]; l = hsl[2]; if (s == 0) { r = g = b = l; } else { ... |
int | HSLtoRGB(float[] hsl) Converts from HSL color space to RGB color. float r, g, b, h, s, l; float temp1, temp2, tempr, tempg, tempb; h = hsl[0]; s = hsl[1]; l = hsl[2]; if (s == 0) { r = g = b = l; else { if (l < 0.5) temp2 = l * (1 + s); else temp2 = (l + s) - (l * s); temp1 = 2 * l - temp2; tempr = h + 1.0f / 3.0f; if (tempr > 1) tempr--; tempg = h; tempb = h - 1.0f / 3.0f; if (tempb < 0) tempb++; if (tempr < 1.0 / 6.0) r = temp1 + (temp2 - temp1) * 6.0f * tempr; else if (tempr < 0.5) r = temp2; else if (tempr < 2.0 / 3.0) r = temp1 + (temp2 - temp1) * ((2.0f / 3.0f) - tempr) * 6.0f; else r = temp1; if (tempg < 1.0 / 6.0) g = temp1 + (temp2 - temp1) * 6.0f * tempg; else if (tempg < 0.5) g = temp2; else if (tempg < 2.0 / 3.0) g = temp1 + (temp2 - temp1) * ((2.0f / 3.0f) - tempg) * 6.0f; else g = temp1; if (tempb < 1.0 / 6.0) b = temp1 + (temp2 - temp1) * 6.0f * tempb; else if (tempb < 0.5) b = temp2; else if (tempb < 2.0 / 3.0) b = temp1 + (temp2 - temp1) * ((2.0f / 3.0f) - tempb) * 6.0f; else b = temp1; int result = 0; result += ((int) (r * 255) & 0xFF) << 16; result += ((int) (g * 255) & 0xFF) << 8; result += ((int) (b * 255) & 0xFF); return result; |
float[] | hslToRGB(int h, float s, float l) hsl To RGB final int hue = normalizeHue(h); float saturation = s; if (saturation > 100) { saturation = 100; if (saturation < 0) { saturation = 0; float lightness = l; if (lightness > 100) { lightness = 100; if (lightness < 0) { lightness = 0; float m2; if (lightness <= 0.5) { m2 = lightness * (saturation + 1); } else { m2 = lightness + saturation - lightness * saturation; float m1 = lightness * 2 - m2; float r = hueToRGB(m1, m2, hue + ONE_THIRD); float g = hueToRGB(m1, m2, hue); float b = hueToRGB(m1, m2, hue - ONE_THIRD); return new float[] { r, g, b }; |
float | hueFromColor(Color c) hue From Color double r = c.getRed() / 255.; double g = c.getGreen() / 255.; double b = c.getBlue() / 255.; double min, max; min = Math.min(r, Math.min(g, b)); max = Math.max(r, Math.max(g, b)); double v = max; double h = 0; ... |