Class HctSolver
- java.lang.Object
-
- org.pushingpixels.ephemeral.chroma.hct.HctSolver
-
public class HctSolver extends java.lang.ObjectA class that solves the HCT equation.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static double[]CRITICAL_PLANES(package private) static double[][]LINRGB_FROM_SCALED_DISCOUNT(package private) static double[][]SCALED_DISCOUNT_FROM_LINRGB(package private) static double[]Y_FROM_LINRGB
-
Constructor Summary
Constructors Modifier Constructor Description privateHctSolver()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description (package private) static booleanareInCyclicOrder(double a, double b, double c)(package private) static double[]bisectToLimit(double y, double targetHue)Finds a color with the given Y and hue on the boundary of the cube.(package private) static double[][]bisectToSegment(double y, double targetHue)Finds the segment containing the desired color.(package private) static doublechromaticAdaptation(double component)(package private) static intcriticalPlaneAbove(double x)(package private) static intcriticalPlaneBelow(double x)(package private) static intfindResultByJ(double hueRadians, double chroma, double y)Finds a color with the given hue, chroma, and Y.(package private) static doublehueOf(double[] linrgb)Returns the hue of a linear RGB color in CAM16.(package private) static doubleintercept(double source, double mid, double target)Solves the lerp equation.(package private) static doubleinverseChromaticAdaptation(double adapted)(package private) static booleanisBounded(double x)(package private) static double[]lerpPoint(double[] source, double t, double[] target)(package private) static double[]midpoint(double[] a, double[] b)(package private) static double[]nthVertex(double y, int n)Returns the nth possible vertex of the polygonal intersection.(package private) static doublesanitizeRadians(double angle)Sanitizes a small enough angle in radians.(package private) static double[]setCoordinate(double[] source, double coordinate, double[] target, int axis)Intersects a segment with a plane.static Cam16solveToCam(double hueDegrees, double chroma, double lstar)Finds an sRGB color with the given hue, chroma, and L*, if possible.static intsolveToInt(double hueDegrees, double chroma, double lstar)Finds an sRGB color with the given hue, chroma, and L*, if possible.(package private) static doubletrueDelinearized(double rgbComponent)Delinearizes an RGB component, returning a floating-point number.
-
-
-
Method Detail
-
sanitizeRadians
static double sanitizeRadians(double angle)
Sanitizes a small enough angle in radians.- Parameters:
angle- An angle in radians; must not deviate too much from 0.- Returns:
- A coterminal angle between 0 and 2pi.
-
trueDelinearized
static double trueDelinearized(double rgbComponent)
Delinearizes an RGB component, returning a floating-point number.- Parameters:
rgbComponent- 0.0 <= rgb_component <= 100.0, represents linear R/G/B channel- Returns:
- 0.0 <= output <= 255.0, color channel converted to regular RGB space
-
chromaticAdaptation
static double chromaticAdaptation(double component)
-
hueOf
static double hueOf(double[] linrgb)
Returns the hue of a linear RGB color in CAM16.- Parameters:
linrgb- The linear RGB coordinates of a color.- Returns:
- The hue of the color in CAM16, in radians.
-
areInCyclicOrder
static boolean areInCyclicOrder(double a, double b, double c)
-
intercept
static double intercept(double source, double mid, double target)Solves the lerp equation.- Parameters:
source- The starting number.mid- The number in the middle.target- The ending number.- Returns:
- A number t such that lerp(source, target, t) = mid.
-
lerpPoint
static double[] lerpPoint(double[] source, double t, double[] target)
-
setCoordinate
static double[] setCoordinate(double[] source, double coordinate, double[] target, int axis)Intersects a segment with a plane.- Parameters:
source- The coordinates of point A.coordinate- The R-, G-, or B-coordinate of the plane.target- The coordinates of point B.axis- The axis the plane is perpendicular with. (0: R, 1: G, 2: B)- Returns:
- The intersection point of the segment AB with the plane R=coordinate, G=coordinate, or B=coordinate
-
isBounded
static boolean isBounded(double x)
-
nthVertex
static double[] nthVertex(double y, int n)Returns the nth possible vertex of the polygonal intersection.- Parameters:
y- The Y value of the plane.n- The zero-based index of the point. 0 <= n <= 11.- Returns:
- The nth possible vertex of the polygonal intersection of the y plane and the RGB cube, in linear RGB coordinates, if it exists. If this possible vertex lies outside of the cube, [-1.0, -1.0, -1.0] is returned.
-
bisectToSegment
static double[][] bisectToSegment(double y, double targetHue)Finds the segment containing the desired color.- Parameters:
y- The Y value of the color.targetHue- The hue of the color.- Returns:
- A list of two sets of linear RGB coordinates, each corresponding to an endpoint of the segment containing the desired color.
-
midpoint
static double[] midpoint(double[] a, double[] b)
-
criticalPlaneBelow
static int criticalPlaneBelow(double x)
-
criticalPlaneAbove
static int criticalPlaneAbove(double x)
-
bisectToLimit
static double[] bisectToLimit(double y, double targetHue)Finds a color with the given Y and hue on the boundary of the cube.- Parameters:
y- The Y value of the color.targetHue- The hue of the color.- Returns:
- The desired color, in linear RGB coordinates.
-
inverseChromaticAdaptation
static double inverseChromaticAdaptation(double adapted)
-
findResultByJ
static int findResultByJ(double hueRadians, double chroma, double y)Finds a color with the given hue, chroma, and Y.- Parameters:
hueRadians- The desired hue in radians.chroma- The desired chroma.y- The desired Y.- Returns:
- The desired color as a hexadecimal integer, if found; 0 otherwise.
-
solveToInt
public static int solveToInt(double hueDegrees, double chroma, double lstar)Finds an sRGB color with the given hue, chroma, and L*, if possible.- Parameters:
hueDegrees- The desired hue, in degrees.chroma- The desired chroma.lstar- The desired L*.- Returns:
- A hexadecimal representing the sRGB color. The color has sufficiently close hue, chroma, and L* to the desired values, if possible; otherwise, the hue and L* will be sufficiently close, and chroma will be maximized.
-
solveToCam
public static Cam16 solveToCam(double hueDegrees, double chroma, double lstar)
Finds an sRGB color with the given hue, chroma, and L*, if possible.- Parameters:
hueDegrees- The desired hue, in degrees.chroma- The desired chroma.lstar- The desired L*.- Returns:
- A CAM16 object representing the sRGB color. The color has sufficiently close hue, chroma, and L* to the desired values, if possible; otherwise, the hue and L* will be sufficiently close, and chroma will be maximized.
-
-