Sha256: bd1911fd7a87083d552240a07c6c1bd50d3cc87380ab6829eb50695c50369afd

Contents?: true

Size: 1.14 KB

Versions: 26

Compression:

Stored size: 1.14 KB

Contents

import { matrix } from './util';

/* Convert between RGB and XYZ
/* ========================================================================== */

export function rgb2xyz(rgbR, rgbG, rgbB) {
	const [ lrgbR, lrgbB, lrgbG ] = [ rgbR, rgbG, rgbB ].map(
		v => v > 4.045 ? Math.pow((v + 5.5) / 105.5, 2.4) * 100 : v / 12.92
	);

	const [ xyzX, xyzY, xyzZ ] = matrix([ lrgbR, lrgbB, lrgbG ], [
		[0.4124564, 0.3575761, 0.1804375],
		[0.2126729, 0.7151522, 0.0721750],
		[0.0193339, 0.1191920, 0.9503041]
	]);

	return [ xyzX, xyzY, xyzZ ];
}

export function xyz2rgb(xyzX, xyzY, xyzZ) {
	const [ lrgbR, lrgbB, lrgbG ] = matrix([ xyzX, xyzY, xyzZ ], [
		[ 3.2404542, -1.5371385, -0.4985314],
		[-0.9692660,  1.8760108,  0.0415560],
		[ 0.0556434, -0.2040259,  1.0572252]
	]);

	const [ rgbR, rgbG, rgbB ] = [ lrgbR, lrgbB, lrgbG ].map(
		v => v > 0.31308 ? 1.055 * Math.pow(v / 100, 1 / 2.4) * 100 - 5.5 : 12.92 * v
	);

	return [ rgbR, rgbG, rgbB ];
}

/*

References
----------

- https://www.w3.org/TR/css-color-4/#rgb-to-lab
- https://www.w3.org/TR/css-color-4/#color-conversion-code

/* ========================================================================== */

Version data entries

26 entries across 25 versions & 8 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/@csstools/convert-colors/lib/rgb-xyz.js
disco_app-0.18.0 test/dummy/node_modules/@csstools/convert-colors/lib/rgb-xyz.js
disco_app-0.18.2 test/dummy/node_modules/@csstools/convert-colors/lib/rgb-xyz.js
disco_app-0.16.1 test/dummy/node_modules/@csstools/convert-colors/lib/rgb-xyz.js
disco_app-0.15.2 test/dummy/node_modules/@csstools/convert-colors/lib/rgb-xyz.js
disco_app-0.18.4 test/dummy/node_modules/@csstools/convert-colors/lib/rgb-xyz.js
disco_app-0.18.1 test/dummy/node_modules/@csstools/convert-colors/lib/rgb-xyz.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/@csstools/convert-colors/lib/rgb-xyz.js
disco_app-0.14.0 test/dummy/node_modules/@csstools/convert-colors/lib/rgb-xyz.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/@csstools/convert-colors/lib/rgb-xyz.js
tang-0.2.1 spec/tang_app/node_modules/@csstools/convert-colors/lib/rgb-xyz.js
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/@csstools/convert-colors/lib/rgb-xyz.js
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/@csstools/convert-colors/lib/rgb-xyz.js
ruby2js-4.0.4 lib/tasks/testrails/node_modules/@csstools/convert-colors/lib/rgb-xyz.js
ruby2js-4.0.3 lib/tasks/testrails/node_modules/@csstools/convert-colors/lib/rgb-xyz.js
tang-0.2.0 spec/tang_app/node_modules/@csstools/convert-colors/lib/rgb-xyz.js
tang-0.1.0 spec/tang_app/node_modules/@csstools/convert-colors/lib/rgb-xyz.js
tang-0.0.9 spec/tang_app/node_modules/@csstools/convert-colors/lib/rgb-xyz.js
enju_library-0.3.8 spec/dummy/node_modules/@csstools/convert-colors/lib/rgb-xyz.js
jester-data-8.0.0 node_modules/@csstools/convert-colors/lib/rgb-xyz.js