UNPKG

chromaticity-color-utilities

Version:
445 lines (444 loc) 16.9 kB
import * as Colors from './Colors'; declare class Convert { /** * Normalize RGB values to 0-1 * * @param {Colors.rgb} rgb * @return {Colors.rgbNormalized} */ static rgbNormalize(rgb: Colors.rgb): Colors.rgbNormalized; /** * Apply gamma to normalized RGB value * NOT to be used with sRGB, L*, or other color spaces that utilize companding transformation formulae * * @param {Colors.rgbNormalized} rgb * @param {number} gamma * @return {Colors.rgbNormalized} */ static applyGamma(rgb: Colors.rgbNormalized, gamma: number | string): Colors.rgbNormalized; /** * Convert RGB to HSV * Saturation and Value are in percentages * * @param {Colors.rgb} rgb * @param {boolean} [round=true] * @return {Colors.hsv} */ static rgb2hsv(rgb: Colors.rgb, round?: boolean): Colors.hsv; /** * Convert RGB to HSL * Saturation and Lightness are in percentages * * @param {Colors.rgb} rgb * @param {boolean} [round=true] * @return {Colors.hsl} */ static rgb2hsl(rgb: Colors.rgb, round?: boolean): Colors.hsl; /** * Convert RGB to HSI * Saturation and Intensity are in percentages * * @param {Colors.rgb} rgb * @param {boolean} [round=true] * @return {Colors.hsi} */ static rgb2hsi(rgb: Colors.rgb, round?: boolean): Colors.hsi; /** * Convert RGB to HSI * Saturation and Intensity are in percentages * * @param {Colors.rgb} rgb * @param {boolean} [round=true] * @return {Colors.hsi} */ static rgb2hsi_deprecated(rgb: Colors.rgb, round?: boolean): Colors.hsi; /** * Convert HSV to RGB * Saturation and Value should be in percentages * * @param {Colors.hsv} hsv * @param {boolean} [round=true] * @param {number} [bitDepth=8] * @return {Colors.rgb} */ static hsv2rgb(hsv: Colors.hsv, round?: boolean, bitDepth?: number): Colors.rgb; /** * Convert HSV to HSL * Saturation and Value should be in percentages * Saturation and Lightness are in percentages * * @param {Colors.hsv} hsv * @param {boolean} [round=true] * @return {Colors.hsl} */ static hsv2hsl(hsv: Colors.hsv, round?: boolean): Colors.hsl; /** * Convert HSV to HSI * Saturation(V) and Value should be in percentages * Saturation(I) and Intensity will be in percentages * * @param {Colors.hsv} hsv * @param {boolean} [round=true] * @return {Colors.hsi} */ static hsv2hsi(hsv: Colors.hsv, round?: boolean): Colors.hsi; /** * Convert HSL to HSV * Saturation and Lightness should be in percentages * Saturation and Value are in percentages * * @param {Colors.hsl} hsl * @param {boolean} [round=true] * @return {Colors.hsv} */ static hsl2hsv(hsl: Colors.hsl, round?: boolean): Colors.hsv; /** * Convert HSL to RGB * Saturation and Lightness should be in percentages * * @param {Colors.hsl} hsl * @param {boolean} [round=true] * @param {number} [bitDepth=8] * @return {Colors.rgb} */ static hsl2rgb(hsl: Colors.hsl, round?: boolean, bitDepth?: number): Colors.rgb; /** * Convert HSL to HSI * Saturation(L) and Lightness should be in percentages * Saturation(I) and Intensity will be in percentages * * @param {Colors.hsl} hsl * @param {boolean} [round=true] * @return {Colors.hsi} */ static hsl2hsi(hsl: Colors.hsl, round?: boolean): Colors.hsi; /** * Convert HSI to RGB * Saturation and Intensity should be in percentages * * @param {Colors.hsi} hsi * @param {boolean} [round=true] * @param {number} [bitDepth=8] * @return {Colors.rgb} */ static hsi2rgb(hsi: Colors.hsi, round?: boolean, bitDepth?: number): Colors.rgb; /** * Convert HSI to RGB * Saturation and Intensity should be in percentages * * @param {Colors.hsi} hsi * @param {boolean} [round=true] * @param {number} [bitDepth=8] * @return {Colors.rgb} */ static hsi2rgb_deprecated(hsi: Colors.hsi, round?: boolean, bitDepth?: number): Colors.rgb; /** * Convert RGB to HSP * Saturation and Perceived Brightness will be in percentages * * @param {Colors.rgb} rgb * @param {boolean} [round=true] * @return {Colors.hsp} */ static rgb2hsp(rgb: Colors.rgb, round?: boolean, Pb?: number, Pr?: number): Colors.hsp; /** * Convert HSP to RGB * Saturation and Perceived Brightness should be in percentages * * @param {Colors.hsp} hsp * @param {boolean} [round=true] * @return {Colors.rgb} */ static hsp2rgb(hsp: Colors.hsp, round?: boolean, bitDepth?: number): Colors.rgb; /** * Convert RGB to CMYK * This conversion is mathematical and does not take pigment conversion into account * * @param {Colors.rgb} rgb * @param {boolean} [round=true] * @param {number} [bitDepth=255] RGB max value per channel * @return {Colors.cmyk} */ static rgb2cmyk(rgb: Colors.rgb, round?: boolean): Colors.cmyk; /** * Convert CMYK to RGB * This conversion is mathematical and does not take pigment conversion into account * * @param {Colors.cmyk} cmyk * @param {boolean} [round=true] * @param {number} [bitDepth=8] * @return {Colors.rgb} */ static cmyk2rgb(cmyk: Colors.cmyk, round?: boolean, bitDepth?: number): Colors.rgb; /** * Convert RGB to YIQ * TODO: Validate Algorithm * * @param {Colors.rgb} rgb * @param {boolean} [normalize=true] true = Y[0,255], I&Q[-128,128]; false = Y[0,1], I[-0.5957,0.5957], Q[-0.5226,0.5226] * @param {boolean} [round=true] will not round if not normalized * @return {Colors.yiq} */ static rgb2yiq(rgb: Colors.rgb, normalize?: boolean, round?: boolean): Colors.yiq; /** * Convert YIQ to RGB * * @param {Colors.yiq} yiq * @param {boolean} [round=true] * @param {number} [bitDepth=8] * @return {Colors.rgb} */ static yiq2rgb(yiq: Colors.yiq, round?: boolean, bitDepth?: number): Colors.rgb; /** * Convert RGB to XYZ * X, Y, and Z will be between 0 and the white point reference XYZ values * * @param {Colors.rgb} rgb * @param {string} [colorSpace=srgb] RGB color space (e.g. sRGB) * @param {string} [referenceWhite=d65] RGB reference white (e.g. D65) * @return {Colors.xyz} */ static rgb2xyz(rgb: Colors.rgb, colorSpace?: string, referenceWhite?: string): Colors.xyz; /** * Convert XYZ to RGB * RGB values that fall outsize representable values will be clamped * * @param {Colors.xyz} xyz * @param {boolean} [round=true] * @param {number} [bitDepth=8] * @return {Colors.rgb} */ static xyz2rgb(xyz: Colors.xyz, colorSpace?: string, referenceWhite?: string, round?: boolean, bitDepth?: number): Colors.rgb; /** * Convert XYZ to xyY * If X = Z = Y = 0, set x and y to chromaticity coordinates of reference white * * @param {Colors.xyz} xyz * @return {Colors.xyy} */ static xyz2xyy(xyz: Colors.xyz, referenceWhite?: string): Colors.xyy; /** * Convert xyY to XYZ * * @param {Colors.xyy} xyy * @return {Colors.xyz} */ static xyy2xyz(xyy: Colors.xyy): Colors.xyz; /** * Convert XYZ to Lab * * @param {Colors.xyz} xyz * @param {string} referenceWhite * @param {boolean} [round=true] * @return {Colors.lab} */ static xyz2lab(xyz: Colors.xyz, referenceWhite?: string, round?: boolean): Colors.lab; /** * Convert Lab to XYZ * * @param {Colors.lab} lab * @return {Colors.xyz} */ static lab2xyz(lab: Colors.lab, referenceWhite?: string): Colors.xyz; /** * Convert XYZ to Luv * L will range between 0% and 100% * u and v will range between -100% and 100% * * @param {Colors.xyz} xyz * @return {Colors.luv} */ static xyz2luv(xyz: Colors.xyz, referenceWhite?: string, round?: boolean): Colors.luv; /** * Convert Luv to XYZ * X, Y, and Z will be in range 0 to 1 * * @param {Colors.luv} luv * @return {Colors.xyz} */ static luv2xyz(luv: Colors.luv, referenceWhite?: string): Colors.xyz; /** * Convert RGB to Rec709 RGB * Will output either 8-bit or 10-bit depending on input color space * * @param {Colors.rgb} rgb * @param {boolean} [round=true] * @param {number} [bitRate=8] * @return {Colors.rec709rgb} */ static rgb2rec709rgb(rgb: Colors.rgb, round?: boolean, bitRate?: number): Colors.rec709rgb; /** * Convert Rec709 RGB to RGB * Converts 8-bit or 10-bit Rec709 RGB values to standard (0 - $color_depth) range * Input RGB values outside of legal black and white points will be clamped * * @param {Colors.rec709rgb} rgb709 * @param {boolean} [round=true] * @param {number} [bitDepth=8] * @return {Colors.rgb} */ static rec709rgb2rgb(rgb709: Colors.rec709rgb, round?: boolean, bitDepth?: number): Colors.rgb; /** * Convert RGB to Rec2020 RGB * Will output either 10-bit or 12-bit depending on input color space * * @param {Colors.rgb} rgb * @param {boolean} [round=true] * @param {number} [bitRate=10] * @return {Colors.rec2020rgb} */ static rgb2rec2020rgb(rgb: Colors.rgb, round?: boolean, bitRate?: number): Colors.rec2020rgb; /** * Convert Rec2020 RGB to RGB * Converts 10-bit or 12-bit Rec2020 RGB values to standard (0 - $color_depth) range * Input RGB values outside of legal black and white points will be clamped * * @param {Colors.rec2020rgb} rgb2020 * @param {boolean} [round=true] * @param {number} [bitDepth=8] * @return {Colors.rgb} */ static rec2020rgb2rgb(rgb2020: Colors.rec2020rgb, round?: boolean, bitDepth?: number): Colors.rgb; /** * Convert RGB to YCbCr * * @param {Colors.rgb} rgb * @param {number} kb Kb constant defined from target color space, such that Kb + Kr + Kg = 1 * @param {number} kr Kr constant defined from target color space, such that Kb + Kr + Kg = 1 * @param {boolean} [round=true] * @return {Colors.ycbcr} */ static rgb2ycbcr(rgb: Colors.rgb, kb: number, kr: number, round?: boolean): Colors.ycbcr; /** * Convert RGB to YPbPr * Y will range from 0 to 1; Pb and Pr will range from -0.5 to 0.5 * * @param {Colors.rgb} rgb * @param {number} kb Kb constant defined from target color space, such that Kb + Kr + Kg = 1 * @param {number} kr Kr constant defined from target color space, such that Kb + Kr + Kg = 1 * @return {Colors.ypbpr} */ static rgb2ypbpr(rgb: Colors.rgb, kb: number, kr: number): Colors.ypbpr; /** * Convert YPbPr to RGB * Y must range from 0 to 1; Pb and Pr must range from -0.5 to 0.5 * * @param {Colors.ypbpr} ypbpr * @param {number} kb Kb constant defined from target color space, such that Kb + Kr + Kg = 1 * @param {number} kr Kr constant defined from target color space, such that Kb + Kr + Kg = 1 * @param {boolean} [round=true] * @param {number} [bitDepth=8] * @return {Colors.rgb} */ static ypbpr2rgb(ypbpr: Colors.ypbpr, kb: number, kr: number, round?: boolean, bitDepth?: number): Colors.rgb; /** * Convert YPbPr to YCbCr * Y must be in range 0 to 1; Pb and Pr must be in range -0.5 to 0.5. * Y' defaults to 16 for black and 235 for white when using an 8-bit representation. * The standard has 8-bit digitized versions of CB and CR scaled to a different range of 16 to 240. * * @param {Colors.ypbpr} ypbpr * @param {number} [yLower=16] Lower bounds of Y * @param {number} [yUpper=235] Upper bounds of Y * @param {number} [cLower=16] Lower bounds of Cb and Cr * @param {number} [cUpper=240] Upper bounds of Cb and Cr * @param {boolean} [round=true] * @return {Colors.ycbcr} */ static ypbpr2ycbcr(ypbpr: Colors.ypbpr, yLower?: number, yUpper?: number, cLower?: number, cUpper?: number, round?: boolean): Colors.ycbcr; /** * Convert YCbCr to YPbPr * Y will be in range 0 to 1; Pb and Pr will be in range -0.5 to 0.5 * * @param {Colors.ycbcr} ycbcr * @param {number} kb * @param {number} kr * @return {Colors.ypbpr} */ static ycbcr2ypbpr(ycbcr: Colors.ycbcr, kb: number, kr: number): Colors.ypbpr; /** * Convert RGB to JPEG YCbCr * Output Y, Cb, and Cr range from 0 to 255 * * @param {Colors.rgb} rgb * @param {boolean} [round=true] * @return {Colors.ycbcr} */ static rgb2jpegycbcr(rgb: Colors.rgb, round?: boolean): Colors.ycbcr; /** * Convert JPEG YCbCr to RGB * Y, Cb, and Cr should range from 0 to 255 * * @param {Colors.ycbcr} ycbcr * @param {boolean} [round=true] * @param {number} [bitDepth=8] * @return {Colors.rgb} */ static jpegycbcr2rgb(ycbcr: Colors.ycbcr, round?: boolean, bitDepth?: number): Colors.rgb; /** * Convert a wavelength in nm to RGB * This is hugely perceptual and approximate. * Adapted from http://www.physics.sfasu.edu/astro/color/spectra.html, * but with better visual falloff at edges. * * @param {Colors.nm} nm Wavelength of light in nanometers (positive number) * @param {number} [gamma=0.8] Gamma adjustment * @param {boolean} [round=true] * @param {number} [bitDepth=8] * @return {Colors.rgb} */ static nm2rgb(nm: Colors.nm, gamma?: number, round?: boolean, bitDepth?: number): Colors.rgb; /** * Convert a color temperature in Kelvin to RGB * Adapted from 'RGB VALUES FOR HOT OBJECTS' by William T. Bridgman, NASA, 2000 * http://www.physics.sfasu.edu/astro/color/blackbodyc.txt * * A black body approximation is used where the temperature, * T, is given in Kelvin. The XYZ values are determined by * "integrating" the product of the wavelength distribution of * energy and the XYZ functions for a uniform source. * * @param {Colors.kelvin} kelvin Color temperature in degrees Kelvin; must fall between 1000 and 40000 * @param {boolean} [round=true] * @param {number} [bitDepth=8] * @return {Colors.rgb} */ static kelvin2rgb(kelvin: Colors.kelvin, round?: boolean, bitDepth?: number): Colors.rgb; /** * Convert a color temperature in Kelvin to RGB * Not accurate for scientific purposes * Original algorithm from: * https://tannerhelland.com/2012/09/18/convert-temperature-rgb-algorithm-code.html * * @param {Colors.kelvin} kelvin Color temperature in degrees Kelvin; must fall between 1000 and 40000 * @param {boolean} [round=true] * @param {number} [bitDepth=8] * @return {Colors.rgb} */ static kelvin2rgb_deprecated(kelvin: Colors.kelvin, round?: boolean, bitDepth?: number): Colors.rgb; /** * Convert HEX to RGB * * @param {Colors.hex} hex * @param {number} [bitDepth=8] * @return {Colors.rgb} */ static hex2rgb(hex: Colors.hex, bitDepth?: number): Colors.rgb; /** * Convert RGB to HEX * * @param {Colors.rgb} rgb * @param {number} [bitDepth=8] * @return {Colors.hex} */ static rgb2hex(rgb: Colors.rgb, bitDepth?: number): Colors.hex; /** * Convert RGB to integer of HEX code * * @param {Colors.rgb} rgb * @param {number} [bitDepth=8] * @return {number} 0xRRGGBB */ static rgb2hexint(rgb: Colors.rgb, bitDepth?: number): number; } export default Convert;