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

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

Description

hsl To Rgb

License

Open Source License

Declaration

public static double[] hslToRgb(double h, double s, double l) 

Method Source Code

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

public class Main {
    public static double[] hslToRgb(double h, double s, double l) {
        // Adapted from http://stackoverflow.com/a/9493060
        double r;
        double g;
        double b;

        if (s == 0) {
            r = l;//w  w  w  .ja  va 2s.c o  m
            g = l;
            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.0 / 3);
            g = hue2Rgb(p, q, h);
            b = hue2Rgb(p, q, h - 1.0 / 3);
        }
        return new double[] { r, g, b };
    }

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

Related

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