Java HSL Color Convert hsl2rgb(int[] hsl)

Here you can find the source of hsl2rgb(int[] hsl)

Description

hslrgb

License

Apache License

Declaration

static int[] hsl2rgb(int[] hsl) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    static int[] hsl2rgb(int[] hsl) {
        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) {
                h = 0d;/*from  w  w w  .  j  ava 2  s . co  m*/
            }

            h = h * 6d;
            double f = h - Math.floor(h);
            double a = Math.round(l * 255d * (1d - s));
            b = Math.round(l * 255d * (1d - (s * f)));
            double c = Math.round(l * 255d * (1d - (s * (1d - f))));
            l = Math.round(l * 255d);

            switch ((int) Math.floor(h)) {
            case 0:
                r = l;
                g = c;
                b = a;
                break;
            case 1:
                r = b;
                g = l;
                b = a;
                break;
            case 2:
                r = a;
                g = l;
                b = c;
                break;
            case 3:
                r = a;
                g = b;
                b = l;
                break;
            case 4:
                r = c;
                g = a;
                b = l;
                break;
            case 5:
                r = l;
                g = a;
                break;
            }
            return new int[] { (int) Math.round(r), (int) Math.round(g), (int) Math.round(b) };
        }

        l = Math.round(l * 255d);
        return new int[] { (int) l, (int) l, (int) l };
    }
}

Related

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