Java HSL Color Convert hslToRgb(double hue, double sat, double lum)

Here you can find the source of hslToRgb(double hue, double sat, double lum)

Description

hsl To Rgb

License

Open Source License

Declaration

private static byte[] hslToRgb(double hue, double sat, double lum) 

Method Source Code

//package com.java2s;

public class Main {
    private static byte[] hslToRgb(double hue, double sat, double lum) {
        double r, g, b;
        if (sat == 0d) {
            r = g = b = lum; // gray scale
        } else {//from  www  . ja va 2 s . com
            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);
            b = hue2rgb(p, q, hue - 1d / 3d);
        }
        final byte red = (byte) (r * 255d);
        final byte green = (byte) (g * 255d);
        final byte blue = (byte) (b * 255d);
        return new byte[] { red, green, blue };
    }

    private static double hue2rgb(double p, double q, double t) {
        if (t < 0d)
            t += 1d;
        if (t > 1d)
            t -= 1d;
        if (t < 1d / 6d)
            return p + (q - p) * 6d * t;
        if (t < 1d / 2d)
            return q;
        if (t < 2d / 3d)
            return p + (q - p) * (2d / 3d - t) * 6d;
        return p;
    }
}

Related

  1. hsl2rgb(int[] hsl)
  2. hsla_hue(double h, double m1, double m2)
  3. hslToHsb(float[] inputHsl)
  4. hslToRgb(double h, double s, double l)
  5. HSLtoRGB(double h, double s, double l)
  6. HSLtoRGB(float h, float s, float l)
  7. HslToRgb(float h, float s, float l, float a)
  8. HSLtoRGB(float hue, float sat, float lum)
  9. hslToRgb(float[] hsl)