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)
271 lines (270 loc) • 8.24 kB
TypeScript
/** @format */
import { Channel } from '../color/channel.js';
import { Color, ColorConvertOptions } from '../color/color.js';
import { Format } from '../color/format.js';
import { MemoryImage } from './image.js';
import { MemoryImageDataUint8 } from './image-data-uint8.js';
import { Palette } from './palette.js';
import { Pixel } from './pixel.js';
/**
* Represents a pixel in an 8-bit memory image.
*/
export declare class PixelUint8 implements Pixel, Iterable<Pixel>, Iterator<Pixel> {
/**
* The index of the pixel in the image data array.
*/
private _index;
/**
* The image data associated with this pixel.
*/
private readonly _image;
/**
* Gets the image data associated with this pixel.
*/
get image(): MemoryImageDataUint8;
/**
* The x-coordinate of the pixel.
*/
private _x;
/**
* Gets the x-coordinate of the pixel.
*/
get x(): number;
/**
* The y-coordinate of the pixel.
*/
private _y;
/**
* Gets the y-coordinate of the pixel.
*/
get y(): number;
/**
* Gets the normalized x-coordinate of the pixel.
*/
get xNormalized(): number;
/**
* Gets the normalized y-coordinate of the pixel.
*/
get yNormalized(): number;
/**
* Gets or sets the index value of the pixel.
*/
get index(): number;
set index(i: number);
/**
* Gets the image data array.
*/
get data(): Uint8Array;
/**
* Checks if the pixel is valid within the image boundaries.
*/
get isValid(): boolean;
/**
* Gets the width of the image.
*/
get width(): number;
/**
* Gets the height of the image.
*/
get height(): number;
/**
* Gets the number of channels in the image.
*/
get length(): number;
/**
* Gets the number of channels in the image.
*/
get numChannels(): number;
/**
* Gets the maximum channel value.
*/
get maxChannelValue(): number;
/**
* Gets the maximum index value.
*/
get maxIndexValue(): number;
/**
* Gets the format of the image.
*/
get format(): Format;
/**
* Checks if the image is in LDR format.
*/
get isLdrFormat(): boolean;
/**
* Checks if the image is in HDR format.
*/
get isHdrFormat(): boolean;
/**
* Checks if the image has a palette.
*/
get hasPalette(): boolean;
/**
* Gets the palette of the image, if any.
*/
get palette(): Palette | undefined;
/**
* Gets or sets the red channel value.
*/
get r(): number;
set r(r: number);
/**
* Gets or sets the green channel value.
*/
get g(): number;
set g(g: number);
/**
* Gets or sets the blue channel value.
*/
get b(): number;
set b(b: number);
/**
* Gets or sets the alpha channel value.
*/
get a(): number;
set a(a: number);
/**
* Gets or sets the normalized red channel value.
*/
get rNormalized(): number;
set rNormalized(v: number);
/**
* Gets or sets the normalized green channel value.
*/
get gNormalized(): number;
set gNormalized(v: number);
/**
* Gets or sets the normalized blue channel value.
*/
get bNormalized(): number;
set bNormalized(v: number);
/**
* Gets or sets the normalized alpha channel value.
*/
get aNormalized(): number;
set aNormalized(v: number);
/**
* Gets the luminance of the pixel.
*/
get luminance(): number;
/**
* Gets the normalized luminance of the pixel.
*/
get luminanceNormalized(): number;
/**
* Constructs a new PixelUint8 instance.
* @param {number} x - The x-coordinate of the pixel.
* @param {number} y - The y-coordinate of the pixel.
* @param {number} index - The index of the pixel in the image data array.
* @param {MemoryImageDataUint8} image - The image data associated with this pixel.
*/
constructor(x: number, y: number, index: number, image: MemoryImageDataUint8);
/**
* Creates a new PixelUint8 instance for the given image data.
* @param {MemoryImageDataUint8} image - The image data.
* @returns {PixelUint8} A new PixelUint8 instance.
*/
static imageData(image: MemoryImageDataUint8): PixelUint8;
/**
* Creates a new PixelUint8 instance for the given image.
* @param {MemoryImage} image - The image.
* @returns {PixelUint8} A new PixelUint8 instance.
*/
static image(image: MemoryImage): PixelUint8;
/**
* Creates a new PixelUint8 instance from another PixelUint8 instance.
* @param {PixelUint8} other - The other PixelUint8 instance.
* @returns {PixelUint8} A new PixelUint8 instance.
*/
static from(other: PixelUint8): PixelUint8;
/**
* Advances the iterator to the next pixel.
* @returns {IteratorResult<Pixel>} The result of the iteration.
*/
next(): IteratorResult<Pixel>;
/**
* Sets the position of the pixel.
* @param {number} x - The x-coordinate.
* @param {number} y - The y-coordinate.
*/
setPosition(x: number, y: number): void;
/**
* Sets the normalized position of the pixel.
* @param {number} x - The normalized x-coordinate.
* @param {number} y - The normalized y-coordinate.
*/
setPositionNormalized(x: number, y: number): void;
/**
* Gets the value of the specified channel.
* @param {number | Channel} channel - The channel index or Channel enum.
* @returns {number} The value of the specified channel.
*/
getChannel(channel: number | Channel): number;
/**
* Gets the normalized value of the specified channel.
* @param {Channel} channel - The Channel enum.
* @returns {number} The normalized value of the specified channel.
*/
getChannelNormalized(channel: Channel): number;
/**
* Sets the value of the specified channel.
* @param {number} channel - The channel index.
* @param {number} value - The value to set.
*/
setChannel(channel: number, value: number): void;
/**
* Sets the pixel color.
* @param {Color} color - The color to set.
*/
set(color: Color): void;
/**
* Sets the RGB values of the pixel.
* @param {number} r - The red value.
* @param {number} g - The green value.
* @param {number} b - The blue value.
*/
setRgb(r: number, g: number, b: number): void;
/**
* Sets the RGBA values of the pixel.
* @param {number} r - The red value.
* @param {number} g - The green value.
* @param {number} b - The blue value.
* @param {number} a - The alpha value.
*/
setRgba(r: number, g: number, b: number, a: number): void;
/**
* Checks if the pixel is equal to another pixel or array of numbers.
* @param {Pixel | number[]} other - The other pixel or array of numbers.
* @returns {boolean} True if the pixels are equal, false otherwise.
*/
equals(other: Pixel | number[]): boolean;
/**
* Converts the pixel to an array of channel values.
* @returns {number[]} An array of channel values.
*/
toArray(): number[];
/**
* Clones the pixel.
* @returns {PixelUint8} A new PixelUint8 instance.
*/
clone(): PixelUint8;
/**
* Converts the pixel to a color.
* @param {ColorConvertOptions} opt - The color conversion options.
* @param {string} opt.format - The format to convert the color to (e.g., 'rgb', 'hex').
* @param {number} opt.numChannels - The number of color channels (e.g., 3 for RGB, 4 for RGBA).
* @param {number} [opt.alpha] - The alpha value for the color (optional).
* @returns {Color} The converted color.
*/
convert(opt: ColorConvertOptions): Color;
/**
* Converts the pixel to a string representation.
* @returns {string} The string representation of the pixel.
*/
toString(): string;
/**
* Returns the iterator for the pixel.
* @returns {Iterator<Pixel>} The iterator for the pixel.
*/
[ ](): Iterator<Pixel>;
}