import { GLclampf3, GLclampf4, GLclampf5 } from './tuples'; /** @todo remove this when webgl types are working again. */ export type GLubyte = number; /** * Color class that allows for specification and conversion of colors in various color spaces. Please not that most of * the color conversion math is based on {@link https://www.easyrgb.com/en/math.php}. The internal color representation * is a 4-tuple of GLclampf components in RGB color space and additional alpha. All color conversion, e.g., getters is * computed on the fly, not cached, and is not optimized for, e.g., massive pixel processing. */ export declare class Color { protected static readonly DEFAULT_ALPHA: GLclampf; protected static readonly HEX_FORMAT_REGEX: RegExp; protected _rgba: GLclampf4; /** @see {@link altered} */ protected _altered: boolean; /** * Converts a hue value into an rgb value. */ protected static hue2rgb(p: GLfloat, q: GLfloat, t: GLfloat): GLfloat; /** * Converts a float value to two-character HEX code. * @param value - A float value in [0.0, 1.0]. * @returns - Two-character hexadecimal representation in [00, FF]. */ protected static to2CharHexCode(value: number): string; /** * Converts a color from HSL space to RGB space. * @param hsl - HSL color tuple: hue, saturation, and lightness, each in [0.0, 1.0]. * @returns - RGB color tuple: red, green, and blue, each in [0.0, 1.0]. */ static hsl2rgb(hsl: GLclampf3): GLclampf3; /** * Converts a color from HSL space to RGB space. * @param rgb - RGB color tuple: red, green, and blue, each in [0.0, 1.0]. * @returns - HSL color tuple: hue, saturation, and lightness, each in [0.0, 1.0]. */ static rgb2hsl(rgb: GLclampf3): GLclampf3; /** * Converts a color from LAB space to XYZ space (D65/2° illuminant) * @param lab - LAB color tuple: lightness, greenRed, and blueYellow, each in [0.0, 1.0]. * @returns - XYZ color tuple: x, y, and z, each in [0.0, 1.0]. */ static lab2xyz(lab: GLclampf3): GLclampf3; /** * Converts a color from XYZ space to CIE-Lab space. * @param xyz - XYZ color tuple: x, y, and z, and refer to the D65/2° illuminant. * @returns - LAB color tuple: lightness, greenRed, and blueYellow, each in [0.0, 1.0]. */ static xyz2lab(xyz: GLclampf3): GLclampf3; /** * Converts a color from XYZ space to Adobe-RGB space. * @param xyz - XYZ color tuple: x, y, and z, and refer to the D65/2° illuminant. * @returns - RGB color tuple: red, green, and blue, each in [0.0, 1.0] */ static xyz2rgb(xyz: GLclampf3): GLclampf3; /** * Converts a color from Adobe-RGB space to XYZ space. * @param rgb - RGB color tuple: red, green, and blue, each in [0.0, 1.0] * @returns - XYZ color tuple: x, y, and z, each in [0.0, 1.0]. */ static rgb2xyz(rgb: GLclampf3): GLclampf3; /** * Converts a color from LAB space to RGB space. * @param lab - LAB color tuple: lightness, greenRed, and blueYellow, each in [0.0, 1.0]. * @returns - RGB color tuple: red, green, and blue, each in [0.0, 1.0] */ static lab2rgb(lab: GLclampf3): GLclampf3; /** * Converts a color from RGB space to LAB space. * @param lab - LAB color tuple: lightness, greenRed, and blueYellow, each in [0.0, 1.0]. * @returns - RGB color tuple: red, green, and blue, each in [0.0, 1.0] */ static rgb2lab(rgb: GLclampf3): GLclampf3; /** * Converts a color from CMYK space to RGB space. * @param cmyk - CMYK color tuple: cyan, magenta, yellow, and key, each in [0.0, 1.0]. * @returns - RGB color tuple: red, green, and blue, each in [0.0, 1.0] */ static cmyk2rgb(cmyk: GLclampf4): GLclampf3; /** * Converts a color from RGB space to CMYK space. * @param rgb - RGB color tuple: red, green, and blue, each in [0.0, 1.0] * @returns - CMYK color tuple: cyan, magenta, yellow, and key, each in [0.0, 1.0]. */ static rgb2cmyk(rgb: GLclampf3): GLclampf4; /** * Converts a color from HEX string to RGBA space. The hex string can start with '#' or '0x' or neither of these. * @param hex - Hexadecimal color string: red, green, and blue, each in ['00', 'ff']. * @returns - RGBA color tuple: red, green, blue, and alpha, each in [0.0, 1.0]. On error [0, 0, 0, 0] is returned. */ static hex2rgba(hex: string): GLclampf4; /** * Converts a color from RGB space to HEX string. * @param rgb - RGB color tuple: red, green, and blue, each in [0.0, 1.0] * @returns - Hexadecimal color string: red, green, and blue, each in ['00', 'ff'], with '#' prefix */ static rgb2hex(rgb: GLclampf3): string; /** * Converts a color from RGBA space to HEX string. * @param rgba - RGBA color tuple: red, green, blue, and alpha, each in [0.0, 1.0] * @returns - Hexadecimal color string: red, green, blue, and alpha, each in ['00', 'ff'], with '#' prefix */ static rgba2hex(rgba: GLclampf4): string; /** * Performs a linear interpolation between x and y using a to weight between them within the specified color space. * @param x - First color stop for lerp/linear interpolation. * @param y - Second color stop for lerp/linear interpolation. * @param a - Specify the value to use to interpolate between x and y. * @param space - The color space that is to be used for linear interpolation of two colors. */ static lerp(x: Color, y: Color, a: number, space?: Color.Space): Color; /** * Creates an instance of color (a 4-tuple in RGBA space). * @param rgba - Either RGB tuple or RGBA tuple. If none is provided, default will be kept. * @param alpha - If RGB tuple is provided an additional alpha value can be specified. */ constructor(rgba?: GLclampf3 | GLclampf4, alpha?: GLclampf); /** * Checks whether or not this color matches a second color (based on internal rgba floating representation). * @param other - Color to compare color values to. * @returns - True iff both colors have the exact same rgba floating point values. */ equals(other: Color): boolean; /** * Specifies the internal rgba store using a color in float (32bit) RGBA colors. * @param red - Red color component in [0.0, 1.0] * @param green - Green color component in [0.0, 1.0] * @param blue - Blue color component in [0.0, 1.0] * @param alpha - Alpha color component in [0.0, 1.0] * @returns - The color instance (this). */ fromF32(red: GLfloat, green: GLfloat, blue: GLfloat, alpha?: GLfloat): Color; /** * Specifies the internal rgba store using a color in unsigned int (8bit) RGBA colors. * @param red - Red color component in [0, 255] * @param green - Green color component in [0, 255] * @param blue - Blue color component in [0, 255] * @param alpha - Alpha color component in [0, 255] * @returns - The color instance (this). */ fromUI8(red: GLubyte, green: GLubyte, blue: GLubyte, alpha?: GLubyte): Color; /** * Specifies the internal rgba store using a color in RGB color space. * @param red - Red color component in [0.0, 1.0] * @param green - Green color component in [0.0, 1.0] * @param blue - Blue color component in [0.0, 1.0] * @param alpha - Alpha color component in [0.0, 1.0] * @returns - The color instance (this). */ fromRGB(red: GLclampf, green: GLclampf, blue: GLclampf, alpha?: GLclampf): Color; /** * Specifies the internal rgba store using a color in HSL color space. * @param hue - Hue color component in [0.0, 1.0] * @param saturation - Saturation color component in [0.0, 1.0] * @param lightness - Lightness color component in [0.0, 1.0] * @param alpha - Alpha color component in [0.0, 1.0] * @returns - The color instance (this). */ fromHSL(hue: GLclampf, saturation: GLclampf, lightness: GLclampf, alpha?: GLclampf): Color; /** * Specifies the internal rgba store using a color in CIE-Lab color space. * @param lightness - Lightness color component in [0.0, 1.0] * @param greenRed - Green-Red/a color component in [0.0, 1.0] * @param blueYellow - Blue-Yellow/b color component in [0.0, 1.0] * @param alpha - Alpha color component in [0.0, 1.0] * @returns - The color instance (this). */ fromLAB(lightness: GLclampf, greenRed: GLclampf, blueYellow: GLclampf, alpha?: GLclampf): Color; /** * Specifies the internal rgba store using a color in CMYK color space. * @param cyan - Cyan color component in [0.0, 1.0] * @param magenta - Magenta color component in [0.0, 1.0] * @param yellow - Yellow color component in [0.0, 1.0] * @param key - Key/Black color component in [0.0, 1.0] * @param alpha - Alpha color component in [0.0, 1.0] * @returns - The color instance (this). */ fromCMYK(cyan: GLclampf, magenta: GLclampf, yellow: GLclampf, key: GLclampf, alpha?: GLclampf): Color; /** * Specifies the internal rgba store using a hexadecimal color string. * @param hex - Hexadecimal color string: red, green, blue, and alpha (optional) each in ['00', 'ff']. * @returns - The color instance (this). */ fromHex(hex: string): Color; /** * Converts the color to a gray value using the specified algorithm. * @param algorithm - The algorithm used for color to gray conversion. */ gray(algorithm?: Color.GrayscaleAlgorithm): GLclampf; /** * Enables generic color access within a specified color space. * @param space - Expected color space of the requested color values. * @param alpha - Whether or not alpha channel should be provided as well. */ tuple(space: Color.Space, alpha?: boolean): GLclampf3 | GLclampf4 | GLclampf5; /** * Read access to the RGB components as floating point 3-tuple, each value in range [0.0, 1.0]. */ get rgb(): GLclampf3; /** * Read access to the RGB components as array of three bytes (8bit unsigned int), each in range [0, 255]. */ get rgbUI8(): Uint8Array; /** * Read access to the RGB components as array of three 32bit floats, each in range [0.0, 1.0]. */ get rgbF32(): Float32Array; /** * Read access to the RGBA components as floating point 4-tuple, each value in range [0.0, 1.0]. */ get rgba(): GLclampf4; /** * Read access to the RGBA components as array of four bytes (8bit unsigned int), each in range [0, 255]. */ get rgbaUI8(): Uint8Array; /** * Read access to the RGBA components as array of four 32bit floats, each in range [0.0, 1.0]. */ get rgbaF32(): Float32Array; /** * Read access to the Red component as float value in range [0.0, 1.0]. */ get r(): GLclampf; /** * Read access to the Green component as float value in range [0.0, 1.0]. */ get g(): GLclampf; /** * Read access to the Blue component as float value in range [0.0, 1.0]. */ get b(): GLclampf; /** * Read access to the Alpha component as float value in range [0.0, 1.0]. */ get a(): GLclampf; /** * Read access to the RGB components as hexadecimal string. */ get hexRGB(): string; /** * Read access to the RGBA components as hexadecimal string. */ get hexRGBA(): string; /** * Read access to the HSL components as floating point 3-tuple, each value in range [0.0, 1.0]. */ get hsl(): GLclampf3; /** * Read access to the HSLA components as floating point 4-tuple, each value in range [0.0, 1.0]. */ get hsla(): GLclampf4; /** * Read access to the LAB components as floating point 3-tuple, each value in range [0.0, 1.0]. */ get lab(): GLclampf3; /** * Read access to the LABA components as floating point 4-tuple, each value in range [0.0, 1.0]. */ get laba(): GLclampf4; /** * Read access to the CMYK components as floating point 4-tuple, each value in range [0.0, 1.0]. */ get cmyk(): GLclampf4; /** * Read access to the CMYKA components as floating point 5-tuple, each value in range [0.0, 1.0]. */ get cmyka(): GLclampf5; /** * Whether or not color value has changed. */ get altered(): boolean; /** * Intended for resetting alteration status. */ set altered(status: boolean); } export declare namespace Color { enum GrayscaleAlgorithm { Average = "average", LinearLuminance = "linear-luminance",/* CIE1931 */ LeastSaturatedVariant = "least-saturated-variant", MinimumDecomposition = "minimum-decomposition", MaximumDecomposition = "maximum-decomposition" } /** * Color spaces covered by this class. */ enum Space { RGB = "rgb", HSL = "hsl", LAB = "lab", CMYK = "cmyk" } }