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)
226 lines (225 loc) • 8.37 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 { PixelUint4 } from './pixel-uint4.js';
/**
* Class representing memory image data with uint4 format.
*/
export declare class MemoryImageDataUint4 implements MemoryImageData, Iterable<Pixel> {
private _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 data of the image.
*/
private readonly _data;
get data(): Uint8Array;
/**
* The number of channels in the image.
*/
private readonly _numChannels;
get numChannels(): number;
/**
* The format of the image.
*/
get format(): Format;
/**
* The format type of the image.
*/
get formatType(): FormatType;
/**
* The buffer of the image data.
*/
get buffer(): ArrayBufferLike;
private _rowStride;
get rowStride(): number;
/**
* The iterator for the image data.
*/
get iterator(): PixelUint4;
/**
* The byte length of the image data.
*/
get byteLength(): number;
/**
* The length of the image data.
*/
get length(): number;
/**
* The maximum channel value.
*/
get maxChannelValue(): number;
/**
* The maximum index value.
*/
get maxIndexValue(): number;
/**
* Whether the image has a palette.
*/
get hasPalette(): boolean;
private _palette?;
get palette(): Palette | undefined;
set palette(p: Palette | undefined);
/**
* Whether the image format is HDR.
*/
get isHdrFormat(): boolean;
/**
* Whether the image format is LDR.
*/
get isLdrFormat(): boolean;
/**
* The bits per channel.
*/
get bitsPerChannel(): number;
/**
* Creates an instance of MemoryImageDataUint4.
* @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 {Uint8Array} [data] - The data of the image.
*/
constructor(width: number, height: number, numChannels: number, data?: Uint8Array);
/**
* Creates a MemoryImageDataUint4 instance with a palette.
* @param {number} width - The width of the image.
* @param {number} height - The height of the image.
* @param {Palette} [palette] - The palette of the image.
* @returns {MemoryImageDataUint4} A new MemoryImageDataUint4 instance.
*/
static palette(width: number, height: number, palette?: Palette): MemoryImageDataUint4;
/**
* Creates a MemoryImageDataUint4 instance from another instance.
* @param {MemoryImageDataUint4} other - The other MemoryImageDataUint4 instance.
* @param {boolean} [skipPixels=false] - Whether to skip copying pixel data.
* @returns {MemoryImageDataUint4} A new MemoryImageDataUint4 instance.
*/
static from(other: MemoryImageDataUint4, skipPixels?: boolean): MemoryImageDataUint4;
/**
* Gets a range of pixels.
* @param {number} x - The x-coordinate of the range.
* @param {number} y - The y-coordinate of the range.
* @param {number} width - The width of the range.
* @param {number} height - The height of the range.
* @returns {Iterator<Pixel>} An iterator for the range of pixels.
*/
getRange(x: number, y: number, width: number, height: number): Iterator<Pixel>;
/**
* Gets a color.
* @param {number} r - The red component.
* @param {number} g - The green component.
* @param {number} b - The blue component.
* @param {number} [a] - The alpha component.
* @returns {Color} A Color instance.
*/
getColor(r: number, g: number, b: number, a?: number): Color;
/**
* Gets a pixel.
* @param {number} x - The x-coordinate of the pixel.
* @param {number} y - The y-coordinate of the pixel.
* @param {Pixel} [pixel] - The pixel instance to reuse.
* @returns {Pixel} A Pixel instance.
*/
getPixel(x: number, y: number, pixel?: Pixel): Pixel;
/**
* Sets a pixel.
* @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 component of a pixel.
* @param {number} x - The x-coordinate of the pixel.
* @param {number} y - The y-coordinate of the pixel.
* @param {number} r - The red component.
*/
setPixelR(x: number, y: number, r: number): void;
/**
* Sets the RGB components of a pixel.
* @param {number} x - The x-coordinate of the pixel.
* @param {number} y - The y-coordinate of the pixel.
* @param {number} r - The red component.
* @param {number} g - The green component.
* @param {number} b - The blue component.
*/
setPixelRgb(x: number, y: number, r: number, g: number, b: number): void;
/**
* Sets the RGBA components of a pixel.
* @param {number} x - The x-coordinate of the pixel.
* @param {number} y - The y-coordinate of the pixel.
* @param {number} r - The red component.
* @param {number} g - The green component.
* @param {number} b - The blue component.
* @param {number} a - The alpha component.
*/
setPixelRgba(x: number, y: number, r: number, g: number, b: number, a: number): void;
/**
* Safely sets the RGB components of a pixel.
* @param {number} x - The x-coordinate of the pixel.
* @param {number} y - The y-coordinate of the pixel.
* @param {number} r - The red component.
* @param {number} g - The green component.
* @param {number} b - The blue component.
*/
setPixelRgbSafe(x: number, y: number, r: number, g: number, b: number): void;
/**
* Safely sets the RGBA components of a pixel.
* @param {number} x - The x-coordinate of the pixel.
* @param {number} y - The y-coordinate of the pixel.
* @param {number} r - The red component.
* @param {number} g - The green component.
* @param {number} b - The blue component.
* @param {number} a - The alpha component.
*/
setPixelRgbaSafe(x: number, y: number, r: number, g: number, b: number, a: number): void;
/**
* Clears the image.
* @param {Color} [_c] - The color to clear with.
*/
clear(_c?: Color): void;
/**
* Clones the image data.
* @param {boolean} [skipPixels=false] - Whether to skip copying pixel data.
* @returns {MemoryImageDataUint4} A new MemoryImageDataUint4 instance.
*/
clone(skipPixels?: boolean): MemoryImageDataUint4;
/**
* Converts the image data to a Uint8Array.
* @returns {Uint8Array} A Uint8Array of the image data.
*/
toUint8Array(): Uint8Array;
/**
* Gets the bytes of the image data.
* @param {MemoryImageDataGetBytesOptions} [opt] - The options for getting the bytes.
* @param {string} [opt.format] - The format in which to get the bytes (e.g., 'png', 'jpeg').
* @param {number} [opt.quality] - The quality of the image data (e.g., 0.8 for 80% quality).
* @param {number} [opt.width] - The width of the image data to be returned.
* @param {number} [opt.height] - The height of the image data to be returned.
* @returns {Uint8Array} A Uint8Array of the image data bytes.
*/
getBytes(opt?: MemoryImageDataGetBytesOptions): Uint8Array;
/**
* Converts the image data to a string.
* @returns {string} A string representation of the image data.
*/
toString(): string;
/**
* The iterator for the image data.
* @returns {Iterator<Pixel, Pixel, undefined>} An iterator for the image data.
*/
[Symbol.iterator](): Iterator<Pixel, Pixel, undefined>;
}