Sha256: 9c9b23a6e6834b401008b1a87136766573a8bad4f590cab5fe9aba81c29019f1

Contents?: true

Size: 880 Bytes

Versions: 26

Compression:

Stored size: 880 Bytes

Contents

import { rgb2hue, rgb2whiteness, rgb2value } from './util';
import { hsl2rgb } from './rgb-hsl';

/* Convert between RGB and HWB
/* ========================================================================== */

export function rgb2hwb(rgbR, rgbG, rgbB, fallbackhue) {
	const hwbH = rgb2hue(rgbR, rgbG, rgbB, fallbackhue);
	const hwbW = rgb2whiteness(rgbR, rgbG, rgbB);
	const hwbV = rgb2value(rgbR, rgbG, rgbB);
	const hwbB = 100 - hwbV;

	return [hwbH, hwbW, hwbB];
}

export function hwb2rgb(hwbH, hwbW, hwbB, fallbackhue) {
	const [ rgbR, rgbG, rgbB ] = hsl2rgb(hwbH, 100, 50, fallbackhue).map(
		v => v * (100 - hwbW - hwbB) / 100 + hwbW
	);

	return [ rgbR, rgbG, rgbB ];
}

/*

References
----------

- https://www.w3.org/TR/css-color-4/#hwb-to-rgb
- http://alvyray.com/Papers/CG/hwb2rgb.htm

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

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-hwb.js
disco_app-0.18.0 test/dummy/node_modules/@csstools/convert-colors/lib/rgb-hwb.js
disco_app-0.18.2 test/dummy/node_modules/@csstools/convert-colors/lib/rgb-hwb.js
disco_app-0.16.1 test/dummy/node_modules/@csstools/convert-colors/lib/rgb-hwb.js
disco_app-0.15.2 test/dummy/node_modules/@csstools/convert-colors/lib/rgb-hwb.js
disco_app-0.18.4 test/dummy/node_modules/@csstools/convert-colors/lib/rgb-hwb.js
disco_app-0.18.1 test/dummy/node_modules/@csstools/convert-colors/lib/rgb-hwb.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/@csstools/convert-colors/lib/rgb-hwb.js
disco_app-0.14.0 test/dummy/node_modules/@csstools/convert-colors/lib/rgb-hwb.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/@csstools/convert-colors/lib/rgb-hwb.js
tang-0.2.1 spec/tang_app/node_modules/@csstools/convert-colors/lib/rgb-hwb.js
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/@csstools/convert-colors/lib/rgb-hwb.js
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/@csstools/convert-colors/lib/rgb-hwb.js
ruby2js-4.0.4 lib/tasks/testrails/node_modules/@csstools/convert-colors/lib/rgb-hwb.js
ruby2js-4.0.3 lib/tasks/testrails/node_modules/@csstools/convert-colors/lib/rgb-hwb.js
tang-0.2.0 spec/tang_app/node_modules/@csstools/convert-colors/lib/rgb-hwb.js
tang-0.1.0 spec/tang_app/node_modules/@csstools/convert-colors/lib/rgb-hwb.js
tang-0.0.9 spec/tang_app/node_modules/@csstools/convert-colors/lib/rgb-hwb.js
enju_library-0.3.8 spec/dummy/node_modules/@csstools/convert-colors/lib/rgb-hwb.js
jester-data-8.0.0 node_modules/@csstools/convert-colors/lib/rgb-hwb.js