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)
186 lines (185 loc) • 8.2 kB
TypeScript
/** @format */
import { Color } from '../color/color.js';
import { Format, FormatType } from '../color/format.js';
import { MemoryImageData, MemoryImageDataGetBytesOptions } from './image-data.js';
import { Palette } from './palette.js';
import { Pixel } from './pixel.js';
import { PixelInt8 } from './pixel-int8.js';
/**
* Class representing an 8-bit memory image data.
* Implements MemoryImageData and Iterable interfaces.
*/
export declare class MemoryImageDataInt8 implements MemoryImageData, Iterable<Pixel> {
/** The width of the image. */
private _width;
/** Gets the width of the image. */
get width(): number;
/** Sets the width of the image. */
set width(v: number);
/** The height of the image. */
private _height;
/** Gets the height of the image. */
get height(): number;
/** Sets the height of the image. */
set height(v: number);
/** The image data stored as an Int8Array. */
private readonly _data;
/** Gets the image data. */
get data(): Int8Array;
/** The number of channels in the image. */
private readonly _numChannels;
/** Gets the number of channels in the image. */
get numChannels(): number;
/** Gets the format of the image data. */
get format(): Format;
/** Gets the format type of the image data. */
get formatType(): FormatType;
/** Gets the buffer of the image data. */
get buffer(): ArrayBufferLike;
/** Gets the row stride of the image data. */
get rowStride(): number;
/** Gets the iterator for the image data. */
get iterator(): PixelInt8;
/** Gets the byte length of the image data. */
get byteLength(): number;
/** Gets the length of the image data. */
get length(): number;
/** Gets the maximum channel value. */
get maxChannelValue(): number;
/** Gets the maximum index value. */
get maxIndexValue(): number;
/** Checks if the image data has a palette. */
get hasPalette(): boolean;
/** Gets the palette of the image data. */
get palette(): Palette | undefined;
/** Checks if the format is HDR. */
get isHdrFormat(): boolean;
/** Checks if the format is LDR. */
get isLdrFormat(): boolean;
/** Gets the bits per channel. */
get bitsPerChannel(): number;
/**
* Constructs a new MemoryImageDataInt8 instance.
* @param {number} width - The width of the image.
* @param {number} height - The height of the image.
* @param {number} numChannels - The number of channels in the image.
* @param {Int8Array} [data] - Optional image data.
*/
constructor(width: number, height: number, numChannels: number, data?: Int8Array);
/**
* Creates a new MemoryImageDataInt8 instance from another instance.
* @param {MemoryImageDataInt8} other - The other MemoryImageDataInt8 instance.
* @param {boolean} [skipPixels=false] - Whether to skip copying pixel data.
* @returns {MemoryImageDataInt8} A new MemoryImageDataInt8 instance.
*/
static from(other: MemoryImageDataInt8, skipPixels?: boolean): MemoryImageDataInt8;
/**
* Gets a range of pixels.
* @param {number} x - The x-coordinate of the starting pixel.
* @param {number} y - The y-coordinate of the starting pixel.
* @param {number} width - The width of the range.
* @param {number} height - The height of the range.
* @returns {Iterator<Pixel>} An iterator for the pixel range.
*/
getRange(x: number, y: number, width: number, height: number): Iterator<Pixel>;
/**
* Gets a color object.
* @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 (optional).
* @returns {Color} A Color object.
*/
getColor(r: number, g: number, b: number, a?: number): Color;
/**
* Gets a pixel at the specified coordinates.
* @param {number} x - The x-coordinate of the pixel.
* @param {number} y - The y-coordinate of the pixel.
* @param {Pixel} [pixel] - Optional pixel object to reuse.
* @returns {Pixel} A Pixel object.
*/
getPixel(x: number, y: number, pixel?: Pixel): Pixel;
/**
* Sets a pixel at the specified coordinates.
* @param {number} x - The x-coordinate of the pixel.
* @param {number} y - The y-coordinate of the pixel.
* @param {Color} p - The color to set.
*/
setPixel(x: number, y: number, p: Color): void;
/**
* Sets the red channel of a pixel at the specified coordinates.
* @param {number} x - The x-coordinate of the pixel.
* @param {number} y - The y-coordinate of the pixel.
* @param {number} r - The red channel value.
*/
setPixelR(x: number, y: number, r: number): void;
/**
* Sets the RGB channels of a pixel at the specified coordinates.
* @param {number} x - The x-coordinate of the pixel.
* @param {number} y - The y-coordinate of the pixel.
* @param {number} r - The red channel value.
* @param {number} g - The green channel value.
* @param {number} b - The blue channel value.
*/
setPixelRgb(x: number, y: number, r: number, g: number, b: number): void;
/**
* Sets the RGBA channels of a pixel at the specified coordinates.
* @param {number} x - The x-coordinate of the pixel.
* @param {number} y - The y-coordinate of the pixel.
* @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.
*/
setPixelRgba(x: number, y: number, r: number, g: number, b: number, a: number): void;
/**
* Safely sets the RGB channels of a pixel at the specified coordinates.
* @param {number} x - The x-coordinate of the pixel.
* @param {number} y - The y-coordinate of the pixel.
* @param {number} r - The red channel value.
* @param {number} g - The green channel value.
* @param {number} b - The blue channel value.
*/
setPixelRgbSafe(x: number, y: number, r: number, g: number, b: number): void;
/**
* Safely sets the RGBA channels of a pixel at the specified coordinates.
* @param {number} x - The x-coordinate of the pixel.
* @param {number} y - The y-coordinate of the pixel.
* @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.
*/
setPixelRgbaSafe(x: number, y: number, r: number, g: number, b: number, a: number): void;
/**
* Clears the image data.
* @param {Color} [_c] - Optional color to clear with.
*/
clear(_c?: Color): void;
/**
* Clones the image data.
* @param {boolean} [skipPixels=false] - Whether to skip copying pixel data.
* @returns {MemoryImageDataInt8} A new MemoryImageDataInt8 instance.
*/
clone(skipPixels?: boolean): MemoryImageDataInt8;
/**
* Converts the image data to a Uint8Array.
* @returns {Uint8Array} A Uint8Array representation of the image data.
*/
toUint8Array(): Uint8Array;
/**
* Gets the bytes of the image data.
* @param {MemoryImageDataGetBytesOptions} [opt] - Optional options for getting the bytes.
* @param {number} [opt.width] - The width of the image. If not provided, the default width will be used.
* @param {number} [opt.height] - The height of the image. If not provided, the default height will be used.
* @param {string} [opt.format] - The format of the image data. Can be 'RGBA', 'RGB', etc.
* @param {boolean} [opt.flipY] - A boolean indicating whether to flip the image data vertically.
* @returns {Uint8Array} A Uint8Array of the image data bytes.
*/
getBytes(opt?: MemoryImageDataGetBytesOptions): Uint8Array;
/**
* Gets the iterator for the image data.
* @returns {Iterator<Pixel, Pixel, undefined>} An iterator for the image data.
*/
[Symbol.iterator](): Iterator<Pixel, Pixel, undefined>;
}