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)
250 lines (249 loc) • 8.88 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 { PixelUint1 } from './pixel-uint1.js';
/**
* Class representing memory image data with 1-bit per pixel.
*/
export declare class MemoryImageDataUint1 implements MemoryImageData, Iterable<Pixel> {
/**
* Optional pixel data.
*/
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);
/**
* Image data.
*/
private readonly _data;
/**
* Gets the image data.
*/
get data(): Uint8Array;
/**
* 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.
*/
get format(): Format;
/**
* Gets the format type of the image.
*/
get formatType(): FormatType;
/**
* Gets the buffer of the image data.
*/
get buffer(): ArrayBufferLike;
/**
* Row stride of the image.
*/
private _rowStride;
/**
* Gets the row stride of the image.
*/
get rowStride(): number;
/**
* Gets the iterator for the image data.
*/
get iterator(): PixelUint1;
/**
* 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 has a palette.
*/
get hasPalette(): boolean;
/**
* Optional palette for the image.
*/
private _palette?;
/**
* Gets the palette of the image.
*/
get palette(): Palette | undefined;
/**
* Sets the palette of the image.
*/
set palette(p: Palette | undefined);
/**
* Checks if the image format is HDR.
*/
get isHdrFormat(): boolean;
/**
* Checks if the image format is LDR.
*/
get isLdrFormat(): boolean;
/**
* Gets the bits per channel.
*/
get bitsPerChannel(): number;
/**
* Creates an instance of MemoryImageDataUint1.
* @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] - Optional image data.
*/
constructor(width: number, height: number, numChannels: number, data?: Uint8Array);
/**
* Creates a MemoryImageDataUint1 instance with a palette.
* @param {number} width - The width of the image.
* @param {number} height - The height of the image.
* @param {Palette} [palette] - Optional palette for the image.
* @returns {MemoryImageDataUint1} A new MemoryImageDataUint1 instance.
*/
static palette(width: number, height: number, palette?: Palette): MemoryImageDataUint1;
/**
* Creates a MemoryImageDataUint1 instance from another instance.
* @param {MemoryImageDataUint1} other - The other MemoryImageDataUint1 instance.
* @param {boolean} [skipPixels=false] - Whether to skip copying pixel data.
* @returns {MemoryImageDataUint1} A new MemoryImageDataUint1 instance.
*/
static from(other: MemoryImageDataUint1, skipPixels?: boolean): MemoryImageDataUint1;
/**
* 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 from the given RGBA values.
* @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 at the given coordinates.
* @param {number} x - The x-coordinate.
* @param {number} y - The y-coordinate.
* @param {Pixel} [pixel] - Optional pixel instance to reuse.
* @returns {Pixel} A Pixel instance.
*/
getPixel(x: number, y: number, pixel?: Pixel): Pixel;
/**
* Sets a pixel at the given coordinates with the given color.
* @param {number} x - The x-coordinate.
* @param {number} y - The y-coordinate.
* @param {Color} p - The color to set.
*/
setPixel(x: number, y: number, p: Color): void;
/**
* Sets the red component of a pixel at the given coordinates.
* @param {number} x - The x-coordinate.
* @param {number} y - The y-coordinate.
* @param {number} r - The red component.
*/
setPixelR(x: number, y: number, r: number): void;
/**
* Sets the RGB components of a pixel at the given coordinates.
* @param {number} x - The x-coordinate.
* @param {number} y - The y-coordinate.
* @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 at the given coordinates.
* @param {number} x - The x-coordinate.
* @param {number} y - The y-coordinate.
* @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 at the given coordinates.
* @param {number} x - The x-coordinate.
* @param {number} y - The y-coordinate.
* @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 at the given coordinates.
* @param {number} x - The x-coordinate.
* @param {number} y - The y-coordinate.
* @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 data.
* @param {Color} [_c] - Optional color to clear with.
*/
clear(_c?: Color): void;
/**
* Clones the current image data.
* @param {boolean} [skipPixels=false] - Whether to skip copying pixel data.
* @returns {MemoryImageDataUint1} A new MemoryImageDataUint1 instance.
*/
clone(skipPixels?: boolean): MemoryImageDataUint1;
/**
* Converts the image data to a Uint8Array.
* @returns {Uint8Array} A Uint8Array representing 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.
* @param {number} [opt.height] - The height of the image.
* @param {string} [opt.format] - The format of the image data (e.g., 'RGBA', 'RGB').
* @param {boolean} [opt.flipY] - A boolean indicating whether to flip the image vertically.
* @returns {Uint8Array} A Uint8Array representing the image data bytes.
*/
getBytes(opt?: MemoryImageDataGetBytesOptions): Uint8Array;
/**
* Converts the image data to a string representation.
* @returns {string} A string representing the image data.
*/
toString(): string;
/**
* Gets the iterator for the image data.
* @returns {Iterator<Pixel, Pixel, undefined>} An iterator for the image data.
*/
[Symbol.iterator](): Iterator<Pixel, Pixel, undefined>;
}