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)
219 lines (218 loc) • 8 kB
TypeScript
/** @format */
import { TypedArray } from './typings.js';
/**
* Interface for initializing InputBuffer with options.
*/
export interface InputBufferInitOptions<T extends TypedArray> {
/** The buffer to read from. */
buffer: T;
/** Optional offset to start reading from. */
offset?: number;
/** Optional length of the buffer to read. */
length?: number;
/** Optional flag to indicate big-endian byte order. */
bigEndian?: boolean;
}
/**
* A buffer that can be read as a stream of bytes.
*/
export declare class InputBuffer<T extends TypedArray> {
/** The underlying buffer. */
private _buffer;
/** Sets the buffer. */
set buffer(v: T);
/** Gets the buffer. */
get buffer(): T;
/** Flag indicating if the buffer is in big-endian byte order. */
private _bigEndian;
/** Sets the big-endian flag. */
set bigEndian(v: boolean);
/** Gets the big-endian flag. */
get bigEndian(): boolean;
/** The current offset in the buffer. */
private _offset;
/** Sets the offset. */
set offset(v: number);
/** Gets the offset. */
get offset(): number;
/** The start position of the buffer. */
private _start;
/** Gets the start position. */
get start(): number;
/** The end position of the buffer. */
private _end;
/** Gets the end position. */
get end(): number;
/**
* The current read position relative to the start of the buffer.
*/
get position(): number;
/**
* How many bytes are left in the stream.
*/
get length(): number;
/**
* Is the current position at the end of the stream?
*/
get isEOS(): boolean;
/**
* Create an InputStream for reading from an Array<int>.
* @param {InputBufferInitOptions<T>} opt Initialization options.
*/
constructor(opt: InputBufferInitOptions<T>);
/**
* Create a copy of another InputBuffer.
* @param {InputBuffer<T>} other - The InputBuffer to copy.
* @param {number} [offset] - Optional offset to start copying from.
* @param {number} [length] - Optional length of the buffer to copy.
* @returns {InputBuffer<T>} - A new InputBuffer instance copied from the other buffer.
*/
static from<T extends TypedArray>(other: InputBuffer<T>, offset?: number, length?: number): InputBuffer<T>;
/**
* Reset to the beginning of the stream.
*/
rewind(): void;
/**
* Access the buffer relative from the current position.
* @param {number} index The index relative to the current position.
* @returns {number} The value at the specified index.
*/
get(index: number): number;
/**
* Set a buffer element relative to the current position.
*
* @param {number} index - The index relative to the current position.
* @param {number} value - The value to set.
* @returns {number} - The value that was set.
*/
set(index: number, value: number): number;
/**
* Copy data from another buffer to this buffer.
* @param {number} start The start position in this buffer.
* @param {number} length The number of bytes to copy.
* @param {InputBuffer<T> | T} other The source buffer to copy from.
* @param {number} [offset] The offset in the source buffer to start copying from.
*/
memcpy(start: number, length: number, other: InputBuffer<T> | T, offset?: number): void;
/**
* Set a range of bytes in this buffer to a value.
* @param {number} start The start position in this buffer.
* @param {number} length The number of bytes to set.
* @param {number} value The value to set.
*/
memset(start: number, length: number, value: number): void;
/**
* Return an InputBuffer to read a subset of this stream.
* @param {number} count The number of bytes to read.
* @param {number} [position] The position to start reading from.
* @param {number} offset The offset to start reading from.
* @returns {InputBuffer<T>} A new InputBuffer for the subset.
*/
subarray(count: number, position?: number, offset?: number): InputBuffer<T>;
/**
* Returns the position of the given value within the buffer.
* @param {number} value The value to search for.
* @param {number} offset The offset to start searching from.
* @returns {number} The position of the value, or -1 if not found.
*/
indexOf(value: number, offset?: number): number;
/**
* Read a specified number of bytes from an offset without moving the read position.
* @param {number} count The number of bytes to read.
* @param {number} offset The offset to start reading from.
* @returns {InputBuffer<T>} A new InputBuffer for the read bytes.
*/
peek(count: number, offset?: number): InputBuffer<T>;
/**
* Move the read position by a specified number of bytes.
* @param {number} count The number of bytes to skip.
*/
skip(count: number): void;
/**
* Read a single value from the buffer.
* @returns {number} The value read.
*/
read(): number;
/**
* Read a specified number of bytes from the stream.
* @param {number} count The number of bytes to read.
* @returns {InputBuffer<T>} A new InputBuffer for the read bytes.
*/
readRange(count: number): InputBuffer<T>;
/**
* Read an 8-bit integer from the stream.
* @returns {number} The 8-bit integer read.
*/
readInt8(): number;
/**
* Read a null-terminated string, or a specified number of bytes as a string.
* @param {number} [length] The number of bytes to read as a string.
* @returns {string} The string read.
* @throws {LibError} If EOF is reached without finding string terminator.
*/
readString(length?: number): string;
/**
* Read one line of a null-terminated string, or a specified number of bytes as a string.
* @param {number} length - The number of bytes to read as a string.
* @returns {string} The string read.
*/
readStringLine(length?: number): string;
/**
* Read a null-terminated UTF-8 string.
* @returns {string} The UTF-8 string read.
*/
readStringUtf8(): string;
/**
* Read a 16-bit unsigned integer from the stream.
* @returns {number} The 16-bit unsigned integer read.
*/
readUint16(): number;
/**
* Read a 16-bit signed integer from the stream.
* @returns {number} The 16-bit signed integer read.
*/
readInt16(): number;
/**
* Read a 24-bit unsigned integer from the stream.
* @returns {number} The 24-bit unsigned integer read.
*/
readUint24(): number;
/**
* Read a 32-bit unsigned integer from the stream.
* @returns {number} The 32-bit unsigned integer read.
*/
readUint32(): number;
/**
* Read a 32-bit signed integer from the stream.
* @returns {number} The 32-bit signed integer read.
*/
readInt32(): number;
/**
* Read a 32-bit float from the stream.
* @returns {number} The 32-bit float read.
*/
readFloat32(): number;
/**
* Read a 64-bit float from the stream.
* @returns {number} The 64-bit float read.
*/
readFloat64(): number;
/**
* Read a 64-bit unsigned integer from the stream.
* @returns {bigint} The 64-bit unsigned integer read.
*/
readUint64(): bigint;
/**
* Convert the buffer to a Uint8Array.
* @param {number} offset - The offset to start from.
* @param {number} [length] - The length of the array.
* @returns {Uint8Array} The Uint8Array representation of the buffer.
*/
toUint8Array(offset?: number, length?: number): Uint8Array;
/**
* Convert the buffer to a Uint32Array.
* @param {number} offset - The offset to start from.
* @returns {Uint32Array} The Uint32Array representation of the buffer.
*/
toUint32Array(offset?: number): Uint32Array;
}