UNPKG

image-in-browser

Version:

Package for encoding / decoding images, transforming images, applying filters, drawing primitives on images on the client side (no need for server Node.js)

210 lines (209 loc) 9.38 kB
/** @format */ import { Color } from './color.js'; import { Format } from './format.js'; /** * Options for converting colors. */ export interface ConvertColorOptions { /** * The source color to convert from. */ from: Color; /** * The target color to convert to. Optional. */ to?: Color; /** * The format to convert the color to. Optional. */ format?: Format; /** * The number of color channels. Optional. */ numChannels?: number; /** * The alpha value for the color. Optional. */ alpha?: number; } export declare abstract class ColorUtils { /** * Converts the color channels of the source color `c` to match the format and number of channels of the target color `c2`. * * @param {Color} c - The source color to be converted. * @param {Color} c2 - The target color object where the converted channels will be set. * @param {number} a - The alpha value to be used if the target color has an alpha channel. * @returns {Color} The target color `c2` with its channels set to the converted values from the source color `c`. */ private static convertColorInternal; /** * Extracts the red component from a 32-bit integer color value. * * @param {number} c - The 32-bit integer color value. * @returns {number} The red component of the color. */ static uint32ToRed(c: number): number; /** * Extracts the green component from a 32-bit unsigned integer color value. * * @param {number} c - The 32-bit unsigned integer representing the color. * @returns {number} The green component of the color, as an 8-bit unsigned integer. */ static uint32ToGreen(c: number): number; /** * Extracts the blue component from a 32-bit unsigned integer. * @param {number} c - The 32-bit unsigned integer. * @returns {number} The blue component (0-255). */ static uint32ToBlue(c: number): number; /** * Extracts the alpha component from a 32-bit unsigned integer. * @param {number} c - The 32-bit unsigned integer. * @returns {number} The alpha component (0-255). */ static uint32ToAlpha(c: number): number; /** * Converts RGBA color values to a single 32-bit unsigned integer. * * @param {number} r - The red component of the color (0-255). * @param {number} g - The green component of the color (0-255). * @param {number} b - The blue component of the color (0-255). * @param {number} a - The alpha component of the color (0-255). * @returns {number} A 32-bit unsigned integer representing the RGBA color. */ static rgbaToUint32(r: number, g: number, b: number, a: number): number; /** * Converts a color from one format to another. * * @param {ConvertColorOptions} opt - The options for the color conversion, including the source color, target format, and other parameters. * @returns {Color} The converted color. * @throws {LibError} if the target format is unknown. */ static convertColor(opt: ConvertColorOptions): Color; /** * Calculates the luminance of a given color. * * @param {Color} c - The color for which to calculate the luminance. * @returns {number} The luminance value of the color. */ static getLuminance(c: Color): number; /** * Calculates the normalized luminance of a given color. * * @param {Color} c - The Color object containing normalized RGB values. * @returns {number} The normalized luminance as a number. */ static getLuminanceNormalized(c: Color): number; /** * Calculates the luminance of an RGB color. * * @param {number} r - The red component of the color (0-255). * @param {number} g - The green component of the color (0-255). * @param {number} b - The blue component of the color (0-255). * @returns {number} The luminance of the color. */ static getLuminanceRgb(r: number, g: number, b: number): number; /** * Converts HSL (Hue, Saturation, Lightness) color values to RGB (Red, Green, Blue). * * @param {number} hue - The hue of the color, a number between 0 and 1. * @param {number} saturation - The saturation of the color, a number between 0 and 1. * @param {number} lightness - The lightness of the color, a number between 0 and 1. * @param {number[]} rgb - Array to return RGB values [red, green, blue], each ranging from 0 to 255. */ static hslToRgb(hue: number, saturation: number, lightness: number, rgb: number[]): void; /** * Converts RGB (Red, Green, Blue) color values to HSV (Hue, Saturation, Value). * * @param {number} r - The red color value, a number between 0 and 255. * @param {number} g - The green color value, a number between 0 and 255. * @param {number} b - The blue color value, a number between 0 and 255. * @param {number[]} hsv - Array to return HSV values [hue, saturation, value], where hue is in degrees (0 to 360), and saturation and value are between 0 and 1. */ static rgbToHsv(r: number, g: number, b: number, hsv: number[]): void; /** * Converts HSV (Hue, Saturation, Value) color values to RGB (Red, Green, Blue). * * @param {number} h - The hue of the color, in degrees (0 to 360). * @param {number} s - The saturation of the color, a number between 0 and 1. * @param {number} v - The value of the color, a number between 0 and 1. * @param {number[]} rgb - Array to return RGB values [red, green, blue], each ranging from 0 to 255. */ static hsvToRgb(h: number, s: number, v: number, rgb: number[]): void; /** * Converts an RGB color value to HSL. * * @param {number} r - The red color value (0-255). * @param {number} g - The green color value (0-255). * @param {number} b - The blue color value (0-255). * @returns {number[]} An array containing the HSL representation [hue, saturation, lightness]. */ static rgbToHsl(r: number, g: number, b: number): number[]; /** * Converts CIELAB (CIE L\*a\*b\*) color space values to XYZ color space values. * * @param {number} l - The lightness value (L*) in CIELAB. * @param {number} a - The a* chromaticity coordinate in CIELAB. * @param {number} b - The b* chromaticity coordinate in CIELAB. * @returns {number[]} The corresponding XYZ color space values. */ static labToXyz(l: number, a: number, b: number): number[]; /** * Converts XYZ color space values to RGB color space values. * * @param {number} x - The X value in the XYZ color space (0 to 100). * @param {number} y - The Y value in the XYZ color space (0 to 100). * @param {number} z - The Z value in the XYZ color space (0 to 100). * @returns {number[]} An array containing the RGB values, each ranging from 0 to 255. */ static xyzToRgb(x: number, y: number, z: number): number[]; /** * Converts CMYK color values to RGB color values. * * @param {number} c - The cyan component (0-255). * @param {number} m - The magenta component (0-255). * @param {number} y - The yellow component (0-255). * @param {number} k - The black component (0-255). * @param {number[]} rgb - Array to return RGB values [red, green, blue], each ranging from 0 to 255. */ static cmykToRgb(c: number, m: number, y: number, k: number, rgb: number[]): void; /** * Converts LAB color values to RGB color values. * * @param {number} l - The lightness value (0 to 100). * @param {number} a - The green-red color component. * @param {number} b - The blue-yellow color component. * @returns {number[]} An array containing the RGB values [R, G, B] where each value is in the range 0 to 255. */ static labToRgb(l: number, a: number, b: number): number[]; /** * Converts an RGB color value to XYZ color space. * * The RGB values should be in the range [0, 255]. The returned XYZ values * will be in the range [0, 100]. * * @param {number} r - The red color value, in the range [0, 255]. * @param {number} g - The green color value, in the range [0, 255]. * @param {number} b - The blue color value, in the range [0, 255]. * @returns {number[]} The XYZ representation of the color, as an array of three numbers. */ static rgbToXyz(r: number, g: number, b: number): number[]; /** * Converts XYZ color space values to CIELAB (CIE L\*a\*b\*) color space values. * * @param {number} x - The X value in the XYZ color space. * @param {number} y - The Y value in the XYZ color space. * @param {number} z - The Z value in the XYZ color space. * @returns {number[]} An array containing the L*, a*, and b* values in the CIELAB color space. */ static xyzToLab(x: number, y: number, z: number): number[]; /** * Convert an RGB color to CIELAB (CIE L\*a\*b\*) color space. * * @param {number} r - Red component (0-255). * @param {number} g - Green component (0-255). * @param {number} b - Blue component (0-255). * @returns {number[]} An array containing the CIELAB values. */ static rgbToLab(r: number, g: number, b: number): number[]; }