Class HSLColorUtil


  • public class HSLColorUtil
    extends java.lang.Object
    Utilities for using Hue, Saturation, Luminance (HSL) colors and converting to/from standard Color objects.
    Author:
    Kevin Menningen
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int HUE_INDEX
      A convenience repeat of the index for the hue value in hue, saturation and luminance array return values.
      static int LUMINANCE_INDEX
      A convenience repeat of the index for the luminance value in hue, saturation and luminance array return values.
      static int SATURATION_INDEX
      A convenience repeat of the index for the saturation value in hue, saturation and luminance array return values.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.awt.Color convertHSLtoRGB​(float hue, float saturation, float luminance)
      Convert a hue, saturation and luminance color value to the standard AWT Color object.
      static float[] convertRGBtoHSL​(java.awt.Color inColor)
      Convert a standard AWT color to hue, saturation and luminance.
      static java.awt.Color getLighterColor​(float[] hslColor, float amount)
      Make a dark color lighter (more luminance) by a specified amount.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • HUE_INDEX

        public static final int HUE_INDEX
        A convenience repeat of the index for the hue value in hue, saturation and luminance array return values.
        See Also:
        Constant Field Values
      • SATURATION_INDEX

        public static final int SATURATION_INDEX
        A convenience repeat of the index for the saturation value in hue, saturation and luminance array return values.
        See Also:
        Constant Field Values
      • LUMINANCE_INDEX

        public static final int LUMINANCE_INDEX
        A convenience repeat of the index for the luminance value in hue, saturation and luminance array return values.
        See Also:
        Constant Field Values
    • Method Detail

      • convertRGBtoHSL

        public static float[] convertRGBtoHSL​(java.awt.Color inColor)
        Convert a standard AWT color to hue, saturation and luminance. Hue varies from 0 to 360, saturation varies from 0 to 1, and luminance varies from 0 to 1.
        Parameters:
        inColor - Color to convert
        Returns:
        An array of 3 floats containing hue, saturation and luminance. The array indices can be obtained from HSLColorSpace.HUE_INDEX, HSLColorSpace.LUMINANCE_INDEX and HSLColorSpace.SATURATION_INDEX.
      • convertHSLtoRGB

        public static java.awt.Color convertHSLtoRGB​(float hue,
                                                     float saturation,
                                                     float luminance)
        Convert a hue, saturation and luminance color value to the standard AWT Color object.
        Parameters:
        hue - The hue of the color from 0.0 to 360.0
        saturation - The saturation of the color from 0.0 to 1.0
        luminance - The luminance (brightness) of the color from 0.0 to 1.0
        Returns:
        A Color object closely matching the hue, saturation and luminance parameters.
      • getLighterColor

        public static java.awt.Color getLighterColor​(float[] hslColor,
                                                     float amount)
        Make a dark color lighter (more luminance) by a specified amount.
        Parameters:
        hslColor - The color to begin with.
        amount - The amount to adjust luminance (positive for lighter, negative for darker).
        Returns:
        The adjusted color.