Class ColorUtilities


  • public class ColorUtilities
    extends java.lang.Object

    ColorUtilities contains a set of tools to perform common color operations easily.

    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private ColorUtilities()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.awt.Color HSLtoRGB​(float h, float s, float l)
      Returns the RGB equivalent of a given HSL (Hue/Saturation/Luminance) color.
      static int[] HSLtoRGB​(float h, float s, float l, int[] rgb)
      Returns the RGB equivalent of a given HSL (Hue/Saturation/Luminance) color.
      private static float hue2RGB​(float v1, float v2, float vH)  
      static float[] RGBtoHSL​(int r, int g, int b)
      Returns the HSL (Hue/Saturation/Luminance) equivalent of a given RGB color.
      static float[] RGBtoHSL​(int r, int g, int b, float[] hsl)
      Returns the HSL (Hue/Saturation/Luminance) equivalent of a given RGB color.
      static float[] RGBtoHSL​(java.awt.Color color)
      Returns the HSL (Hue/Saturation/Luminance) equivalent of a given RGB color.
      static float[] RGBtoHSL​(java.awt.Color color, float[] hsl)
      Returns the HSL (Hue/Saturation/Luminance) equivalent of a given RGB color.
      • Methods inherited from class java.lang.Object

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

      • ColorUtilities

        private ColorUtilities()
    • Method Detail

      • RGBtoHSL

        public static float[] RGBtoHSL​(java.awt.Color color)

        Returns the HSL (Hue/Saturation/Luminance) equivalent of a given RGB color. All three HSL components are between 0.0 and 1.0.

        Parameters:
        color - the RGB color to convert
        Returns:
        a new array of 3 floats corresponding to the HSL components
      • RGBtoHSL

        public static float[] RGBtoHSL​(java.awt.Color color,
                                       float[] hsl)

        Returns the HSL (Hue/Saturation/Luminance) equivalent of a given RGB color. All three HSL components are between 0.0 and 1.0.

        Parameters:
        color - the RGB color to convert
        hsl - a pre-allocated array of floats; can be null
        Returns:
        hsl if non-null, a new array of 3 floats otherwise
        Throws:
        java.lang.IllegalArgumentException - if hsl has a length lower than 3
      • RGBtoHSL

        public static float[] RGBtoHSL​(int r,
                                       int g,
                                       int b)

        Returns the HSL (Hue/Saturation/Luminance) equivalent of a given RGB color. All three HSL components are between 0.0 and 1.0.

        Parameters:
        r - the red component, between 0 and 255
        g - the green component, between 0 and 255
        b - the blue component, between 0 and 255
        Returns:
        a new array of 3 floats corresponding to the HSL components
      • RGBtoHSL

        public static float[] RGBtoHSL​(int r,
                                       int g,
                                       int b,
                                       float[] hsl)

        Returns the HSL (Hue/Saturation/Luminance) equivalent of a given RGB color. All three HSL components are floats between 0.0 and 1.0.

        Parameters:
        r - the red component, between 0 and 255
        g - the green component, between 0 and 255
        b - the blue component, between 0 and 255
        hsl - a pre-allocated array of floats; can be null
        Returns:
        hsl if non-null, a new array of 3 floats otherwise
        Throws:
        java.lang.IllegalArgumentException - if hsl has a length lower than 3
      • HSLtoRGB

        public static java.awt.Color HSLtoRGB​(float h,
                                              float s,
                                              float l)

        Returns the RGB equivalent of a given HSL (Hue/Saturation/Luminance) color.

        Parameters:
        h - the hue component, between 0.0 and 1.0
        s - the saturation component, between 0.0 and 1.0
        l - the luminance component, between 0.0 and 1.0
        Returns:
        a new Color object equivalent to the HSL components
      • HSLtoRGB

        public static int[] HSLtoRGB​(float h,
                                     float s,
                                     float l,
                                     int[] rgb)

        Returns the RGB equivalent of a given HSL (Hue/Saturation/Luminance) color. All three RGB components are integers between 0 and 255.

        Parameters:
        h - the hue component, between 0.0 and 1.0
        s - the saturation component, between 0.0 and 1.0
        l - the luminance component, between 0.0 and 1.0
        rgb - a pre-allocated array of ints; can be null
        Returns:
        rgb if non-null, a new array of 3 ints otherwise
        Throws:
        java.lang.IllegalArgumentException - if rgb has a length lower than 3
      • hue2RGB

        private static float hue2RGB​(float v1,
                                     float v2,
                                     float vH)