• Docs
  • API
Show / Hide Table of Contents
  • NixUniversalSDK
    • BatteryStateEventArgs
    • ColorData
    • ColorDifferenceType
    • ColorDifferenceTypeExtensions
    • ColorType
    • ColorTypeExtensions
    • ColorUtils
    • CommandStatus
    • CommandStatusExtensions
    • DensityData
    • DensityStatus
    • DensityStatusExtensions
    • DeviceCompat
    • DeviceResult
    • DeviceScanner
    • DeviceScannerState
    • DeviceScannerStateExtensions
    • DeviceState
    • DeviceStateExtensions
    • DeviceStatus
    • DeviceStatusArgs
    • DeviceStatusExtensions
    • DeviceType
    • DeviceTypeExtensions
    • DeviceVersion
    • ExtPowerStateEventArgs
    • IColorData
    • IColorDataExtensions
    • IDensityData
    • IDeviceCompat
    • IDeviceCompatEvents
    • IDeviceCompatExtensions
    • IDeviceScanner
    • IDeviceScannerEvents
    • IMeasurementData
    • IMeasurementDataExtensions
    • ISpectralData
    • ISpectralDataExtensions
    • Illuminant
    • IlluminantExtensions
    • InterfaceType
    • InterfaceTypeExtensions
    • LicenseFeature
    • LicenseFeatureExtensions
    • LicenseManager
    • LicenseManagerState
    • MeasurementData
    • Observer
    • ObserverExtensions
    • ReferenceWhite
    • ReferenceWhiteExtensions
    • ScanMode
    • ScanModeExtensions
    • ScanResultEventArgs
    • ScannerCreatedEventArgs
    • SpectralData
  • NixUniversalSDK.Wrapper
    • Constants
    • Delegates
    • Delegates.BoolValue
    • Delegates.Empty
    • Delegates.IntValue
    • Delegates.StringValue
    • DeviceCompatModule
    • DeviceScannerModule
    • Exported

Class ColorUtils

Color math utility functions

Inheritance
object
ColorUtils
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: NixUniversalSDK
Assembly: NixUniversalSDK.dll
Syntax
public static class ColorUtils

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

Declaration
public static double[] AdaptXyz(double[] xyzIn, double[] refIn, double[] refOut)
Parameters
Type Name Description
double[] xyzIn

Source color, referenced to refIn (element order X, Y, Z)

double[] refIn

Source reference white (element order X, Y, Z)

double[] refOut

Destination reference white (element order X, Y, Z)

Returns
Type Description
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.

Declaration
public static double[] ClipXyz(double[] xyz, double[] xyzRef)
Parameters
Type Name Description
double[] xyz

CIEXYZ value (element order X, Y, Z)

double[] xyzRef

CIEXYZ value for reference white (X, Y, Z)

Returns
Type Description
double[]

Clipped CIEXYZ value (element order X, Y, Z)

CmykToXyz(double[], double[], bool)

Calculates XYZ value from CMYK input using built-in lookup tables

Declaration
public static double[] CmykToXyz(double[] cmykIn, double[] refOut, bool bpc)
Parameters
Type Name Description
double[] cmykIn

CMYK colour input, unity scale (element order C, M, Y, K)

double[] refOut

Reference white value for XYZ output, unity scale (element order X, Y, Z)

bool bpc

Set to true to perform black point compensation

Returns
Type Description
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

Declaration
public static double[] CmykToXyz(double[] cmykIn, double[] refOut, bool bpc, double[][] m, int[][] input, int[][] clut, int[][] output)
Parameters
Type Name Description
double[] cmykIn

CMYK colour input, unity scale (element order C, M, Y, K)

double[] refOut

Reference white value for XYZ output, unity scale (element order X, Y, Z)

bool bpc

Set to true to perform black point compensation

double[][] m

3x3 Extracted from ICC profile: transformation matrix to perform on LAB value (NOT used in current function)

int[][] input

256x4 Extracted from ICC profile: InputCurves

int[][] clut

6561x3 Extracted from ICC profile: CMYK to LAB LUT (flattened 9x9x9x9 array with 3 channels, one each for L, A, B)

int[][] output

Extracted from ICC profile: OutputCurves (NOT used in current function, default profile has 1:1 output)

Returns
Type Description
double[]

XYZ value output, unity scale (element order X, Y, Z)

DegToRad(double)

Converts angle in degrees to radians (used in dE2000 function)

Declaration
public static double DegToRad(double deg)
Parameters
Type Name Description
double deg

Angle in degrees

Returns
Type Description
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.

Declaration
public static double DeltaE00(double[] lab1, double[] lab2, double kL = 1, double kC = 1, double kH = 1)
Parameters
Type Name Description
double[] lab1

First CIELAB value (element order L, a, b)

double[] lab2

Second CIELAB value (element order L, a, b)

double kL

Model parameter (optional, default 1)

double kC

Model parameter (optional, default 1)

double kH

Model parameter (optional, default 1)

Returns
Type Description
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.

Declaration
public static double DeltaE76(double[] lab1, double[] lab2)
Parameters
Type Name Description
double[] lab1

First CIELAB value (element order L, a, b)

double[] lab2

Second CIELAB value (element order L, a, b)

Returns
Type Description
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.

Declaration
public static double DeltaE94(double[] lab1, double[] lab2, double kL, double k1, double k2)
Parameters
Type Name Description
double[] lab1

First CIELAB value (element order L, a, b)

double[] lab2

Second CIELAB value (element order L, a, b)

double kL

Weighting factor (application dependent)

double k1

Weighting factor (application dependent)

double k2

Weighting factor (application dependent)

Returns
Type Description
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)

Declaration
public static double DeltaE94G(double[] lab1, double[] lab2)
Parameters
Type Name Description
double[] lab1

First CIELAB value (element order L, a, b)

double[] lab2

Second CIELAB value (element order L, a, b)

Returns
Type Description
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)

Declaration
public static double DeltaE94T(double[] lab1, double[] lab2)
Parameters
Type Name Description
double[] lab1

First CIELAB value (element order L, a, b)

double[] lab2

Second CIELAB value (element order L, a, b)

Returns
Type Description
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.

Declaration
public static double DeltaECmc(double[] lab1, double[] lab2, double l, double c)
Parameters
Type Name Description
double[] lab1

First CIELAB value (element order L, a, b)

double[] lab2

First CIELAB value (element order L, a, b)

double l

Model parameter l

double c

Model parameter c

Returns
Type Description
double

Delta E (CMC) value

LabToLch(double[])

Takes CIELAB value and converts to polar coordinates (LCH)

Declaration
public static double[] LabToLch(double[] labIn)
Parameters
Type Name Description
double[] labIn

CIELAB value (element order L, a, b)

Returns
Type Description
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

Declaration
public static double[] LabToXyz(double[] lab, Illuminant illuminant, Observer observer)
Parameters
Type Name Description
double[] lab
Illuminant illuminant

Illuminant for reference white point

Observer observer

Observer for reference white point

Returns
Type Description
double[]

CIEXYZ value (element order X, Y, Z)

LabToXyz(double[], ReferenceWhite)

Takes CIELAB value and its reference white to calculate CIEXYZ value

Declaration
public static double[] LabToXyz(double[] lab, ReferenceWhite reference)
Parameters
Type Name Description
double[] lab

CIELAB value (element order L, a, b)

ReferenceWhite reference

Reference white point for input CIEXYZ value

Returns
Type Description
double[]

CIEXYZ value (element order X, Y, Z)

LabToXyz(double[], double[])

Takes CIELAB value and its reference white to calculate CIEXYZ value

Declaration
public static double[] LabToXyz(double[] lab, double[] xyzRef)
Parameters
Type Name Description
double[] lab

CIELAB value (element order L, a, b)

double[] xyzRef

Reference white (element order X, Y, Z)

Returns
Type Description
double[]

CIEXYZ value (element order X, Y, Z)

LchToLab(double[])

Takes LCHab value and converts to CIELAB

Declaration
public static double[] LchToLab(double[] lchIn)
Parameters
Type Name Description
double[] lchIn

LCHab value (element order L, c, h). Hue angle h is in degrees

Returns
Type Description
double[]

CIELAB value (element order L, a, b)

LchToLuv(double[])

Takes LCHuv value and converts to CIELUV

Declaration
public static double[] LchToLuv(double[] lchIn)
Parameters
Type Name Description
double[] lchIn

LCHuv value (element order L, c, h). Hue angle h is in degrees

Returns
Type Description
double[]

CIELUV value (element order L, u, v)

LuvToLch(double[])

Takes CIELUV value and converts to polar coordinates (LCH)

Declaration
public static double[] LuvToLch(double[] LuvIn)
Parameters
Type Name Description
double[] LuvIn

CIELUV value (element order L, u, v)

Returns
Type Description
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

Declaration
public static double[] LuvToXyz(double[] luvIn, double[] xyzRef)
Parameters
Type Name Description
double[] luvIn

CIELUV value (element order L, u, v)

double[] xyzRef

CIEXYZ reference white (element order X, Y, Z)

Returns
Type Description
double[]

CIEXYZ value (element order X, Y, Z)

RadToDeg(double)

Converts angle in radians to degrees (used in dE2000 function)

Declaration
public static double RadToDeg(double rads)
Parameters
Type Name Description
double rads

Angle in radians

Returns
Type Description
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.

Declaration
public static double[] RgbToXyz(double[] rgbIn, double[] rC, double[] gC, double[] bC, double[] wC, double[] refOut)
Parameters
Type Name Description
double[] rgbIn

Input linear RGB value, unity scale (element order R, G, B)

double[] rC

RGB space red primary chromaticity coordinates (element order x, y)

double[] gC

RGB space green primary chromaticity coordinates (element order x, y)

double[] bC

RGB space blue primary chromaticity coordinates (element order x, y)

double[] wC

RGB space reference white/grey chromaticity coordinates (element order x, y)

double[] refOut

Selected reference white of output XYZ color, unity scale (element order X, Y, Z)

Returns
Type Description
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")

Declaration
public static string RgbTripletToHexString(byte[] rgb)
Parameters
Type Name Description
byte[] rgb
Returns
Type Description
string
Exceptions
Type Condition
ArgumentException

Thrown if array does not have three entries

SRgbToXyz(byte[], double[])

Calculates XYZ from sRGB value

Declaration
public static double[] SRgbToXyz(byte[] sRgb, double[] refOut)
Parameters
Type Name Description
byte[] sRgb

Non-linear sRGB value, 0 - 255 scale (element order R, G, B)

double[] refOut

Reference white of colour output, unity scale (element order X, Y, Z)

Returns
Type Description
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.

Declaration
public static double[] Spectral10ToDensity(int[] lambda, float[] reflectance, DensityStatus status)
Parameters
Type Name Description
int[] lambda

Wavelength values of provided reflectance data.

float[] reflectance

Reflectance data. Must contain the same number of elements as lambda

DensityStatus status

Selected density status

Returns
Type Description
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.

Declaration
public static double[] Spectral10ToXyz(int[] lambda, float[] reflectance, Illuminant illuminant, Observer observer)
Parameters
Type Name Description
int[] lambda

Wavelength values of provided reflectance data.

float[] reflectance

Reflectance data. Must contain the same number of elements as lambda

Illuminant illuminant

Reference illuminant

Observer observer

Reference observer

Returns
Type Description
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.

Declaration
public static double[] Spectral10ToXyz(int[] lambda, float[] reflectance, ReferenceWhite reference)
Parameters
Type Name Description
int[] lambda

Wavelength values of provided reflectance data.

float[] reflectance

Reflectance data. Must contain the same number of elements as lambda

ReferenceWhite reference

Selected reference white

Returns
Type Description
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.

Declaration
public static double[] XyzChromaticity(double[] xyz)
Parameters
Type Name Description
double[] xyz

Source color (element order X, Y, Z)

Returns
Type Description
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

Declaration
public static double[] XyzToCmyk(double[] xyzIn, double[] xyzRef, bool bpc)
Parameters
Type Name Description
double[] xyzIn

XYZ colour, unity scale (element order X, Y, Z)

double[] xyzRef

Reference white value for xyzIn, unity scale (element order X, Y, Z)

bool bpc

Black point compensation enabled / disabled

Returns
Type Description
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

Declaration
public static double[] XyzToCmyk(double[] xyzIn, double[] xyzRef, bool bpc, double[][] m, int[][] inputCurves, int[][] clut, int[][] outputCurves)
Parameters
Type Name Description
double[] xyzIn

XYZ colour, unity scale (element order X, Y, Z)

double[] xyzRef

Reference white value for xyzIn, unity scale (element order X, Y, Z)

bool bpc

Black point compensation enabled / disabled

double[][] m

3x3 Extracted from ICC profile: transformation matrix to perform on LAB value (code only tested with identity matrix)

int[][] inputCurves

256x3 Extracted from ICC profile: InputCurves

int[][] clut

35937x4: Extracted from ICC profile: Lab to CMYK LUT (flattened 33x33x33 array with 4 channels, one each for C,M,Y,K)

int[][] outputCurves

256x4: Extracted from ICC profile: OutputCurves

Returns
Type Description
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.

Declaration
public static double[] XyzToLab(double[] xyz, Illuminant illuminant, Observer observer)
Parameters
Type Name Description
double[] xyz
Illuminant illuminant

Illuminant for reference white point

Observer observer

Observer for reference white point

Returns
Type Description
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.

Declaration
public static double[] XyzToLab(double[] xyz, ReferenceWhite reference)
Parameters
Type Name Description
double[] xyz

CIEXYZ value (element order X, Y, Z)

ReferenceWhite reference

Reference white point for input CIEXYZ value

Returns
Type Description
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)

Declaration
public static double[] XyzToLab(double[] xyz, double[] xyzRef)
Parameters
Type Name Description
double[] xyz

CIEXYZ value (element order X, Y, Z)

double[] xyzRef

CIEXYZ value for reference white (X, Y, Z)

Returns
Type Description
double[]

CIELAB value (element order L, a, b)

XyzToLuv(double[], double[])

Takes CIEXYZ value and its reference white to calculate CIELUV value.

Declaration
public static double[] XyzToLuv(double[] xyzIn, double[] xyzRef)
Parameters
Type Name Description
double[] xyzIn

CIEXYZ value (element order X, Y, Z)

double[] xyzRef

CIEXYZ reference white (element order X, Y, Z)

Returns
Type Description
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

Declaration
public static double[] XyzToRgb(double[] xyzIn, double[] refIn, double[] rC, double[] gC, double[] bC, double[] wC)
Parameters
Type Name Description
double[] xyzIn

Input colour XYZ values, unity scale (element order X, Y, Z)

double[] refIn

Reference white of input colour xyzIn, unity scale (element order X, Y, Z)

double[] rC

RGB space red primary chromaticity coordinates (element order x, y)

double[] gC

RGB space green primary chromaticity coordinates (element order x, y)

double[] bC

RGB space blue primary chromaticity coordinates (element order x, y)

double[] wC

RGB space reference white/grey chromaticity coordinates (element order x, y)

Returns
Type Description
double[]

XyzToSRgb(double[], double[])

Calculates companded sRGB value from XYZ given reference white of XYZ value.

Declaration
public static byte[] XyzToSRgb(double[] xyzIn, double[] refIn)
Parameters
Type Name Description
double[] xyzIn

Input colour XYZ values, unity scale (element order X, Y, Z)

double[] refIn

Reference white of input colour xyzIn, unity scale (element order X, Y, Z)

Returns
Type Description
byte[]

Non-linear sRGB value, 0 - 255 scale (element order R, G, B)

In this article
Back to top Generated by DocFX