Java HSL Color Convert hsl2rgb(double h, double s, double l)

Here you can find the source of hsl2rgb(double h, double s, double l)

Description

hslrgb

License

Open Source License

Declaration

public static int[] hsl2rgb(double h, double s, double l) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static int[] hsl2rgb(double h, double s, double l) {
        //h *= 360.0;

        double r, g, b;

        if (s <= 0) {
            r = g = b = l;/*w ww .  j ava2 s.c o m*/
        } 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);
            b = hue2rgb(p, q, h - 1 / 3.0);
        }

        return new int[] { (int) Math.round(r * 255), (int) Math.round(g * 255), (int) Math.round(b * 255) };
    }

    protected static double hue2rgb(double p, double q, double t) {
        if (t < 0)
            t += 1;
        if (t > 1)
            t -= 1;
        if (t < 1 / 6.0)
            return p + (q - p) * 6 * t;
        if (t < 1 / 2.0)
            return q;
        if (t < 2 / 3.0)
            return p + (q - p) * (2 / 3.0 - t) * 6;
        return p;
    }
}

Related

  1. findHue(Color color)
  2. hsl2hex(int[] hsl)
  3. hsl2rgb(float h, float s, float l)
  4. hsl2rgb(int[] hsl)
  5. hsla_hue(double h, double m1, double m2)
  6. hslToHsb(float[] inputHsl)