UNPKG

molstar

Version:

A comprehensive macromolecular library.

106 lines 3.16 kB
"use strict"; /** * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose <alexander.rose@weirdbyte.de> * * Color conversion code adapted from chroma.js (https://github.com/gka/chroma.js) * Copyright (c) 2011-2018, Gregor Aisch, BSD license */ Object.defineProperty(exports, "__esModule", { value: true }); exports.Hcl = void 0; var misc_1 = require("../../../mol-math/misc"); var lab_1 = require("./lab"); /** * CIE HCL (Hue-Chroma-Luminance) color * * - H [0..360] * - C [0..100] * - L [0..100] * * Cylindrical representation of CIELUV (see https://en.wikipedia.org/wiki/CIELUV) */ function Hcl() { return Hcl.zero(); } exports.Hcl = Hcl; (function (Hcl) { function zero() { var out = [0.1, 0.0, 0.0]; out[0] = 0; return out; } Hcl.zero = zero; function create(h, c, l) { var out = zero(); out[0] = h; out[1] = c; out[2] = l; return out; } Hcl.create = create; var tmpFromColorLab = [0, 0, 0]; function fromColor(out, color) { return lab_1.Lab.toHcl(out, lab_1.Lab.fromColor(tmpFromColorLab, color)); } Hcl.fromColor = fromColor; function fromLab(hcl, lab) { return lab_1.Lab.toHcl(hcl, lab); } Hcl.fromLab = fromLab; var tmpToColorLab = [0, 0, 0]; function toColor(hcl) { return lab_1.Lab.toColor(toLab(tmpToColorLab, hcl)); } Hcl.toColor = toColor; /** * Convert from a qualitative parameter h and a quantitative parameter l to a 24-bit pixel. * * These formulas were invented by David Dalrymple to obtain maximum contrast without going * out of gamut if the parameters are in the range 0-1. * A saturation multiplier was added by Gregor Aisch */ function toLab(out, hcl) { var h = hcl[0], c = hcl[1], l = hcl[2]; if (isNaN(h)) h = 0; h = (0, misc_1.degToRad)(h); out[0] = l; out[1] = Math.cos(h) * c; out[2] = Math.sin(h) * c; return out; } Hcl.toLab = toLab; function copy(out, c) { out[0] = c[0]; out[1] = c[1]; out[2] = c[2]; return out; } Hcl.copy = copy; function saturate(out, c, amount) { out[0] = c[0]; out[1] = Math.max(0, c[1] + Kn * amount); out[2] = c[2]; return out; } Hcl.saturate = saturate; function desaturate(out, c, amount) { return saturate(out, c, -amount); } Hcl.desaturate = desaturate; var tmpDarkenLab = [0, 0, 0]; function darken(out, c, amount) { toLab(tmpDarkenLab, c); return lab_1.Lab.toHcl(out, lab_1.Lab.darken(tmpDarkenLab, tmpDarkenLab, amount)); } Hcl.darken = darken; function lighten(out, c, amount) { return darken(out, c, -amount); } Hcl.lighten = lighten; // Corresponds roughly to RGB brighter/darker var Kn = 18; })(Hcl || (Hcl = {})); exports.Hcl = Hcl; //# sourceMappingURL=hcl.js.map