Class ColorUtils


  • public class ColorUtils
    extends java.lang.Object
    Color science utilities.

    Utility methods for color science constants and color space conversions that aren't HCT or CAM16.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) static double[][] SRGB_TO_XYZ  
      (package private) static double[] WHITE_POINT_D65  
      (package private) static double[][] XYZ_TO_SRGB  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private ColorUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int alphaFromArgb​(int argb)
      Returns the alpha component of a color in ARGB format.
      static int argbFromLab​(double l, double a, double b)
      Converts a color represented in Lab color space into an ARGB integer.
      static int argbFromLinrgb​(double[] linrgb)
      Converts a color from linear RGB components to ARGB format.
      static int argbFromLstar​(double lstar)
      Converts an L* value to an ARGB representation.
      static int argbFromRgb​(int red, int green, int blue)
      Converts a color from RGB components to ARGB format.
      static int argbFromXyz​(double x, double y, double z)
      Converts a color from ARGB to XYZ.
      static int blueFromArgb​(int argb)
      Returns the blue component of a color in ARGB format.
      static int delinearized​(double rgbComponent)
      Delinearizes an RGB component.
      static int greenFromArgb​(int argb)
      Returns the green component of a color in ARGB format.
      static boolean isOpaque​(int argb)
      Returns whether a color in ARGB format is opaque.
      (package private) static double labF​(double t)  
      static double[] labFromArgb​(int argb)
      Converts a color from ARGB representation to L*a*b* representation.
      (package private) static double labInvf​(double ft)  
      static double linearized​(int rgbComponent)
      Linearizes an RGB component.
      static double lstarFromArgb​(int argb)
      Computes the L* value of a color in ARGB representation.
      static double lstarFromY​(double y)
      Converts a Y value to an L* value.
      static int redFromArgb​(int argb)
      Returns the red component of a color in ARGB format.
      static double[] whitePointD65()
      Returns the standard white point; white on a sunny day.
      static double[] xyzFromArgb​(int argb)
      Converts a color from XYZ to ARGB.
      static double yFromLstar​(double lstar)
      Converts an L* value to a Y value.
      • Methods inherited from class java.lang.Object

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

      • SRGB_TO_XYZ

        static final double[][] SRGB_TO_XYZ
      • XYZ_TO_SRGB

        static final double[][] XYZ_TO_SRGB
      • WHITE_POINT_D65

        static final double[] WHITE_POINT_D65
    • Constructor Detail

      • ColorUtils

        private ColorUtils()
    • Method Detail

      • argbFromRgb

        public static int argbFromRgb​(int red,
                                      int green,
                                      int blue)
        Converts a color from RGB components to ARGB format.
      • argbFromLinrgb

        public static int argbFromLinrgb​(double[] linrgb)
        Converts a color from linear RGB components to ARGB format.
      • alphaFromArgb

        public static int alphaFromArgb​(int argb)
        Returns the alpha component of a color in ARGB format.
      • redFromArgb

        public static int redFromArgb​(int argb)
        Returns the red component of a color in ARGB format.
      • greenFromArgb

        public static int greenFromArgb​(int argb)
        Returns the green component of a color in ARGB format.
      • blueFromArgb

        public static int blueFromArgb​(int argb)
        Returns the blue component of a color in ARGB format.
      • isOpaque

        public static boolean isOpaque​(int argb)
        Returns whether a color in ARGB format is opaque.
      • argbFromXyz

        public static int argbFromXyz​(double x,
                                      double y,
                                      double z)
        Converts a color from ARGB to XYZ.
      • xyzFromArgb

        public static double[] xyzFromArgb​(int argb)
        Converts a color from XYZ to ARGB.
      • argbFromLab

        public static int argbFromLab​(double l,
                                      double a,
                                      double b)
        Converts a color represented in Lab color space into an ARGB integer.
      • labFromArgb

        public static double[] labFromArgb​(int argb)
        Converts a color from ARGB representation to L*a*b* representation.
        Parameters:
        argb - the ARGB representation of a color
        Returns:
        a Lab object representing the color
      • argbFromLstar

        public static int argbFromLstar​(double lstar)
        Converts an L* value to an ARGB representation.
        Parameters:
        lstar - L* in L*a*b*
        Returns:
        ARGB representation of grayscale color with lightness matching L*
      • lstarFromArgb

        public static double lstarFromArgb​(int argb)
        Computes the L* value of a color in ARGB representation.
        Parameters:
        argb - ARGB representation of a color
        Returns:
        L*, from L*a*b*, coordinate of the color
      • yFromLstar

        public static double yFromLstar​(double lstar)
        Converts an L* value to a Y value.

        L* in L*a*b* and Y in XYZ measure the same quantity, luminance.

        L* measures perceptual luminance, a linear scale. Y in XYZ measures relative luminance, a logarithmic scale.

        Parameters:
        lstar - L* in L*a*b*
        Returns:
        Y in XYZ
      • lstarFromY

        public static double lstarFromY​(double y)
        Converts a Y value to an L* value.

        L* in L*a*b* and Y in XYZ measure the same quantity, luminance.

        L* measures perceptual luminance, a linear scale. Y in XYZ measures relative luminance, a logarithmic scale.

        Parameters:
        y - Y in XYZ
        Returns:
        L* in L*a*b*
      • linearized

        public static double linearized​(int rgbComponent)
        Linearizes an RGB component.
        Parameters:
        rgbComponent - 0 <= rgb_component <= 255, represents R/G/B channel
        Returns:
        0.0 <= output <= 100.0, color channel converted to linear RGB space
      • delinearized

        public static int delinearized​(double rgbComponent)
        Delinearizes an RGB component.
        Parameters:
        rgbComponent - 0.0 <= rgb_component <= 100.0, represents linear R/G/B channel
        Returns:
        0 <= output <= 255, color channel converted to regular RGB space
      • whitePointD65

        public static double[] whitePointD65()
        Returns the standard white point; white on a sunny day.
        Returns:
        The white point
      • labF

        static double labF​(double t)
      • labInvf

        static double labInvf​(double ft)