(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.colorimetry = {})); })(this, (function (exports) { 'use strict'; class Rgb { constructor(red, green, blue) { this._r = Rgb.Min; this._g = Rgb.Min; this._b = Rgb.Min; this.r = red; this.b = blue; this.g = green; } get r() { return this._r; } set r(value) { this._r = value > Rgb.Max ? Rgb.Max : value < Rgb.Min ? Rgb.Min : value; } get g() { return this._g; } set g(value) { this._g = value > Rgb.Max ? Rgb.Max : value < Rgb.Min ? Rgb.Min : value; } get b() { return this._b; } set b(value) { this._b = value > Rgb.Max ? Rgb.Max : value < Rgb.Min ? Rgb.Min : value; } equals(obj) { return this._r === obj.r && this._g === obj.g && this._b === obj.b; } } Rgb.Min = 0; Rgb.Max = 255; class Hsb { constructor(hue, saturation, brightness) { this._h = Hsb.HueMin; this._s = Hsb.Min; this._b = Hsb.Min; this.h = hue; this.s = saturation; this.b = brightness; } get h() { return this._h; } set h(value) { this._h = value > Hsb.HueMax ? Hsb.HueMax : value < Hsb.HueMin ? Hsb.HueMin : value; } get s() { return this._s; } set s(value) { this._s = value > Hsb.Max ? Hsb.Max : value < Hsb.Min ? Hsb.Min : value; } get b() { return this._b; } set b(value) { this._b = value > Hsb.Max ? Hsb.Max : value < Hsb.Min ? Hsb.Min : value; } equals(obj) { return this._h === obj.h && this._s === obj.s && this._b === obj.b; } } Hsb.Min = 0; Hsb.Max = 1; Hsb.HueMin = 0; Hsb.HueMax = 360; class Hsl { constructor(hue, saturation, lightness) { this._h = Hsl.HueMin; this._s = Hsl.Min; this._l = Hsl.Min; this.h = hue; this.s = saturation; this.l = lightness; } get h() { return this._h; } set h(value) { this._h = value > Hsl.HueMax ? Hsl.HueMax : value < Hsl.HueMin ? Hsl.HueMin : value; } get s() { return this._s; } set s(value) { this._s = value > Hsl.Max ? Hsl.Max : value < Hsl.Min ? Hsl.Min : value; } get l() { return this._l; } set l(value) { this._l = value > Hsl.Max ? Hsl.Max : value < Hsl.Min ? Hsl.Min : value; } equals(obj) { return this._h === obj.h && this._s === obj.s && this._l === obj.l; } } Hsl.Min = 0; Hsl.Max = 1; Hsl.HueMin = 0; Hsl.HueMax = 360; class Cmyk { constructor(cyan, magenta, yellow, black) { this._c = Cmyk.Min; this._m = Cmyk.Min; this._y = Cmyk.Min; this._k = Cmyk.Min; this.c = cyan; this.m = magenta; this.y = yellow; this.k = black; } get c() { return this._c; } set c(value) { this._c = value > Cmyk.Max ? Cmyk.Max : value < Cmyk.Min ? Cmyk.Min : value; } get m() { return this._m; } set m(value) { this._m = value > Cmyk.Max ? Cmyk.Max : value < Cmyk.Min ? Cmyk.Min : value; } get y() { return this._y; } set y(value) { this._y = value > Cmyk.Max ? Cmyk.Max : value < Cmyk.Min ? Cmyk.Min : value; } get k() { return this._k; } set k(value) { this._k = value > Cmyk.Max ? Cmyk.Max : value < Cmyk.Min ? Cmyk.Min : value; } equals(obj) { return (this._c === obj.c && this._m === obj.m && this._y === obj.y && this._k === obj.k); } } Cmyk.Min = 0; Cmyk.Max = 1; class YuvProfile { constructor(uMax, vMax, yuvMatrix, rgbMatrix, offset = [0, 0, 0]) { this._uMax = uMax; this._vMax = vMax; this._yuvMatrix = yuvMatrix; this._rgbMatrix = rgbMatrix; this._offset = offset; } get uMin() { return -this._uMax; } get uMax() { return this._uMax; } get vMin() { return -this._vMax; } get vMax() { return this._vMax; } get yuvMatrix() { return this._yuvMatrix; } get rgbMatrix() { return this._rgbMatrix; } get offset() { return this._offset; } } YuvProfile.BT_470 = new YuvProfile(0.436, 0.615, [ [0.299, 0.587, 0.114], [-0.14713, -0.28886, 0.436], [0.615, -0.51499, -0.10001], ], [ [1, 0, 1.13983], [1, -0.39465, -0.5806], [1, 2.03211, 0], ]); YuvProfile.BT_601 = new YuvProfile(0.5, 0.5, [ [0.299, 0.587, 0.114], [-0.168736, -0.331264, 0.5], [0.5, -0.418688, -0.081312], ], [ [1.1643, 0, 1.596], [1.1643, -0.39176, -0.81296], [1.1643, 2.01723, 0], ], [-0.0627, -0.5, -0.5]); YuvProfile.BT_709 = new YuvProfile(0.436, 0.615, [ [0.2126, 0.7152, 0.0722], [-0.09991, -0.33609, 0.436], [0.615, -0.55861, -0.05639], ], [ [1, 0, 1.28033], [1, -0.21482, -0.38059], [1, 2.12798, 0], ]); class Yuv { constructor(y, u, v, p = YuvProfile.BT_470) { this._p = YuvProfile.BT_470; this._y = 0; this._u = -YuvProfile.BT_470.uMax; this._v = -YuvProfile.BT_470.vMax; this._p = p; this.y = y; this.u = u; this.v = v; } get y() { return this._y; } set y(value) { this._y = value > 1 ? 1 : value < 0 ? 0 : value; } get u() { return this._u; } set u(value) { this._u = value > this._p.uMax ? this._p.uMax : value < this._p.uMin ? this._p.uMin : value; } get v() { return this._v; } set v(value) { this._v = value > this._p.vMax ? this._p.vMax : value < this._p.vMin ? this._p.vMin : value; } equals(obj) { return this._y === obj.y && this._u === obj.u && this._v === obj.v; } } class CieXyz { constructor(x, y, z, w = CieXyz.D65) { this._x = CieXyz.Min; this._y = CieXyz.Min; this._z = CieXyz.Min; this._w = [...w]; this.x = x; this.y = y; this.z = z; } get x() { return this._x; } set x(value) { this._x = value > this._w[0] ? this._w[0] : value < CieXyz.Min ? CieXyz.Min : value; } get y() { return this._y; } set y(value) { this._y = value > this._w[1] ? this._w[1] : value < CieXyz.Min ? CieXyz.Min : value; } get z() { return this._z; } set z(value) { this._z = value > this._w[2] ? this._w[2] : value < CieXyz.Min ? CieXyz.Min : value; } equals(obj) { return this._x === obj.y && this._y === obj.y && this._z === obj.z; } } CieXyz.Min = 0; CieXyz.D65 = [0.9505, 1.0, 1.089]; exports.ConverterUtils = void 0; (function (ConverterUtils) { function roundInt(value, fractionDigits = 2) { return Math.round(Number.parseFloat(value.toFixed(fractionDigits))); } ConverterUtils.roundInt = roundInt; })(exports.ConverterUtils || (exports.ConverterUtils = {})); exports.RgbConverter = void 0; (function (RgbConverter) { function padHex(value) { return value.toString(16).padStart(2, "0"); } function RgbToHex(rgb) { return `#${padHex(rgb.r)}${padHex(rgb.g)}${padHex(rgb.b)}`; } RgbConverter.RgbToHex = RgbToHex; function getHsbFromRgb(red, green, blue) { const r = red / 255.0; const g = green / 255.0; const b = blue / 255.0; const max = Math.max(r, Math.max(g, b)); const min = Math.min(r, Math.min(g, b)); let h = 0.0; if (max == r && g >= b) { h = max - min !== 0 ? (60 * (g - b)) / (max - min) : 0; } else if (max == r && g < b) { h = (60 * (g - b)) / (max - min) + 360; } else if (max == g) { h = (60 * (b - r)) / (max - min) + 120; } else if (max == b) { h = (60 * (r - g)) / (max - min) + 240; } const s = max == 0 ? 0.0 : 1.0 - min / max; return [h, s, max]; } RgbConverter.getHsbFromRgb = getHsbFromRgb; function RgbToHsb(rgb) { const values = getHsbFromRgb(rgb.r, rgb.g, rgb.b); return new Hsb(values[0], values[1], values[2]); } RgbConverter.RgbToHsb = RgbToHsb; function getHslFromRgb(red, green, blue) { const r = red / 255.0; const g = green / 255.0; const b = blue / 255.0; const max = Math.max(r, Math.max(g, b)); const min = Math.min(r, Math.min(g, b)); let h = 0, s = 0, l = 0; if (max == r && g >= b) { h = max - min !== 0 ? (h = (60.0 * (g - b)) / (max - min)) : 0; } else if (max == r && g < b) { h = (60.0 * (g - b)) / (max - min) + 360.0; } else if (max == g) { h = (60.0 * (b - r)) / (max - min) + 120.0; } else if (max == b) { h = (60.0 * (r - g)) / (max - min) + 240.0; } l = (max + min) / 2.0; if (l == 0 || max == min) { s = 0; } else if (0 < l && l <= 0.5) { s = (max - min) / (max + min); } else if (l > 0.5) { s = (max - min) / (2 - (max + min)); } return [h, s, l]; } RgbConverter.getHslFromRgb = getHslFromRgb; function RgbToHsl(rgb) { const values = getHslFromRgb(rgb.r, rgb.g, rgb.b); return new Hsl(values[0], values[1], values[2]); } RgbConverter.RgbToHsl = RgbToHsl; function getCmykFromRgb(red, green, blue) { const c = (255 - red) / 255; const m = (255 - green) / 255; const y = (255 - blue) / 255; const k = Math.min(c, Math.min(m, y)); if (k == 1.0) { return [0, 0, 0, 1]; } return [(c - k) / (1 - k), (m - k) / (1 - k), (y - k) / (1 - k), k]; } RgbConverter.getCmykFromRgb = getCmykFromRgb; function RgbToCmyk(rgb) { const values = getCmykFromRgb(rgb.r, rgb.g, rgb.b); return new Cmyk(values[0], values[1], values[2], values[3]); } RgbConverter.RgbToCmyk = RgbToCmyk; function getYuvFromRgb(red, green, blue, profile = YuvProfile.BT_470) { const r = red / 255.0; const g = green / 255.0; const b = blue / 255.0; const matrix = profile.yuvMatrix; const y = matrix[0][0] * r + matrix[0][1] * g + matrix[0][2] * b; const u = matrix[1][0] * r + matrix[1][1] * g + matrix[1][2] * b; const v = matrix[2][0] * r + matrix[2][1] * g + matrix[2][2] * b; return [y, u, v]; } RgbConverter.getYuvFromRgb = getYuvFromRgb; function RgbToYuv(rgb, profile = YuvProfile.BT_470) { const values = getYuvFromRgb(rgb.r, rgb.g, rgb.b, profile); return new Yuv(values[0], values[1], values[2]); } RgbConverter.RgbToYuv = RgbToYuv; function getCieXyzFromRgb(red, green, blue) { const rLinear = red / 255.0; const gLinear = green / 255.0; const bLinear = blue / 255.0; const r = rLinear > 0.04045 ? Math.pow((rLinear + 0.055) / (1 + 0.055), 2.4) : rLinear / 12.92; const g = gLinear > 0.04045 ? Math.pow((gLinear + 0.055) / (1 + 0.055), 2.4) : gLinear / 12.92; const b = bLinear > 0.04045 ? Math.pow((bLinear + 0.055) / (1 + 0.055), 2.4) : bLinear / 12.92; return [ r * 0.4124 + g * 0.3576 + b * 0.1805, r * 0.2126 + g * 0.7152 + b * 0.0722, r * 0.0193 + g * 0.1192 + b * 0.9505, ]; } RgbConverter.getCieXyzFromRgb = getCieXyzFromRgb; function RgbToCieXyz(rgb) { const values = getCieXyzFromRgb(rgb.r, rgb.g, rgb.b); return new CieXyz(values[0], values[1], values[2]); } RgbConverter.RgbToCieXyz = RgbToCieXyz; })(exports.RgbConverter || (exports.RgbConverter = {})); exports.HexConverter = void 0; (function (HexConverter) { function HexToRgb(hex) { const radix = 16; if (hex.length === 4) { return new Rgb(parseInt(`${hex[1]}${hex[1]}`, radix), parseInt(`${hex[2]}${hex[2]}`, radix), parseInt(`${hex[3]}${hex[3]}`, radix)); } return new Rgb(parseInt(`${hex[1]}${hex[2]}`, radix), parseInt(`${hex[3]}${hex[4]}`, radix), parseInt(`${hex[5]}${hex[6]}`, radix)); } HexConverter.HexToRgb = HexToRgb; function HexToHsb(hex) { return exports.RgbConverter.RgbToHsb(HexToRgb(hex)); } HexConverter.HexToHsb = HexToHsb; function HexToHsl(hex) { return exports.RgbConverter.RgbToHsl(HexToRgb(hex)); } HexConverter.HexToHsl = HexToHsl; function HexToCmyk(hex) { return exports.RgbConverter.RgbToCmyk(HexToRgb(hex)); } HexConverter.HexToCmyk = HexToCmyk; function HexToYuv(hex, profile = YuvProfile.BT_470) { return exports.RgbConverter.RgbToYuv(HexToRgb(hex), profile); } HexConverter.HexToYuv = HexToYuv; function HexToCieXyz(hex) { return exports.RgbConverter.RgbToCieXyz(HexToRgb(hex)); } HexConverter.HexToCieXyz = HexToCieXyz; })(exports.HexConverter || (exports.HexConverter = {})); exports.HsbConverter = void 0; (function (HsbConverter) { function getRgbFromHsb(hue, saturation, brightness) { if (saturation === 0) { return [ exports.ConverterUtils.roundInt(brightness * 255.0), exports.ConverterUtils.roundInt(brightness * 255.0), exports.ConverterUtils.roundInt(brightness * 255.0), ]; } const sectorPos = hue / 60.0; const sectorNumber = parseInt(`${Math.floor(sectorPos)}`); const fractionalSector = sectorPos - sectorNumber; const p = brightness * (1.0 - saturation); const q = brightness * (1.0 - saturation * fractionalSector); const t = brightness * (1.0 - saturation * (1 - fractionalSector)); let r = 0; let g = 0; let b = 0; switch (sectorNumber) { case 0: r = brightness; g = t; b = p; break; case 1: r = q; g = brightness; b = p; break; case 2: r = p; g = brightness; b = t; break; case 3: r = p; g = q; b = brightness; break; case 4: r = t; g = p; b = brightness; break; case 5: r = brightness; g = p; b = q; break; } return [ exports.ConverterUtils.roundInt(r * 255.0), exports.ConverterUtils.roundInt(g * 255.0), exports.ConverterUtils.roundInt(b * 255.0), ]; } HsbConverter.getRgbFromHsb = getRgbFromHsb; function HsbToHex(hsb) { const rgbs = getRgbFromHsb(hsb.h, hsb.s, hsb.b); return exports.RgbConverter.RgbToHex(new Rgb(rgbs[0], rgbs[1], rgbs[2])); } HsbConverter.HsbToHex = HsbToHex; function HsbToRgb(hsb) { const rgbs = getRgbFromHsb(hsb.h, hsb.s, hsb.b); return new Rgb(rgbs[0], rgbs[1], rgbs[2]); } HsbConverter.HsbToRgb = HsbToRgb; function HsbToHsl(hsb) { const rgbs = getRgbFromHsb(hsb.h, hsb.s, hsb.b); const hsls = exports.RgbConverter.getHslFromRgb(rgbs[0], rgbs[1], rgbs[2]); return new Hsl(hsls[0], hsls[1], hsls[2]); } HsbConverter.HsbToHsl = HsbToHsl; function HsbToCmyk(hsb) { const rgbs = getRgbFromHsb(hsb.h, hsb.s, hsb.b); const cmyks = exports.RgbConverter.getCmykFromRgb(rgbs[0], rgbs[1], rgbs[2]); return new Cmyk(cmyks[0], cmyks[1], cmyks[2], cmyks[3]); } HsbConverter.HsbToCmyk = HsbToCmyk; function HsbToYuv(hsb, profile = YuvProfile.BT_470) { const rgbs = getRgbFromHsb(hsb.h, hsb.s, hsb.b); const yuvs = exports.RgbConverter.getYuvFromRgb(rgbs[0], rgbs[1], rgbs[2], profile); return new Yuv(yuvs[0], yuvs[1], yuvs[2]); } HsbConverter.HsbToYuv = HsbToYuv; function HsbToCieXyz(hsb) { const rgbs = getRgbFromHsb(hsb.h, hsb.s, hsb.b); const cies = exports.RgbConverter.getCieXyzFromRgb(rgbs[0], rgbs[1], rgbs[2]); return new CieXyz(cies[0], cies[1], cies[2]); } HsbConverter.HsbToCieXyz = HsbToCieXyz; })(exports.HsbConverter || (exports.HsbConverter = {})); exports.HslConverter = void 0; (function (HslConverter) { function getRgbFromHsl(hue, saturation, luminance) { if (saturation === 0) { return [ exports.ConverterUtils.roundInt(luminance * 255.0), exports.ConverterUtils.roundInt(luminance * 255.0), exports.ConverterUtils.roundInt(luminance * 255.0), ]; } const q = luminance < 0.5 ? luminance * (1.0 + saturation) : luminance + saturation - luminance * saturation; const p = 2.0 * luminance - q; const Hk = hue / 360.0; const T = new Array(3); T[0] = Hk + 1.0 / 3.0; T[1] = Hk; T[2] = Hk - 1.0 / 3.0; for (let i = 0; i < 3; i++) { if (T[i] < 0) T[i] += 1.0; if (T[i] > 1) T[i] -= 1.0; if (T[i] * 6 < 1) { T[i] = p + (q - p) * 6.0 * T[i]; } else if (T[i] * 2.0 < 1) { T[i] = q; } else if (T[i] * 3.0 < 2) { T[i] = p + (q - p) * (2.0 / 3.0 - T[i]) * 6.0; } else T[i] = p; } return [ exports.ConverterUtils.roundInt(T[0] * 255.0), exports.ConverterUtils.roundInt(T[1] * 255.0), exports.ConverterUtils.roundInt(T[2] * 255.0), ]; } HslConverter.getRgbFromHsl = getRgbFromHsl; function HslToHex(hsl) { const rgbs = getRgbFromHsl(hsl.h, hsl.s, hsl.l); return exports.RgbConverter.RgbToHex(new Rgb(rgbs[0], rgbs[1], rgbs[2])); } HslConverter.HslToHex = HslToHex; function HslToRgb(hsl) { const rgbs = getRgbFromHsl(hsl.h, hsl.s, hsl.l); return new Rgb(rgbs[0], rgbs[1], rgbs[2]); } HslConverter.HslToRgb = HslToRgb; function HslToHsb(hsl) { const rgbs = getRgbFromHsl(hsl.h, hsl.s, hsl.l); const hsbs = exports.RgbConverter.getHsbFromRgb(rgbs[0], rgbs[1], rgbs[2]); return new Hsb(hsbs[0], hsbs[1], hsbs[2]); } HslConverter.HslToHsb = HslToHsb; function HslToCmyk(hsl) { const rgbs = getRgbFromHsl(hsl.h, hsl.s, hsl.l); const cmyks = exports.RgbConverter.getCmykFromRgb(rgbs[0], rgbs[1], rgbs[2]); return new Cmyk(cmyks[0], cmyks[1], cmyks[2], cmyks[3]); } HslConverter.HslToCmyk = HslToCmyk; function HslToYuv(hsl, profile = YuvProfile.BT_470) { const rgbs = getRgbFromHsl(hsl.h, hsl.s, hsl.l); const yuvs = exports.RgbConverter.getYuvFromRgb(rgbs[0], rgbs[1], rgbs[2], profile); return new Yuv(yuvs[0], yuvs[1], yuvs[2]); } HslConverter.HslToYuv = HslToYuv; function HslToCieXyz(hsl) { const rgbs = getRgbFromHsl(hsl.h, hsl.s, hsl.l); const cies = exports.RgbConverter.getCieXyzFromRgb(rgbs[0], rgbs[1], rgbs[2]); return new CieXyz(cies[0], cies[1], cies[2]); } HslConverter.HslToCieXyz = HslToCieXyz; })(exports.HslConverter || (exports.HslConverter = {})); exports.CmykConverter = void 0; (function (CmykConverter) { function getRgbFromCmyk(cyan, magenta, yellow, black) { const red = (1 - cyan) * (1 - black); const green = (1 - magenta) * (1 - black); const blue = (1 - yellow) * (1 - black); return [ exports.ConverterUtils.roundInt(red * 255.0), exports.ConverterUtils.roundInt(green * 255.0), exports.ConverterUtils.roundInt(blue * 255.0), ]; } CmykConverter.getRgbFromCmyk = getRgbFromCmyk; function CmykToHex(cmyk) { const rgbs = getRgbFromCmyk(cmyk.c, cmyk.m, cmyk.y, cmyk.k); return exports.RgbConverter.RgbToHex(new Rgb(rgbs[0], rgbs[1], rgbs[2])); } CmykConverter.CmykToHex = CmykToHex; function CmykToRgb(cmyk) { const rgbs = getRgbFromCmyk(cmyk.c, cmyk.m, cmyk.y, cmyk.k); return new Rgb(rgbs[0], rgbs[1], rgbs[2]); } CmykConverter.CmykToRgb = CmykToRgb; function CmykToHsl(cmyk) { const rgbs = getRgbFromCmyk(cmyk.c, cmyk.m, cmyk.y, cmyk.k); const hsls = exports.RgbConverter.getHslFromRgb(rgbs[0], rgbs[1], rgbs[2]); return new Hsl(hsls[0], hsls[1], hsls[2]); } CmykConverter.CmykToHsl = CmykToHsl; function CmykToHsb(cmyk) { const rgbs = getRgbFromCmyk(cmyk.c, cmyk.m, cmyk.y, cmyk.k); const hsbs = exports.RgbConverter.getHsbFromRgb(rgbs[0], rgbs[1], rgbs[2]); return new Hsb(hsbs[0], hsbs[1], hsbs[2]); } CmykConverter.CmykToHsb = CmykToHsb; function CmykToYuv(cmyk) { const rgbs = getRgbFromCmyk(cmyk.c, cmyk.m, cmyk.y, cmyk.k); const yuvs = exports.RgbConverter.getYuvFromRgb(rgbs[0], rgbs[1], rgbs[2]); return new Yuv(yuvs[0], yuvs[1], yuvs[2]); } CmykConverter.CmykToYuv = CmykToYuv; function CmykToCieXyz(cmyk) { const rgbs = getRgbFromCmyk(cmyk.c, cmyk.m, cmyk.y, cmyk.k); const cies = exports.RgbConverter.getCieXyzFromRgb(rgbs[0], rgbs[1], rgbs[2]); return new CieXyz(cies[0], cies[1], cies[2]); } CmykConverter.CmykToCieXyz = CmykToCieXyz; })(exports.CmykConverter || (exports.CmykConverter = {})); exports.YuvConverter = void 0; (function (YuvConverter) { function getRgbFromYuv(y, u, v, profile = YuvProfile.BT_470) { const matrix = profile.rgbMatrix; const offset = profile.offset; const r = matrix[0][0] * (y + offset[0]) + matrix[0][1] * (u + offset[1]) + matrix[0][2] * (v + offset[2]); const g = matrix[1][0] * (y + offset[0]) + matrix[1][1] * (u + offset[1]) + matrix[1][2] * (v + offset[2]); const b = matrix[2][0] * (y + offset[0]) + matrix[2][1] * (u + offset[1]) + matrix[2][2] * (v + offset[2]); return [ exports.ConverterUtils.roundInt(r * 255.0), exports.ConverterUtils.roundInt(g * 255.0), exports.ConverterUtils.roundInt(b * 255.0), ]; } YuvConverter.getRgbFromYuv = getRgbFromYuv; function YuvToHex(yuv) { const rgbs = getRgbFromYuv(yuv.y, yuv.u, yuv.v); return exports.RgbConverter.RgbToHex(new Rgb(rgbs[0], rgbs[1], rgbs[2])); } YuvConverter.YuvToHex = YuvToHex; function YuvToRgb(yuv) { const rgbs = getRgbFromYuv(yuv.y, yuv.u, yuv.v); return new Rgb(rgbs[0], rgbs[1], rgbs[2]); } YuvConverter.YuvToRgb = YuvToRgb; function YuvToHsl(yuv) { const rgbs = getRgbFromYuv(yuv.y, yuv.u, yuv.v); const hsls = exports.RgbConverter.getHslFromRgb(rgbs[0], rgbs[1], rgbs[2]); return new Hsl(hsls[0], hsls[1], hsls[2]); } YuvConverter.YuvToHsl = YuvToHsl; function YuvToHsb(yuv) { const rgbs = getRgbFromYuv(yuv.y, yuv.u, yuv.v); const hsbs = exports.RgbConverter.getHsbFromRgb(rgbs[0], rgbs[1], rgbs[2]); return new Hsb(hsbs[0], hsbs[1], hsbs[2]); } YuvConverter.YuvToHsb = YuvToHsb; function YuvToCmyk(yuv) { const rgbs = getRgbFromYuv(yuv.y, yuv.u, yuv.v); const cmyks = exports.RgbConverter.getCmykFromRgb(rgbs[0], rgbs[1], rgbs[2]); return new Cmyk(cmyks[0], cmyks[1], cmyks[2], cmyks[3]); } YuvConverter.YuvToCmyk = YuvToCmyk; function YuvToCieXyz(yuv) { const rgbs = getRgbFromYuv(yuv.y, yuv.u, yuv.v); const cies = exports.RgbConverter.getCieXyzFromRgb(rgbs[0], rgbs[1], rgbs[2]); return new CieXyz(cies[0], cies[1], cies[2]); } YuvConverter.YuvToCieXyz = YuvToCieXyz; })(exports.YuvConverter || (exports.YuvConverter = {})); exports.CieXyzConverter = void 0; (function (CieXyzConverter) { function getRgbFromCieXyz(x, y, z) { const Clinear = new Array(3); Clinear[0] = x * 3.2406 - y * 1.5372 - z * 0.4986; Clinear[1] = -x * 0.9689 + y * 1.8758 - z * 0.0415; Clinear[2] = x * 0.0557 - y * 0.204 + z * 1.057; for (let i = 0; i < 3; i++) { Clinear[i] = Clinear[i] <= 0.0031308 ? 12.92 * Clinear[i] : (1 + 0.055) * Math.pow(Clinear[i], 1.0 / 2.4) - 0.055; } return [ exports.ConverterUtils.roundInt(Clinear[0] * 255.0), exports.ConverterUtils.roundInt(Clinear[1] * 255.0), exports.ConverterUtils.roundInt(Clinear[2] * 255.0), ]; } CieXyzConverter.getRgbFromCieXyz = getRgbFromCieXyz; function CieXyzToHex(xyz) { const rgbs = getRgbFromCieXyz(xyz.x, xyz.y, xyz.z); return exports.RgbConverter.RgbToHex(new Rgb(rgbs[0], rgbs[1], rgbs[2])); } CieXyzConverter.CieXyzToHex = CieXyzToHex; function CieXyzToRgb(xyz) { const rgbs = getRgbFromCieXyz(xyz.x, xyz.y, xyz.z); return new Rgb(rgbs[0], rgbs[1], rgbs[2]); } CieXyzConverter.CieXyzToRgb = CieXyzToRgb; function CieXyzToHsl(xyz) { const rgbs = getRgbFromCieXyz(xyz.x, xyz.y, xyz.z); const hsls = exports.RgbConverter.getHslFromRgb(rgbs[0], rgbs[1], rgbs[2]); return new Hsl(hsls[0], hsls[1], hsls[2]); } CieXyzConverter.CieXyzToHsl = CieXyzToHsl; function CieXyzToHsb(xyz) { const rgbs = getRgbFromCieXyz(xyz.x, xyz.y, xyz.z); const hsbs = exports.RgbConverter.getHsbFromRgb(rgbs[0], rgbs[1], rgbs[2]); return new Hsb(hsbs[0], hsbs[1], hsbs[2]); } CieXyzConverter.CieXyzToHsb = CieXyzToHsb; function CieXyzToCmyk(xyz) { const rgbs = getRgbFromCieXyz(xyz.x, xyz.y, xyz.z); const cmyks = exports.RgbConverter.getCmykFromRgb(rgbs[0], rgbs[1], rgbs[2]); return new Cmyk(cmyks[0], cmyks[1], cmyks[2], cmyks[3]); } CieXyzConverter.CieXyzToCmyk = CieXyzToCmyk; function CieXyzToYuv(xyz) { const rgbs = getRgbFromCieXyz(xyz.x, xyz.y, xyz.z); const yuvs = exports.RgbConverter.getYuvFromRgb(rgbs[0], rgbs[1], rgbs[2]); return new Yuv(yuvs[0], yuvs[1], yuvs[2]); } CieXyzConverter.CieXyzToYuv = CieXyzToYuv; })(exports.CieXyzConverter || (exports.CieXyzConverter = {})); exports.CieXyz = CieXyz; exports.Cmyk = Cmyk; exports.Hsb = Hsb; exports.Hsl = Hsl; exports.Rgb = Rgb; exports.Yuv = Yuv; exports.YuvProfile = YuvProfile; }));