Class ColorUtils
- Namespace
- NixUniversalSDK
- Assembly
- NixUniversalSDK.dll
Color math utility functions
public static class ColorUtils
- Inheritance
-
ColorUtils
- Inherited Members
Methods
AdaptXyz(double[], double[], double[])
Adapts colour in XYZ from one reference white to another using Bradford adaptation method. NOTE: refIn, refOut, xyzIn must all be on the same scale
public static double[] AdaptXyz(double[] xyzIn, double[] refIn, double[] refOut)
Parameters
xyzIndouble[]Source color, referenced to refIn (element order X, Y, Z)
refIndouble[]Source reference white (element order X, Y, Z)
refOutdouble[]Destination reference white (element order X, Y, Z)
Returns
- double[]
Adapted color, referenced to refOut (element order X, Y, Z)
ClipXyz(double[], double[])
Clips CIEXYZ values in between 0 and the value of the reference white to ensure X, Y, Z are in the proper range.
public static double[] ClipXyz(double[] xyz, double[] xyzRef)
Parameters
xyzdouble[]CIEXYZ value (element order X, Y, Z)
xyzRefdouble[]CIEXYZ value for reference white (X, Y, Z)
Returns
- double[]
Clipped CIEXYZ value (element order X, Y, Z)
CmykToXyz(double[], double[], bool)
Calculates XYZ value from CMYK input using built-in lookup tables
public static double[] CmykToXyz(double[] cmykIn, double[] refOut, bool bpc)
Parameters
cmykIndouble[]CMYK colour input, unity scale (element order C, M, Y, K)
refOutdouble[]Reference white value for XYZ output, unity scale (element order X, Y, Z)
bpcboolSet to true to perform black point compensation
Returns
- double[]
XYZ value output, unity scale (element order X, Y, Z)
CmykToXyz(double[], double[], bool, double[][], int[][], int[][], int[][])
Calculates XYZ value from CMYK input using lookup tables provided as input arguments
public static double[] CmykToXyz(double[] cmykIn, double[] refOut, bool bpc, double[][] m, int[][] input, int[][] clut, int[][] output)
Parameters
cmykIndouble[]CMYK colour input, unity scale (element order C, M, Y, K)
refOutdouble[]Reference white value for XYZ output, unity scale (element order X, Y, Z)
bpcboolSet to true to perform black point compensation
mdouble[][]3x3 Extracted from ICC profile: transformation matrix to perform on LAB value (NOT used in current function)
inputint[][]256x4 Extracted from ICC profile: InputCurves
clutint[][]6561x3 Extracted from ICC profile: CMYK to LAB LUT (flattened 9x9x9x9 array with 3 channels, one each for L, A, B)
outputint[][]Extracted from ICC profile: OutputCurves (NOT used in current function, default profile has 1:1 output)
Returns
- double[]
XYZ value output, unity scale (element order X, Y, Z)
DegToRad(double)
Converts angle in degrees to radians (used in dE2000 function)
public static double DegToRad(double deg)
Parameters
degdoubleAngle in degrees
Returns
- double
Angle in radians
DeltaE00(double[], double[], double, double, double)
Takes two CIELAB values and calculates color difference (dE) using the CIE2000 formula. NOTE: both CIELAB values must share the same reference white. If they do not, convert to XYZ, adapt, convert back to CIELAB before calculating dE.
public static double DeltaE00(double[] lab1, double[] lab2, double kL = 1, double kC = 1, double kH = 1)
Parameters
lab1double[]First CIELAB value (element order L, a, b)
lab2double[]Second CIELAB value (element order L, a, b)
kLdoubleModel parameter (optional, default 1)
kCdoubleModel parameter (optional, default 1)
kHdoubleModel parameter (optional, default 1)
Returns
- double
Delta E (2000) value
DeltaE76(double[], double[])
Takes two CIELAB values and calculates color difference (dE) using CIE1976 formula. NOTE: both CIELAB values must share the same reference white. If they do not: convert to XYZ, adapt, convert back to CIELAB before calculating dE.
public static double DeltaE76(double[] lab1, double[] lab2)
Parameters
lab1double[]First CIELAB value (element order L, a, b)
lab2double[]Second CIELAB value (element order L, a, b)
Returns
- double
Delta E (1976) value
DeltaE94(double[], double[], double, double, double)
Takes two CIELAB values and calculates color difference (dE) using the CIE1994 formula. Requires weighting factors kL, k1, and k2 which are dependent on application. Use DeltaE94G(double[], double[]) for graphic design applications andDeltaE94T(double[], double[]) for textile applications. Both CIELAB values must share the same reference white.If they do not, convert to XYZ, adapt, convert back to CIELAB before calculating dE.
public static double DeltaE94(double[] lab1, double[] lab2, double kL, double k1, double k2)
Parameters
lab1double[]First CIELAB value (element order L, a, b)
lab2double[]Second CIELAB value (element order L, a, b)
kLdoubleWeighting factor (application dependent)
k1doubleWeighting factor (application dependent)
k2doubleWeighting factor (application dependent)
Returns
- double
Delta E (1994) value
DeltaE94G(double[], double[])
Takes two CIELAB values and calculates color difference (dE) using the CIE1994 formula for the graphic design application (kL = 1, k1 = 0.045, k2 = 0.015). See also DeltaE94(double[], double[], double, double, double)
public static double DeltaE94G(double[] lab1, double[] lab2)
Parameters
lab1double[]First CIELAB value (element order L, a, b)
lab2double[]Second CIELAB value (element order L, a, b)
Returns
- double
Delta E (1994) value
DeltaE94T(double[], double[])
Takes two CIELAB values and calculates color difference (dE) using the CIE1994 formula for the textiles design application (kL = 2, k1 = 0.048, k2 = 0.014). See also DeltaE94(double[], double[], double, double, double)
public static double DeltaE94T(double[] lab1, double[] lab2)
Parameters
lab1double[]First CIELAB value (element order L, a, b)
lab2double[]Second CIELAB value (element order L, a, b)
Returns
- double
Delta E (1994) value
DeltaECmc(double[], double[], double, double)
Takes two CIELAB values and calculates color difference (dE) using the CMC(l:c) formula. Depends on model parameters l and c; common values used are CMC(2:1) for acceptability and CMC(1:1) for perceptibility.
public static double DeltaECmc(double[] lab1, double[] lab2, double l, double c)
Parameters
lab1double[]First CIELAB value (element order L, a, b)
lab2double[]First CIELAB value (element order L, a, b)
ldoubleModel parameter l
cdoubleModel parameter c
Returns
- double
Delta E (CMC) value
LabToLch(double[])
Takes CIELAB value and converts to polar coordinates (LCH)
public static double[] LabToLch(double[] labIn)
Parameters
labIndouble[]CIELAB value (element order L, a, b)
Returns
- double[]
LCHab value (element order L, c, h). Hue angle h is in degrees
LabToXyz(double[], Illuminant, Observer)
Takes CIELAB value and its reference white to calculate CIEXYZ value
public static double[] LabToXyz(double[] lab, Illuminant illuminant, Observer observer)
Parameters
labdouble[]illuminantIlluminantIlluminant for reference white point
observerObserverObserver for reference white point
Returns
- double[]
CIEXYZ value (element order X, Y, Z)
LabToXyz(double[], ReferenceWhite)
Takes CIELAB value and its reference white to calculate CIEXYZ value
public static double[] LabToXyz(double[] lab, ReferenceWhite reference)
Parameters
labdouble[]CIELAB value (element order L, a, b)
referenceReferenceWhiteReference white point for input CIEXYZ value
Returns
- double[]
CIEXYZ value (element order X, Y, Z)
LabToXyz(double[], double[])
Takes CIELAB value and its reference white to calculate CIEXYZ value
public static double[] LabToXyz(double[] lab, double[] xyzRef)
Parameters
labdouble[]CIELAB value (element order L, a, b)
xyzRefdouble[]Reference white (element order X, Y, Z)
Returns
- double[]
CIEXYZ value (element order X, Y, Z)
LchToLab(double[])
Takes LCHab value and converts to CIELAB
public static double[] LchToLab(double[] lchIn)
Parameters
lchIndouble[]LCHab value (element order L, c, h). Hue angle h is in degrees
Returns
- double[]
CIELAB value (element order L, a, b)
LchToLuv(double[])
Takes LCHuv value and converts to CIELUV
public static double[] LchToLuv(double[] lchIn)
Parameters
lchIndouble[]LCHuv value (element order L, c, h). Hue angle h is in degrees
Returns
- double[]
CIELUV value (element order L, u, v)
LuvToLch(double[])
Takes CIELUV value and converts to polar coordinates (LCH)
public static double[] LuvToLch(double[] LuvIn)
Parameters
LuvIndouble[]CIELUV value (element order L, u, v)
Returns
- double[]
LCHuv value (element order L, c, h). Hue angle h is in degrees
LuvToXyz(double[], double[])
Takes CIELUV value and its reference white to calculate CIEXYZ value
public static double[] LuvToXyz(double[] luvIn, double[] xyzRef)
Parameters
luvIndouble[]CIELUV value (element order L, u, v)
xyzRefdouble[]CIEXYZ reference white (element order X, Y, Z)
Returns
- double[]
CIEXYZ value (element order X, Y, Z)
RadToDeg(double)
Converts angle in radians to degrees (used in dE2000 function)
public static double RadToDeg(double rads)
Parameters
radsdoubleAngle in radians
Returns
- double
Angle in degrees
RgbToXyz(double[], double[], double[], double[], double[], double[])
Calculates XYZ from linear RGB given chromaticity coordinates of RGB working space primaries and reference whites of RGB and XYZ value.
public static double[] RgbToXyz(double[] rgbIn, double[] rC, double[] gC, double[] bC, double[] wC, double[] refOut)
Parameters
rgbIndouble[]Input linear RGB value, unity scale (element order R, G, B)
rCdouble[]RGB space red primary chromaticity coordinates (element order x, y)
gCdouble[]RGB space green primary chromaticity coordinates (element order x, y)
bCdouble[]RGB space blue primary chromaticity coordinates (element order x, y)
wCdouble[]RGB space reference white/grey chromaticity coordinates (element order x, y)
refOutdouble[]Selected reference white of output XYZ color, unity scale (element order X, Y, Z)
Returns
- double[]
XYZ value, unity scale, with reference white refOut (element order X, Y, Z)
RgbTripletToHexString(byte[])
Takes a RGB triplet and formats it as a HEX string (e.g. - "#RRGGBB")
public static string RgbTripletToHexString(byte[] rgb)
Parameters
rgbbyte[]
Returns
Exceptions
- ArgumentException
Thrown if array does not have three entries
SRgbToXyz(byte[], double[])
Calculates XYZ from sRGB value
public static double[] SRgbToXyz(byte[] sRgb, double[] refOut)
Parameters
sRgbbyte[]Non-linear sRGB value, 0 - 255 scale (element order R, G, B)
refOutdouble[]Reference white of colour output, unity scale (element order X, Y, Z)
Returns
- double[]
XYZ value, unity scale, with reference white refOut (element order X, Y, Z)
Spectral10ToDensity(int[], float[], DensityStatus)
Takes reflectance data on 10 nm intervals and calculates CMYK densities according to ISO 5-3:2009. Data must be provided on 10 nm intervals corresponding to the nearest 10 nanometer. Density values are calculated across the range 340 - 770 nm. If the provided data spans a shorter range (e.g. - 400 - 700 nm), the values at the boundaries are repeated.
public static double[] Spectral10ToDensity(int[] lambda, float[] reflectance, DensityStatus status)
Parameters
lambdaint[]Wavelength values of provided reflectance data.
reflectancefloat[]Reflectance data. Must contain the same number of elements as lambda
statusDensityStatusSelected density status
Returns
- double[]
CMYK densities (element order C, M, Y, K)
Spectral10ToXyz(int[], float[], Illuminant, Observer)
Takes reflectance data on 10 nm intervals and calculates a CIEXYZ value according to ASTM E308. Data must be provided on 10 nm intervals corresponding to the nearest 10 nanometer. CIEXYZ values are calculated across the range 360 - 780 nm.If the provided data spans a shorter range (e.g. - 400 - 700 nm), the values at the boundaries are repeated.
public static double[] Spectral10ToXyz(int[] lambda, float[] reflectance, Illuminant illuminant, Observer observer)
Parameters
lambdaint[]Wavelength values of provided reflectance data.
reflectancefloat[]Reflectance data. Must contain the same number of elements as lambda
illuminantIlluminantReference illuminant
observerObserverReference observer
Returns
- double[]
CIEXYZ value reported on 0 - 1.0 scale (element order X, Y, Z)
Spectral10ToXyz(int[], float[], ReferenceWhite)
Takes reflectance data on 10 nm intervals and calculates a CIEXYZ value according to ASTM E308. Data must be provided on 10 nm intervals corresponding to the nearest 10 nanometer. CIEXYZ values are calculated across the range 360 - 780 nm. If the provided data spans a shorter range (e.g. - 400 - 700 nm), the values at the boundaries are repeated.
public static double[] Spectral10ToXyz(int[] lambda, float[] reflectance, ReferenceWhite reference)
Parameters
lambdaint[]Wavelength values of provided reflectance data.
reflectancefloat[]Reflectance data. Must contain the same number of elements as lambda
referenceReferenceWhiteSelected reference white
Returns
- double[]
CIEXYZ value reported on 0 - 1.0 scale (element order X, Y, Z)
XyzChromaticity(double[])
Calculates chromaticity coordinates x,y from a given xyz value. WARNING: Be aware that for black xyz(0, 0, 0), the result is undefined. For this case, use chromaticity of reference white instead.
public static double[] XyzChromaticity(double[] xyz)
Parameters
xyzdouble[]Source color (element order X, Y, Z)
Returns
- double[]
Chromaticity of input color, unity scale (element order x, y)
XyzToCmyk(double[], double[], bool)
Calculates CMYK value from XYZ input using built in lookup tables
public static double[] XyzToCmyk(double[] xyzIn, double[] xyzRef, bool bpc)
Parameters
xyzIndouble[]XYZ colour, unity scale (element order X, Y, Z)
xyzRefdouble[]Reference white value for xyzIn, unity scale (element order X, Y, Z)
bpcboolBlack point compensation enabled / disabled
Returns
- double[]
CMYK value on unity scale (element order C, M, Y, K)
XyzToCmyk(double[], double[], bool, double[][], int[][], int[][], int[][])
Calculates CMYK value from XYZ using lookup tables provided as inputCurves arguments
public static double[] XyzToCmyk(double[] xyzIn, double[] xyzRef, bool bpc, double[][] m, int[][] inputCurves, int[][] clut, int[][] outputCurves)
Parameters
xyzIndouble[]XYZ colour, unity scale (element order X, Y, Z)
xyzRefdouble[]Reference white value for xyzIn, unity scale (element order X, Y, Z)
bpcboolBlack point compensation enabled / disabled
mdouble[][]3x3 Extracted from ICC profile: transformation matrix to perform on LAB value (code only tested with identity matrix)
inputCurvesint[][]256x3 Extracted from ICC profile: InputCurves
clutint[][]35937x4: Extracted from ICC profile: Lab to CMYK LUT (flattened 33x33x33 array with 4 channels, one each for C,M,Y,K)
outputCurvesint[][]256x4: Extracted from ICC profile: OutputCurves
Returns
- double[]
CMYK value on unity scale (element order C, M, Y, K)
XyzToLab(double[], Illuminant, Observer)
Takes CIEXYZ value and its reference white to calculate CIELAB value. Value xyz and xyzRef must be either unity (Y on 0 - 1) input.
public static double[] XyzToLab(double[] xyz, Illuminant illuminant, Observer observer)
Parameters
xyzdouble[]illuminantIlluminantIlluminant for reference white point
observerObserverObserver for reference white point
Returns
- double[]
CIELAB value (element order L, a, b)
XyzToLab(double[], ReferenceWhite)
Takes CIEXYZ value and its reference white to calculate CIELAB value. Value xyz and xyzRef must be either unity (Y on 0 - 1) input.
public static double[] XyzToLab(double[] xyz, ReferenceWhite reference)
Parameters
xyzdouble[]CIEXYZ value (element order X, Y, Z)
referenceReferenceWhiteReference white point for input CIEXYZ value
Returns
- double[]
CIELAB value (element order L, a, b)
XyzToLab(double[], double[])
Takes CIEXYZ value and its reference white to calculate CIELAB value. Values xyz and xyzRef can be either unity (0 - 1) or scaled (0 - 100) input, but both vectors must be the same scale. (i.e., if xyz is unity scale, xyzRef must also be unity scale)
public static double[] XyzToLab(double[] xyz, double[] xyzRef)
Parameters
xyzdouble[]CIEXYZ value (element order X, Y, Z)
xyzRefdouble[]CIEXYZ value for reference white (X, Y, Z)
Returns
- double[]
CIELAB value (element order L, a, b)
XyzToLuv(double[], double[])
Takes CIEXYZ value and its reference white to calculate CIELUV value.
public static double[] XyzToLuv(double[] xyzIn, double[] xyzRef)
Parameters
xyzIndouble[]CIEXYZ value (element order X, Y, Z)
xyzRefdouble[]CIEXYZ reference white (element order X, Y, Z)
Returns
- double[]
CIELUV value (element order L, u, v)
XyzToRgb(double[], double[], double[], double[], double[], double[])
Calculates linear RGB from XYZ given chromaticity coordinates of RGB working space primaries and reference whites of RGB and XYZ value
public static double[] XyzToRgb(double[] xyzIn, double[] refIn, double[] rC, double[] gC, double[] bC, double[] wC)
Parameters
xyzIndouble[]Input colour XYZ values, unity scale (element order X, Y, Z)
refIndouble[]Reference white of input colour xyzIn, unity scale (element order X, Y, Z)
rCdouble[]RGB space red primary chromaticity coordinates (element order x, y)
gCdouble[]RGB space green primary chromaticity coordinates (element order x, y)
bCdouble[]RGB space blue primary chromaticity coordinates (element order x, y)
wCdouble[]RGB space reference white/grey chromaticity coordinates (element order x, y)
Returns
- double[]
XyzToSRgb(double[], double[])
Calculates companded sRGB value from XYZ given reference white of XYZ value.
public static byte[] XyzToSRgb(double[] xyzIn, double[] refIn)
Parameters
xyzIndouble[]Input colour XYZ values, unity scale (element order X, Y, Z)
refIndouble[]Reference white of input colour xyzIn, unity scale (element order X, Y, Z)
Returns
- byte[]
Non-linear sRGB value, 0 - 255 scale (element order R, G, B)