Class Cam16


  • public final class Cam16
    extends java.lang.Object
    CAM16, a color appearance model. Colors are not just defined by their hex code, but rather, a hex code and viewing conditions.

    CAM16 instances also have coordinates in the CAM16-UCS space, called J*, a*, b*, or jstar, astar, bstar in code. CAM16-UCS is included in the CAM16 specification, and should be used when measuring distances between colors.

    In traditional color spaces, a color can be identified solely by the observer's measurement of the color. Color appearance models such as CAM16 also use information about the environment where the color was observed, known as the viewing conditions.

    For example, white under the traditional assumption of a midday sun white point is accurately measured as a slightly chromatic blue by CAM16. (roughly, hue 203, chroma 3, lightness 100)

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private double astar  
      private double bstar  
      (package private) static double[][] CAM16RGB_TO_XYZ  
      private double chroma  
      private double hue  
      private double j  
      private double jstar  
      private double m  
      private double q  
      private double s  
      private double[] tempArray  
      (package private) static double[][] XYZ_TO_CAM16RGB  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private Cam16​(double hue, double chroma, double j, double q, double m, double s, double jstar, double astar, double bstar)
      All of the CAM16 dimensions can be calculated from 3 of the dimensions, in the following combinations: - {j or q} and {c, m, or s} and hue - jstar, astar, bstar Prefer using a static method that constructs from 3 of those dimensions.
    • Field Detail

      • XYZ_TO_CAM16RGB

        static final double[][] XYZ_TO_CAM16RGB
      • CAM16RGB_TO_XYZ

        static final double[][] CAM16RGB_TO_XYZ
      • hue

        private final double hue
      • chroma

        private final double chroma
      • j

        private final double j
      • q

        private final double q
      • m

        private final double m
      • s

        private final double s
      • jstar

        private final double jstar
      • astar

        private final double astar
      • bstar

        private final double bstar
      • tempArray

        private final double[] tempArray
    • Constructor Detail

      • Cam16

        private Cam16​(double hue,
                      double chroma,
                      double j,
                      double q,
                      double m,
                      double s,
                      double jstar,
                      double astar,
                      double bstar)
        All of the CAM16 dimensions can be calculated from 3 of the dimensions, in the following combinations: - {j or q} and {c, m, or s} and hue - jstar, astar, bstar Prefer using a static method that constructs from 3 of those dimensions. This constructor is intended for those methods to use to return all possible dimensions.
        Parameters:
        hue - for example, red, orange, yellow, green, etc.
        chroma - informally, colorfulness / color intensity. like saturation in HSL, except perceptually accurate.
        j - lightness
        q - brightness; ratio of lightness to white point's lightness
        m - colorfulness
        s - saturation; ratio of chroma to white point's chroma
        jstar - CAM16-UCS J coordinate
        astar - CAM16-UCS a coordinate
        bstar - CAM16-UCS b coordinate
    • Method Detail

      • distance

        public double distance​(Cam16 other)
        CAM16 instances also have coordinates in the CAM16-UCS space, called J*, a*, b*, or jstar, astar, bstar in code. CAM16-UCS is included in the CAM16 specification, and is used to measure distances between colors.
      • getHue

        public double getHue()
        Hue in CAM16
      • getChroma

        public double getChroma()
        Chroma in CAM16
      • getJ

        public double getJ()
        Lightness in CAM16
      • getQ

        public double getQ()
        Brightness in CAM16.

        Prefer lightness, brightness is an absolute quantity. For example, a sheet of white paper is much brighter viewed in sunlight than in indoor light, but it is the lightest object under any lighting.

      • getM

        public double getM()
        Colorfulness in CAM16.

        Prefer chroma, colorfulness is an absolute quantity. For example, a yellow toy car is much more colorful outside than inside, but it has the same chroma in both environments.

      • getS

        public double getS()
        Saturation in CAM16.

        Colorfulness in proportion to brightness. Prefer chroma, saturation measures colorfulness relative to the color's own brightness, where chroma is colorfulness relative to white.

      • getJstar

        public double getJstar()
        Lightness coordinate in CAM16-UCS
      • getAstar

        public double getAstar()
        a* coordinate in CAM16-UCS
      • getBstar

        public double getBstar()
        b* coordinate in CAM16-UCS
      • fromInt

        public static Cam16 fromInt​(int argb)
        Create a CAM16 color from a color, assuming the color was viewed in default viewing conditions.
        Parameters:
        argb - ARGB representation of a color.
      • fromIntInViewingConditions

        static Cam16 fromIntInViewingConditions​(int argb,
                                                ViewingConditions viewingConditions)
        Create a CAM16 color from a color in defined viewing conditions.
        Parameters:
        argb - ARGB representation of a color.
        viewingConditions - Information about the environment where the color was observed.
      • fromXyzInViewingConditions

        static Cam16 fromXyzInViewingConditions​(double x,
                                                double y,
                                                double z,
                                                ViewingConditions viewingConditions)
      • fromJch

        static Cam16 fromJch​(double j,
                             double c,
                             double h)
        Parameters:
        j - CAM16 lightness
        c - CAM16 chroma
        h - CAM16 hue
      • fromJchInViewingConditions

        private static Cam16 fromJchInViewingConditions​(double j,
                                                        double c,
                                                        double h,
                                                        ViewingConditions viewingConditions)
        Parameters:
        j - CAM16 lightness
        c - CAM16 chroma
        h - CAM16 hue
        viewingConditions - Information about the environment where the color was observed.
      • fromUcs

        public static Cam16 fromUcs​(double jstar,
                                    double astar,
                                    double bstar)
        Create a CAM16 color from CAM16-UCS coordinates.
        Parameters:
        jstar - CAM16-UCS lightness.
        astar - CAM16-UCS a dimension. Like a* in L*a*b*, it is a Cartesian coordinate on the Y axis.
        bstar - CAM16-UCS b dimension. Like a* in L*a*b*, it is a Cartesian coordinate on the X axis.
      • fromUcsInViewingConditions

        public static Cam16 fromUcsInViewingConditions​(double jstar,
                                                       double astar,
                                                       double bstar,
                                                       ViewingConditions viewingConditions)
        Create a CAM16 color from CAM16-UCS coordinates in defined viewing conditions.
        Parameters:
        jstar - CAM16-UCS lightness.
        astar - CAM16-UCS a dimension. Like a* in L*a*b*, it is a Cartesian coordinate on the Y axis.
        bstar - CAM16-UCS b dimension. Like a* in L*a*b*, it is a Cartesian coordinate on the X axis.
        viewingConditions - Information about the environment where the color was observed.
      • toInt

        public int toInt()
        ARGB representation of the color. Assumes the color was viewed in default viewing conditions, which are near-identical to the default viewing conditions for sRGB.
      • viewed

        int viewed​(ViewingConditions viewingConditions)
        ARGB representation of the color, in defined viewing conditions.
        Parameters:
        viewingConditions - Information about the environment where the color will be viewed.
        Returns:
        ARGB representation of color
      • xyzInViewingConditions

        double[] xyzInViewingConditions​(ViewingConditions viewingConditions,
                                        double[] returnArray)