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)
160 lines (159 loc) • 6.12 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';
/**
* A 4-bit unsigned int color with channel values in the range [0, 15].
*/
export declare class ColorUint4 implements Color {
/** Internal data storage for color channels */
private _data;
/** Format of the color */
get format(): Format;
/** Length of the color data */
private readonly _length;
/** Length of the color data */
get length(): number;
/** Maximum value for any channel */
get maxChannelValue(): number;
/** Maximum value for the index */
get maxIndexValue(): number;
/** Indicates if the format is Low Dynamic Range */
get isLdrFormat(): boolean;
/** Indicates if the format is High Dynamic Range */
get isHdrFormat(): boolean;
/** Indicates if the color has a palette */
get hasPalette(): boolean;
/** Palette associated with the color, if any */
get palette(): Palette | undefined;
/** Index value of the color */
get index(): number;
set index(i: number);
/** Red channel value */
get r(): number;
set r(r: number);
/** Green channel value */
get g(): number;
set g(g: number);
/** Blue channel value */
get b(): number;
set b(b: number);
/** Alpha channel value */
get a(): number;
set a(a: number);
/** Normalized red channel value */
get rNormalized(): number;
set rNormalized(v: number);
/** Normalized green channel value */
get gNormalized(): number;
set gNormalized(v: number);
/** Normalized blue channel value */
get bNormalized(): number;
set bNormalized(v: number);
/** Normalized alpha channel value */
get aNormalized(): number;
set aNormalized(v: number);
/** Luminance of the color */
get luminance(): number;
/** Normalized luminance of the color */
get luminanceNormalized(): number;
/**
* Constructs a new ColorUint4 instance.
* @param {Uint8Array | number} data - Either a Uint8Array or a number representing the length of the color data.
*/
constructor(data: Uint8Array | number);
/**
* Creates a new ColorUint4 instance from another ColorUint4 instance.
* @param {ColorUint4} other - The other ColorUint4 instance.
* @returns {ColorUint4} A new ColorUint4 instance.
*/
static from(other: ColorUint4): ColorUint4;
/**
* Creates a new ColorUint4 instance from a Uint8Array.
* @param {Uint8Array} color - The Uint8Array representing the color.
* @returns {ColorUint4} A new ColorUint4 instance.
*/
static fromArray(color: Uint8Array): ColorUint4;
/**
* Creates a new ColorUint4 instance with RGB values.
* @param {number} r - Red channel value.
* @param {number} g - Green channel value.
* @param {number} b - Blue channel value.
* @returns {ColorUint4} A new ColorUint4 instance.
*/
static rgb(r: number, g: number, b: number): ColorUint4;
/**
* Creates a new ColorUint4 instance with RGBA values.
* @param {number} r - Red channel value.
* @param {number} g - Green channel value.
* @param {number} b - Blue channel value.
* @param {number} a - Alpha channel value.
* @returns {ColorUint4} A new ColorUint4 instance.
*/
static rgba(r: number, g: number, b: number, a: number): ColorUint4;
/**
* Gets the value of a specific channel.
* @param {number | Channel} channel - The channel index or Channel enum.
* @returns {number} The value of the channel.
*/
getChannel(channel: number | Channel): 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 other Color instance.
*/
set(c: Color): void;
/**
* Sets the RGB values of the color.
* @param {number} r - Red channel value.
* @param {number} g - Green channel value.
* @param {number} b - Blue channel value.
*/
setRgb(r: number, g: number, b: number): void;
/**
* Sets the RGBA values of the color.
* @param {number} r - Red channel value.
* @param {number} g - Green channel value.
* @param {number} b - Blue channel value.
* @param {number} a - Alpha channel value.
*/
setRgba(r: number, g: number, b: number, a: number): void;
/**
* Converts the color to an array of channel values.
* @returns {number[]} An array of channel values.
*/
toArray(): number[];
/**
* Creates a clone of the current color instance.
* @returns {ColorUint4} A new ColorUint4 instance that is a clone of the current instance.
*/
clone(): ColorUint4;
/**
* 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 current color instance to a different format based on the provided options.
*
* @param {ColorConvertOptions} [opt] - Optional parameters for color conversion.
* @param {string} [opt.format] - The target color format (e.g., 'rgb', 'hex').
* @param {number} [opt.numChannels] - The number of color channels to include in the conversion.
* @param {number} [opt.alpha] - The alpha value for the color conversion.
* @returns {Color} The converted color.
*/
convert(opt?: ColorConvertOptions): Color;
}