Java RGB Color Create RGBAFromHSLA(float h, float s, float l, float a)

Here you can find the source of RGBAFromHSLA(float h, float s, float l, float a)

Description

Converts SAC HSLA (or HSL) LexicalUnit value to RGBA

License

Open Source License

Parameter

Parameter Description
value a parameter

Declaration

public static String RGBAFromHSLA(float h, float s, float l, float a) 

Method Source Code

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

public class Main {
    /**/*  w ww .java 2 s.  c  o  m*/
     * Converts SAC HSLA (or HSL) LexicalUnit value to RGBA
     * @param value
     * @return
     */
    public static String RGBAFromHSLA(float h, float s, float l, float a) {
        int r, g, b;
        float m2;
        if (l <= 0.5)
            m2 = l * (s + 1);
        else
            m2 = l + s - l * s;

        float m1 = l * 2 - m2;
        r = (int) (HUEToRGB(m1, m2, h + 1 / 3F) * 255);
        g = (int) (HUEToRGB(m1, m2, h) * 255);
        b = (int) (HUEToRGB(m1, m2, h - 1 / 3F) * 255);

        return String.format("rgba(%s, %s, %s, %s)", r, g, b, a);

    }

    private static float HUEToRGB(float m1, float m2, float h) {
        if (h < 0)
            h++;
        if (h > 1)
            h--;
        if (h * 6 < 1)
            return m1 + (m2 - m1) * h * 6;
        if (h * 2 < 1)
            return m2;
        if (h * 3 < 2)
            return m1 + (m2 - m1) * (2 / 3F - h) * 6;
        return m1;
    }
}

Related

  1. rgba(int red, int green, int blue)
  2. rgba_bilinear_filter(int rgb00, int rgb01, int rgb10, int rgb11, int u, int v)
  3. rgbaColour(int red, int green, int blue, int alpha)
  4. RGBAequals(float[] rgba1, float[] rgba2, float eps)
  5. RGBAFromHEX(String stringValue)
  6. rgbClamp(float c)
  7. rgbComponents(int argb)
  8. rgbDistance(int color1, int color2)
  9. rgbFromColorInt(int c)