@atlaskit/tokens
Version:
Design tokens are the single source of truth to name and store design decisions.
20 lines (19 loc) • 596 B
JavaScript
import * as mathUtils from './math-utils';
/**
* Delinearizes an RGB component.
*
* @param rgbComponent 0.0 <= rgb_component <= 100.0, represents
* linear R/G/B channel
* @return 0 <= output <= 255, color channel converted to regular
* RGB space
*/
export function delinearized(rgbComponent) {
var normalized = rgbComponent / 100.0;
var delinearized = 0.0;
if (normalized <= 0.0031308) {
delinearized = normalized * 12.92;
} else {
delinearized = 1.055 * Math.pow(normalized, 1.0 / 2.4) - 0.055;
}
return mathUtils.clampInt(0, 255, Math.round(delinearized * 255.0));
}