Class HSLColor



  • public class HSLColor
    extends Object
    This class interfaces with colors in terms of Hue, Saturation and Luminance.

    This is copied from Rob Camick's class here:
    http://tips4java.wordpress.com/2009/07/05/hsl-color/

    See Also:
    HSL Color
    • Constructor Summary

      Constructors

      Constructor and Description
      HSLColor()
       
    • Method Summary

      Methods

      Modifier and Type Method and Description
      static float[] fromRGB(Color color, float[] dest)
      Convert a RGB Color to it corresponding HSL values.
      static int toRGB(float[] hsl)
      Convert HSL values to a RGB Color with a default alpha value of 1.
      static int toRGB(float[] hsl, float alpha)
      Convert HSL values to a RGB Color.
      static int toRGB(float h, float s, float l)
      Convert HSL values to a ARGB Color with a default alpha value of 1.
      static int toRGB(float h, float s, float l, float alpha)
      Convert HSL values to an ARGB Color.
    • Constructor Detail

      • HSLColor

        public HSLColor()
    • Method Detail

      • fromRGB

        public static float[] fromRGB(Color color,
                                      float[] dest)
        Convert a RGB Color to it corresponding HSL values.
        Parameters:
        color - the color to convert.
        dest - the optional array to store the result in.
        Returns:
        an array containing the 3 HSL values.
      • toRGB

        public static int toRGB(float[] hsl)
        Convert HSL values to a RGB Color with a default alpha value of 1.
        H (Hue) is specified as degrees in the range 0 - 1.
        S (Saturation) is specified as a percentage in the range 0 - 1.
        L (Luminance) is specified as a percentage in the range 0 - 1.
        Parameters:
        hsl - an array containing the 3 HSL values
        Returns:
        the ARGB value of this color
      • toRGB

        public static int toRGB(float[] hsl,
                                float alpha)
        Convert HSL values to a RGB Color.
        H (Hue) is specified as degrees in the range 0 - 1.
        S (Saturation) is specified as a percentage in the range 0 - 1.
        L (Luminance) is specified as a percentage in the range 0 - 1.
        Parameters:
        hsl - an array containing the 3 HSL values
        alpha - the alpha value between 0 - 1
        Returns:
        the ARGB value of this color
      • toRGB

        public static int toRGB(float h,
                                float s,
                                float l)
        Convert HSL values to a ARGB Color with a default alpha value of 1.
        Parameters:
        h - Hue is specified as degrees in the range 0 - 1.
        s - Saturation is specified as a percentage in the range 0 - 1.
        l - Luminance is specified as a percentage in the range 0 - 1.
        Returns:
        the ARGB value of this color
      • toRGB

        public static int toRGB(float h,
                                float s,
                                float l,
                                float alpha)
        Convert HSL values to an ARGB Color.
        Parameters:
        h - Hue is specified as degrees in the range 0 - 1.
        s - Saturation is specified as a percentage in the range 0 - 1.
        l - Luminance is specified as a percentage in the range 0 - 1.
        alpha - the alpha value between 0 - 1
        Returns:
        the ARGB value of this color