Java Utililty Methods HSL Color Convert

List of utility methods to do HSL Color Convert

Description

The list of methods to do HSL Color Convert are organized into topic(s).

Method

floatfindHue(Color color)
Finds the closest hue possible to given color.
float[] hsbvals = new float[3];
Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), hsbvals);
return hsbvals[0];
Stringhsl2hex(int[] hsl)
hslhex
return rgb2hex(hsl2rgb(hsl));
int[]hsl2rgb(double h, double s, double l)
hslrgb
double r, g, b;
if (s <= 0) {
    r = g = b = l;
} else {
    double q = l < 0.5 ? l * (1 + s) : l + s - l * s;
    double p = 2 * l - q;
    r = hue2rgb(p, q, h + 1 / 3.0);
    g = hue2rgb(p, q, h);
...
int[]hsl2rgb(float h, float s, float l)
hslrgb
float c = (1 - Math.abs(2 * l - 1)) * s;
float x = c * (1 - Math.abs((h / 60) % 2 - 1));
float m = l - c / 2;
float r1 = 0, g1 = 0, b1 = 0;
if (h < 60) {
    r1 = c;
    g1 = x;
    b1 = 0;
...
int[]hsl2rgb(int[] hsl)
hslrgb
double h = hsl[0] / 360d;
double s = hsl[1] / 100d;
double l = hsl[2] / 100d;
double r = 0d;
double g = 0d;
double b;
if (s > 0d) {
    if (h >= 1d) {
...
doublehsla_hue(double h, double m1, double m2)
hslhue
h = h < 0 ? h + 1 : (h > 1 ? h - 1 : h);
if (h * 6 < 1) {
    return m1 + (m2 - m1) * h * 6;
} else if (h * 2 < 1) {
    return m2;
} else if (h * 3 < 2) {
    return m1 + (m2 - m1) * (2F / 3 - h) * 6;
} else {
...
float[]hslToHsb(float[] inputHsl)
Convert a color in HSL color space to one in HSB color space.
float hHsl = inputHsl[H];
float sHsl = inputHsl[S];
float lHsl = inputHsl[L];
float hHsb = hHsl;
float bHsb = (2 * lHsl + sHsl * (1 - Math.abs(2 * lHsl - 1))) / 2;
float sHsb = 2 * (bHsb - lHsl) / bHsb;
float[] hsb = { hHsb, sHsb, bHsb };
return hsb;
...
int[]HSLtoRGB(double h, double s, double l)
Converts HSL to RGB.
int r;
int g;
int b;
double var1;
double var2;
if (s == 0) {
    r = (int) (l * 255);
    g = (int) (l * 255);
...
double[]hslToRgb(double h, double s, double l)
hsl To Rgb
double r;
double g;
double b;
if (s == 0) {
    r = l;
    g = l;
    b = l;
} else {
...
byte[]hslToRgb(double hue, double sat, double lum)
hsl To Rgb
double r, g, b;
if (sat == 0d) {
    r = g = b = lum; 
} else {
    final double q = lum < 0.5d ? lum * (1d + sat) : lum + sat - lum * sat;
    final double p = 2d * lum - q;
    r = hue2rgb(p, q, hue + 1d / 3d);
    g = hue2rgb(p, q, hue);
...