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)
167 lines (166 loc) • 6.75 kB
TypeScript
/** @format */
import { Palette } from '../image/palette.js';
import { Channel } from './channel.js';
import { Color, ColorConvertOptions } from './color.js';
import { Format } from './format.js';
/**
* An 8-bit unsigned int color with channel values in the range [0, 255].
*/
export declare class ColorUint8 implements Color {
/** Holds the color data as an array of 8-bit unsigned integers. */
protected data: Uint8Array;
/** Gets the format of the color. */
get format(): Format;
/** Gets the length of the color data array. */
get length(): number;
/** Gets the maximum value a channel can have. */
get maxChannelValue(): number;
/** Gets the maximum value an index can have. */
get maxIndexValue(): number;
/** Checks if the format is Low Dynamic Range (LDR). */
get isLdrFormat(): boolean;
/** Checks if the format is High Dynamic Range (HDR). */
get isHdrFormat(): boolean;
/** Checks if the color has a palette. */
get hasPalette(): boolean;
/** Gets the palette of the color, if any. */
get palette(): Palette | undefined;
/** Gets the index value of the color. */
get index(): number;
/** Sets the index value of the color. */
set index(i: number);
/** Gets the red channel value. */
get r(): number;
/** Sets the red channel value. */
set r(r: number);
/** Gets the green channel value. */
get g(): number;
/** Sets the green channel value. */
set g(g: number);
/** Gets the blue channel value. */
get b(): number;
/** Sets the blue channel value. */
set b(b: number);
/** Gets the alpha channel value. */
get a(): number;
/** Sets the alpha channel value. */
set a(a: number);
/** Gets the normalized red channel value. */
get rNormalized(): number;
/** Sets the normalized red channel value. */
set rNormalized(v: number);
/** Gets the normalized green channel value. */
get gNormalized(): number;
/** Sets the normalized green channel value. */
set gNormalized(v: number);
/** Gets the normalized blue channel value. */
get bNormalized(): number;
/** Sets the normalized blue channel value. */
set bNormalized(v: number);
/** Gets the normalized alpha channel value. */
get aNormalized(): number;
/** Sets the normalized alpha channel value. */
set aNormalized(v: number);
/** Gets the luminance of the color. */
get luminance(): number;
/** Gets the normalized luminance of the color. */
get luminanceNormalized(): number;
/**
* Constructs a new ColorUint8 instance.
* @param {Uint8Array | number} data - The initial data for the color, either as a Uint8Array or a number.
*/
constructor(data: Uint8Array | number);
/**
* Creates a new ColorUint8 instance from another ColorUint8 instance.
* @param {ColorUint8} other - The other ColorUint8 instance to copy.
* @returns {ColorUint8} A new ColorUint8 instance.
*/
static from(other: ColorUint8): ColorUint8;
/**
* Creates a new ColorUint8 instance from a Uint8Array.
* @param {Uint8Array} color - The color data as a Uint8Array.
* @returns {ColorUint8} A new ColorUint8 instance.
*/
static fromArray(color: Uint8Array): ColorUint8;
/**
* Creates a new ColorUint8 instance with RGB values.
* @param {number} r - The red channel value.
* @param {number} g - The green channel value.
* @param {number} b - The blue channel value.
* @returns {ColorUint8} A new ColorUint8 instance.
*/
static rgb(r: number, g: number, b: number): ColorUint8;
/**
* Creates a new ColorUint8 instance with RGBA values.
* @param {number} r - The red channel value.
* @param {number} g - The green channel value.
* @param {number} b - The blue channel value.
* @param {number} a - The alpha channel value.
* @returns {ColorUint8} A new ColorUint8 instance.
*/
static rgba(r: number, g: number, b: number, a: number): ColorUint8;
/**
* Gets the value of a specific channel.
* @param {number | Channel} channel - The channel index or Channel enum.
* @param {number} [defValue=0] - The default value if the channel is not present.
* @returns {number} The value of the channel.
*/
getChannel(channel: number | Channel, defValue?: number): number;
/**
* Gets the normalized value of a specific channel.
* @param {number | Channel} channel - The channel index or Channel enum.
* @returns {number} The normalized value of the channel.
*/
getChannelNormalized(channel: number | Channel): number;
/**
* Sets the value of a specific channel.
* @param {number | Channel} index - The channel index or Channel enum.
* @param {number} value - The value to set.
*/
setChannel(index: number | Channel, value: number): void;
/**
* Sets the color values from another Color instance.
* @param {Color} c - The Color instance to copy values from.
*/
set(c: Color): void;
/**
* Sets the RGB values of the color.
* @param {number} r - The red channel value.
* @param {number} g - The green channel value.
* @param {number} b - The blue channel value.
*/
setRgb(r: number, g: number, b: number): void;
/**
* Sets the RGBA values of the color.
* @param {number} r - The red channel value.
* @param {number} g - The green channel value.
* @param {number} b - The blue channel value.
* @param {number} a - The alpha channel value.
*/
setRgba(r: number, g: number, b: number, a: number): void;
/**
* Converts the color data to an array of numbers.
* @returns {number[]} An array of numbers representing the color data.
*/
toArray(): number[];
/**
* Creates a clone of the current ColorUint8 instance.
* @returns {ColorUint8} A new ColorUint8 instance that is a clone of the current instance.
*/
clone(): ColorUint8;
/**
* Checks if the current color is equal to another color.
* @param {Color} other - The other color to compare with.
* @returns {boolean} True if the colors are equal, false otherwise.
*/
equals(other: Color): boolean;
/**
* Converts the color to another format.
* @param {ColorConvertOptions} [opt] - The options for the conversion.
* @param {string} [opt.format] - The target format.
* @param {number} [opt.numChannels] - The number of channels in the target format.
* @param {number} [opt.alpha] - The alpha value in the target format.
* @returns {Color} The converted color.
*/
convert(opt?: ColorConvertOptions): Color;
}