chromaticity-color-utilities
Version:
Color utilities for Node.js
850 lines (849 loc) • 24.1 kB
JavaScript
"use strict";
// chromaticity-color-utilities
// Copyright (C) 2022 Emma Litwa-Vulcu
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
Object.defineProperty(exports, "__esModule", { value: true });
exports.xyzWavelengths = exports.colorSpaces = exports.stdIlluminants = exports.cieK = exports.cieE = void 0;
/**
* CIE Constants of L* Function
* ϵ = cieE
* κ = cieK
*
* Standard Illuminant White Points
* Reference Hue and RGB values
* Correlated Black Body Radiation Color Temperatures in deg K
* Chromaticity Coordinates (1931 2 deg & 1964 10 deg)
* Tristimulus Values for std 2 deg observer (incomplete)
*
* Color Spaces
* Gamma values
* XYZ to RGB and RGB to XYZ conversion matrices for various
* reference illuminants (generally d50 and d65, not comprehensive)
*/
// 0.008856 Initial CIE standard
// 216/24389 Intent of CIE standard, updated to standard in 2004
exports.cieE = 216 / 24389;
// 903.3 Initial CIE standard
// 24389/27 Intent of CIE standard, updated to standard in 2004
exports.cieK = 24389 / 27;
// Standard Illuminant White Points, including:
// Reference Hue and RGB values
// Correlated Black Body Radiation Color Temperatures in deg K
// Chromaticity Coordinates (1931 2 deg & 1964 10 deg)
// Tristimulus Values for std 2 deg observer (incomplete)
exports.stdIlluminants = {
a: {
ref: 'Incandescent / Tungsten',
k: 2856,
hue: 30,
rgb: [255, 175, 95],
chrom: {
'2d': {
x: 0.44757,
y: 0.40745,
},
'10d': {
x: 0.45117,
y: 0.40594,
},
},
vector: [1.0985, 1, 0.35585],
},
b: {
ref: 'Direct Sunlight at Noon',
k: 4874,
hue: 27,
rgb: [255, 226, 199],
chrom: {
'2d': {
x: 0.34842,
y: 0.35161,
},
'10d': {
x: 0.3498,
y: 0.3527,
},
},
vector: [0.99072, 1, 0.85223],
},
c: {
ref: 'Average / North Sky Daylight',
k: 6774,
hue: 276,
rgb: [248, 245, 255],
chrom: {
'2d': {
x: 0.31006,
y: 0.31616,
},
'10d': {
x: 0.31039,
y: 0.31905,
},
},
vector: [0.98074, 1, 1.18232],
},
d50: {
ref: 'Horizon Light / ICC profile PCS',
k: 5003,
hue: 35,
rgb: [255, 228, 205],
chrom: {
'2d': {
x: 0.34567,
y: 0.3585,
},
'10d': {
x: 0.34773,
y: 0.35952,
},
},
// 0.82 or 1.82 ?? >_>
vector: [0.96422, 1, 0.82521],
},
d55: {
ref: 'Mid-morning / Mid-afternoon Daylight',
k: 5503,
hue: 36,
rgb: [255, 236, 223],
chrom: {
'2d': {
x: 0.33242,
y: 0.34743,
},
'10d': {
x: 0.33411,
y: 0.34877,
},
},
vector: [0.95682, 1, 0.92149],
},
d65: {
ref: 'Noon Daylight / Television / sRGB',
k: 6504,
hue: false,
rgb: [255, 249, 255],
chrom: {
'2d': {
x: 0.31271,
y: 0.32902,
},
'10d': {
x: 0.31382,
y: 0.331,
},
},
vector: [0.95047, 1, 1.08883],
},
d75: {
ref: 'North Sky Daylight',
k: 7504,
hue: 217,
rgb: [232, 236, 255],
chrom: {
'2d': {
x: 0.29902,
y: 0.31485,
},
'10d': {
x: 0.29968,
y: 0.3174,
},
},
vector: [0.94972, 1, 1.22638],
},
e: {
ref: 'Equal Energy',
k: 5454,
hue: 10,
rgb: [255, 235, 221],
chrom: {
'2d': {
x: 1 / 3,
y: 1 / 3,
},
'10d': {
x: 1 / 3,
y: 1 / 3,
},
},
vector: [1, 1, 1],
},
f1: {
ref: 'Daylight Fluorescent',
k: 6430,
hue: 111,
rgb: [255, 248, 253],
chrom: {
'2d': {
x: 0.3131,
y: 0.33727,
},
'10d': {
x: 0.31811,
y: 0.33559,
},
},
},
f2: {
ref: 'Cool White FLuorescent',
k: 4230,
hue: 33,
rgb: [255, 213, 171],
chrom: {
'2d': {
x: 0.37208,
y: 0.37529,
},
'10d': {
x: 0.37925,
y: 0.36733,
},
},
vector: [0.99186, 1, 1.67393],
},
f3: {
ref: 'White Fluorescent',
k: 3450,
hue: 32,
rgb: [255, 194, 131],
chrom: {
'2d': {
x: 0.4091,
y: 0.3943,
},
'10d': {
x: 0.41761,
y: 0.38324,
},
},
},
f4: {
ref: 'Warm White FLuorescent',
k: 2940,
hue: 30,
rgb: [255, 177, 101],
chrom: {
'2d': {
x: 0.44018,
y: 0.40329,
},
'10d': {
x: 0.4492,
y: 0.39074,
},
},
},
f5: {
ref: 'Daylight FLuorescent',
k: 6350,
hue: 106,
rgb: [255, 247, 250],
chrom: {
'2d': {
x: 0.31379,
y: 0.34531,
},
'10d': {
x: 0.31975,
y: 0.34246,
},
},
},
f6: {
ref: 'Lite White Fluorescent',
k: 4150,
hue: 38,
rgb: [255, 212, 168],
chrom: {
'2d': {
x: 0.3779,
y: 0.38835,
},
'10d': {
x: 0.3866,
y: 0.37847,
},
},
},
f7: {
ref: 'D65 Simulator, Daylight Simulator',
k: 6500,
hue: false,
rgb: [255, 249, 255],
chrom: {
'2d': {
x: 0.31292,
y: 0.32933,
},
'10d': {
x: 0.31569,
y: 0.3296,
},
},
vector: [0.95041, 1, 1.08747],
},
f8: {
ref: 'D50 Simulator, Sylvania F40 Design 50',
k: 5000,
hue: 35,
rgb: [255, 228, 204],
chrom: {
'2d': {
x: 0.34588,
y: 0.35875,
},
'10d': {
x: 0.34902,
y: 0.35939,
},
},
},
f9: {
ref: 'Cool White Deluxe Fluorescent',
k: 4150,
hue: 30,
rgb: [255, 212, 168],
chrom: {
'2d': {
x: 0.37417,
y: 0.37281,
},
'10d': {
x: 0.37829,
y: 0.37045,
},
},
},
f10: {
ref: 'Philips TL85, Ultralume 50',
k: 5000,
hue: 36,
rgb: [255, 228, 204],
chrom: {
'2d': {
x: 0.34609,
y: 0.35986,
},
'10d': {
x: 0.3509,
y: 0.35444,
},
},
},
f11: {
ref: 'Philips TL84, Ultralume 40',
k: 4000,
hue: 31,
rgb: [255, 208, 160],
chrom: {
'2d': {
x: 0.38052,
y: 0.37713,
},
'10d': {
x: 0.38541,
y: 0.37123,
},
},
vector: [1.00962, 1, 0.6435],
},
f12: {
ref: 'Philips TL83, Ultralume 30',
k: 3000,
hue: 31,
rgb: [255, 179, 105],
chrom: {
'2d': {
x: 0.43695,
y: 0.40441,
},
'10d': {
x: 0.44256,
y: 0.39717,
},
},
},
icc: [0.9642, 1, 0.8249],
};
exports.colorSpaces = {
adobergb1998: {
name: 'Adobe RGB (1998)',
gamma: 2.2,
rgb2xyz: {
d65: [
[0.5767309, 0.185554, 0.1881852],
[0.2973769, 0.6273491, 0.0752741],
[0.0270343, 0.0706872, 0.9911085],
],
d50: [
[0.6097559, 0.2052401, 0.149224],
[0.3111242, 0.625656, 0.0632197],
[0.0194811, 0.0608902, 0.7448387],
],
},
xyz2rgb: {
d65: [
[2.041369, -0.5649464, -0.3446944],
[-0.969266, 1.8760108, 0.041556],
[0.0134474, -0.1183897, 1.0154096],
],
d50: [
[1.9624274, -0.6105343, -0.3413404],
[-0.9787684, 1.9161415, 0.033454],
[0.0286869, -0.1406752, 1.3487655],
],
},
},
applergb: {
name: 'Apple RGB',
gamma: 1.8,
rgb2xyz: {
d65: [
[0.4497288, 0.3162486, 0.1844926],
[0.2446525, 0.6720283, 0.0833192],
[0.0251848, 0.1411824, 0.9224628],
],
d50: [
[0.4755678, 0.3396722, 0.14898],
[0.2551812, 0.6725693, 0.0722496],
[0.0184697, 0.1133771, 0.6933632],
],
},
xyz2rgb: {
d65: [
[2.9515373, -1.2894116, -0.4738445],
[-1.0851093, 1.9908566, 0.0372026],
[0.0854934, -0.2694964, 1.0912975],
],
d50: [
[2.8510695, -1.3605261, -0.4708281],
[-1.092768, 2.0348871, 0.0227598],
[0.1027403, -0.2964984, 1.4510659],
],
},
},
bestrgb: {
name: 'Best RGB',
gamma: 2.2,
rgb2xyz: {
d50: [
[0.6326696, 0.2045558, 0.1269946],
[0.2284569, 0.7373523, 0.0341908],
[0, 0.0095142, 0.8156958],
],
},
xyz2rgb: {
d50: [
[1.7552599, -0.4836786, -0.253],
[-0.5441336, 1.5068789, 0.0215528],
[0.0063467, -0.0175761, 1.2256959],
],
},
},
betargb: {
name: 'Beta RGB',
gamma: 2.2,
rgb2xyz: {
d50: [
[0.6712537, 0.1745834, 0.1183829],
[0.3032726, 0.6637861, 0.0329413],
[0, 0.040701, 0.784509],
],
},
xyz2rgb: {
d50: [
[1.683227, -0.4282363, -0.2360185],
[-0.7710229, 1.7065571, 0.04469],
[0.0400013, -0.0885376, 1.272364],
],
},
},
brucergb: {
name: 'Bruce RGB',
gamma: 2.2,
rgb2xyz: {
d65: [
[0.4674162, 0.2944512, 0.1886026],
[0.2410115, 0.6835475, 0.075441],
[0.0219101, 0.0736128, 0.9933071],
],
d50: [
[0.4941816, 0.3204834, 0.149555],
[0.2521531, 0.6844869, 0.06336],
[0.0157886, 0.0629304, 0.7464909],
],
},
xyz2rgb: {
d65: [
[2.7454669, -1.1358136, -0.4350269],
[-0.969266, 1.8760108, 0.041556],
[0.0112723, -0.1139754, 1.0132541],
],
d50: [
[2.6502856, -1.2014485, -0.4289936],
[-0.9787684, 1.9161415, 0.033454],
[0.026457, -0.1361227, 1.3458542],
],
},
},
ciergb: {
name: 'CIE RGB',
gamma: 2.2,
rgb2xyz: {
e: [
[0.488718, 0.3106803, 0.2006017],
[0.1762044, 0.8129847, 0.0108109],
[0, 0.0102048, 0.9897952],
],
d50: [
[0.486887, 0.3062984, 0.1710347],
[0.1746583, 0.8247541, 0.0005877],
[-0.0012563, 0.0169832, 0.8094831],
],
},
xyz2rgb: {
e: [
[2.3706743, -0.9000405, -0.4706338],
[-0.513885, 1.4253036, 0.0885814],
[0.0052982, -0.0146949, 1.0093968],
],
d50: [
[2.3638081, -0.867603, -0.4988161],
[-0.500594, 1.3962369, 0.1047562],
[0.0141712, -0.03064, 1.2323842],
],
},
},
colormatchrgb: {
name: 'ColorMatch RGB',
gamma: 1.8,
rgb2xyz: {
d50: [
[0.5093439, 0.3209071, 0.1339691],
[0.274884, 0.6581315, 0.0669845],
[0.0242545, 0.1087821, 0.6921735],
],
},
xyz2rgb: {
d50: [
[2.6422874, -1.223427, -0.3930143],
[-1.1119763, 2.0590183, 0.0159614],
[0.0821699, -0.2807254, 1.4559877],
],
},
},
donrgb4: {
name: 'Don RGB 4',
gamma: 2.2,
rgb2xyz: {
d50: [
[0.6457711, 0.1933511, 0.1250978],
[0.2783496, 0.6879702, 0.0336802],
[0.0037113, 0.0179861, 0.8035125],
],
},
xyz2rgb: {
d50: [
[1.7603902, -0.4881198, -0.2536126],
[-0.7126288, 1.6527432, 0.0416715],
[0.0078207, -0.0347411, 1.2447743],
],
},
},
ecirgb: {
name: 'ECI RGB v2',
// gamma = L*
rgb2xyz: {
d50: [
[0.6502043, 0.1780774, 0.1359384],
[0.3202499, 0.6020711, 0.0776791],
[0, 0.067839, 0.757371],
],
},
xyz2rgb: {
d50: [
[1.7827618, -0.4969847, -0.2690101],
[-0.9593623, 1.9477962, -0.0275807],
[0.0859317, -0.1744674, 1.3228273],
],
},
},
ektaspaceps5: {
name: 'Ekta Space PS5',
gamma: 2.2,
rgb2xyz: {
d50: [
[0.5938914, 0.2729801, 0.0973485],
[0.2606286, 0.7349465, 0.0044249],
[0, 0.0419969, 0.7832131],
],
},
xyz2rgb: {
d50: [
[2.0043819, -0.7304844, -0.2450052],
[-0.7110285, 1.6202126, 0.0792227],
[0.0381263, -0.086878, 1.2725438],
],
},
},
ntscrgb: {
name: 'NTSC RGB',
gamma: 2.2,
rgb2xyz: {
c: [
[0.6068909, 0.1735011, 0.200348],
[0.2989164, 0.586599, 0.1144845],
[0, 0.0660957, 1.1162243],
],
d50: [
[0.6343706, 0.1852204, 0.144629],
[0.3109496, 0.5915984, 0.097452],
[-0.0011817, 0.0555518, 0.7708399],
],
},
xyz2rgb: {
c: [
[1.9099961, -0.5324542, -0.2882091],
[-0.9846663, 1.999171, -0.0283082],
[0.0583056, -0.1183781, 0.8975535],
],
d50: [
[1.8464881, -0.5521299, -0.2766458],
[-0.982663, 2.0044755, -0.0690396],
[0.0736477, -0.145302, 1.3018376],
],
},
},
palsecamrgb: {
name: 'PAL/SECAM RGB',
gamma: 2.2,
rgb2xyz: {
d65: [
[0.430619, 0.3415419, 0.1783091],
[0.2220379, 0.7066384, 0.0713236],
[0.0201853, 0.1295504, 0.9390944],
],
d50: [
[0.4552773, 0.36755, 0.1413926],
[0.2323025, 0.7077956, 0.0599019],
[0.0145457, 0.1049154, 0.7057489],
],
},
xyz2rgb: {
d65: [
[3.0628971, -1.3931791, -0.4757517],
[-0.969266, 1.8760108, 0.041556],
[0.0678775, -0.2288548, 1.069349],
],
d50: [
[2.9603944, -1.4678519, -0.4685105],
[-0.9787684, 1.9161415, 0.033454],
[0.0844874, -0.2545973, 1.4216174],
],
},
},
prophotorgb: {
name: 'ProPhoto RGB',
gamma: 1.8,
rgb2xyz: {
d50: [
[0.7976749, 0.1351917, 0.0313534],
[0.2880402, 0.7118741, 8.57e-5],
[0, 0, 0.82521],
],
},
xyz2rgb: {
d50: [
[1.3459433, -0.2556075, -0.0511118],
[-0.5445989, 1.5081673, 0.0205351],
[0, 0, 1.2118128],
],
},
},
smptecrgb: {
name: 'SMPTE-C RGB',
gamma: 2.2,
rgb2xyz: {
d65: [
[0.3935891, 0.3652497, 0.1916313],
[0.2124132, 0.7010437, 0.0865432],
[0.0187423, 0.1119313, 0.9581563],
],
d50: [
[0.416329, 0.3931464, 0.1547446],
[0.2216999, 0.7032549, 0.0750452],
[0.0136576, 0.0913604, 0.720192],
],
},
xyz2rgb: {
d65: [
[3.505396, -1.7394894, -0.543964],
[-1.0690722, 1.9778245, 0.0351722],
[0.05632, -0.1970226, 1.0502026],
],
d50: [
[3.392194, -1.8264027, -0.5385522],
[-1.0770996, 2.0213975, 0.0207989],
[0.0723073, -0.2217902, 1.3960932],
],
},
},
srgb: {
name: 'sRGB',
// sRGB companding / ~=2.2
rgb2xyz: {
d65: [
[0.4124564, 0.3575761, 0.1804375],
[0.2126729, 0.7151522, 0.072175],
[0.0193339, 0.119192, 0.9503041],
],
d50: [
[0.4360747, 0.3850649, 0.1430804],
[0.2225045, 0.7168786, 0.0606169],
[0.0139322, 0.0971045, 0.7141733],
],
},
xyz2rgb: {
d65: [
[3.2404542, -1.5371385, -0.4985314],
[-0.969266, 1.8760108, 0.041556],
[0.0556434, -0.2040259, 1.0572252],
],
d50: [
[3.1338561, -1.6168667, -0.4906146],
[-0.9787684, 1.9161415, 0.033454],
[0.0719453, -0.2289914, 1.4052427],
],
},
},
widegamutrgb: {
name: 'Wide Gamut RGB',
gamma: 2.2,
rgb2xyz: {
d50: [
[0.7161046, 0.1009296, 0.1471858],
[0.2581874, 0.7249378, 0.0168748],
[0, 0.0517813, 0.7734287],
],
},
xyz2rgb: {
d50: [
[1.4628067, -0.1840623, -0.2743606],
[-0.5217933, 1.4472381, 0.0677227],
[0.0349342, -0.096893, 1.2884099],
],
},
},
};
/**
* William T. Bridgman, NASA; Dan Bruton, SFASU. "RGB Values for Hot Objects". (2000)
* http://www.physics.sfasu.edu/astro/color/blackbodyc.txt
*
* CIE Color Matching Vectors (x_bar,y_bar,z_bar)
* for wavelenghts in 5 nm increments from 380 nm to 780 nm.
*/
exports.xyzWavelengths = {
gamma: 0.8,
chromaticityCoordinates: {
r: [0.64, 0.33],
g: [0.29, 0.6],
b: [0.15, 0.06],
w: [0.3127, 0.3291],
},
vectors: [
[0.0014, 0.0, 0.0065],
[0.0022, 0.0001, 0.0105],
[0.0042, 0.0001, 0.0201],
[0.0076, 0.0002, 0.0362],
[0.0143, 0.0004, 0.0679],
[0.0232, 0.0006, 0.1102],
[0.0435, 0.0012, 0.2074],
[0.0776, 0.0022, 0.3713],
[0.1344, 0.004, 0.6456],
[0.2148, 0.0073, 1.0391],
[0.2839, 0.0116, 1.3856],
[0.3285, 0.0168, 1.623],
[0.3483, 0.023, 1.7471],
[0.3481, 0.0298, 1.7826],
[0.3362, 0.038, 1.7721],
[0.3187, 0.048, 1.7441],
[0.2908, 0.06, 1.6692],
[0.2511, 0.0739, 1.5281],
[0.1954, 0.091, 1.2876],
[0.1421, 0.1126, 1.0419],
[0.0956, 0.139, 0.813],
[0.058, 0.1693, 0.6162],
[0.032, 0.208, 0.4652],
[0.0147, 0.2586, 0.3533],
[0.0049, 0.323, 0.272],
[0.0024, 0.4073, 0.2123],
[0.0093, 0.503, 0.1582],
[0.0291, 0.6082, 0.1117],
[0.0633, 0.71, 0.0782],
[0.1096, 0.7932, 0.0573],
[0.1655, 0.862, 0.0422],
[0.2257, 0.9149, 0.0298],
[0.2904, 0.954, 0.0203],
[0.3597, 0.9803, 0.0134],
[0.4334, 0.995, 0.0087],
[0.5121, 1.0, 0.0057],
[0.5945, 0.995, 0.0039],
[0.6784, 0.9786, 0.0027],
[0.7621, 0.952, 0.0021],
[0.8425, 0.9154, 0.0018],
[0.9163, 0.87, 0.0017],
[0.9786, 0.8163, 0.0014],
[1.0263, 0.757, 0.0011],
[1.0567, 0.6949, 0.001],
[1.0622, 0.631, 0.0008],
[1.0456, 0.5668, 0.0006],
[1.0026, 0.503, 0.0003],
[0.9384, 0.4412, 0.0002],
[0.8544, 0.381, 0.0002],
[0.7514, 0.321, 0.0001],
[0.6424, 0.265, 0.0],
[0.5419, 0.217, 0.0],
[0.4479, 0.175, 0.0],
[0.3608, 0.1382, 0.0],
[0.2835, 0.107, 0.0],
[0.2187, 0.0816, 0.0],
[0.1649, 0.061, 0.0],
[0.1212, 0.0446, 0.0],
[0.0874, 0.032, 0.0],
[0.0636, 0.0232, 0.0],
[0.0468, 0.017, 0.0],
[0.0329, 0.0119, 0.0],
[0.0227, 0.0082, 0.0],
[0.0158, 0.0057, 0.0],
[0.0114, 0.0041, 0.0],
[0.0081, 0.0029, 0.0],
[0.0058, 0.0021, 0.0],
[0.0041, 0.0015, 0.0],
[0.0029, 0.001, 0.0],
[0.002, 0.0007, 0.0],
[0.0014, 0.0005, 0.0],
[0.001, 0.0004, 0.0],
[0.0007, 0.0002, 0.0],
[0.0005, 0.0002, 0.0],
[0.0003, 0.0001, 0.0],
[0.0002, 0.0001, 0.0],
[0.0002, 0.0001, 0.0],
[0.0001, 0.0, 0.0],
[0.0001, 0.0, 0.0],
[0.0001, 0.0, 0.0],
[0.0, 0.0, 0.0],
],
};