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)
147 lines (146 loc) • 5.05 kB
TypeScript
/** @format */
import { InputBuffer } from '../common/input-buffer.js';
import { Decoder, DecoderDecodeOptions } from './decoder.js';
import { PngInfo } from './png/png-info.js';
import { MemoryImage } from '../image/image.js';
import { ImageFormat } from './image-format.js';
/**
* Decode a PNG encoded image.
*/
export declare class PngDecoder implements Decoder {
/**
* The input buffer for the PNG data.
*/
private _input?;
/**
* Get the input buffer.
*/
get input(): InputBuffer<Uint8Array> | undefined;
/**
* Information about the PNG image.
*/
private _info;
/**
* Get the PNG information.
*/
get info(): PngInfo;
/**
* The current progress in the Y direction.
*/
private _progressY;
/**
* Get the current progress in the Y direction.
*/
get progressY(): number;
/**
* The bit buffer used for reading bits.
*/
private _bitBuffer;
/**
* Get the bit buffer.
*/
get bitBuffer(): number;
/**
* The length of the bit buffer.
*/
private _bitBufferLen;
/**
* Get the length of the bit buffer.
*/
get bitBufferLen(): number;
/**
* Get the image format.
*/
get format(): ImageFormat;
/**
* The number of frames that can be decoded.
*/
get numFrames(): number;
/**
* Unfilter a row of pixels.
* @param {PngFilterType} filterType - The type of filter used.
* @param {number} bpp - Bytes per pixel.
* @param {Uint8Array} row - The current row of pixels.
* @param {Uint8Array} [prevRow] - The previous row of pixels.
* @throws {LibError} Throws an error if the filter type is invalid.
*/
private static unfilter;
/**
* Return the CRC of the bytes.
* @param {string} type - The type of the chunk.
* @param {Uint8Array} bytes - The bytes of the chunk.
* @returns {number} The CRC value.
*/
private static crc;
/**
* Process a pass of an interlaced image.
* @param {InputBuffer<Uint8Array>} input - The input buffer.
* @param {MemoryImage} image - The memory image.
* @param {number} xOffset - The X offset.
* @param {number} yOffset - The Y offset.
* @param {number} xStep - The X step.
* @param {number} yStep - The Y step.
* @param {number} passWidth - The width of the pass.
* @param {number} passHeight - The height of the pass.
*/
private processPass;
/**
* Process the input buffer and decode the image.
* @param {InputBuffer<Uint8Array>} input - The input buffer.
* @param {MemoryImage} image - The memory image.
*/
private process;
/**
* Reset the bit buffer.
*/
private resetBits;
/**
* Read a number of bits from the input stream.
* @param {InputBuffer<Uint8Array>} input - The input buffer.
* @param {number} numBits - The number of bits to read.
* @returns {number} The read bits.
* @throws {LibError} If there is invalid PNG data.
*/
private readBits;
/**
* Read the next pixel from the input stream.
* @param {InputBuffer<Uint8Array>} input - The input buffer.
* @param {number[]} pixel - The pixel array to store the read pixel.
*/
private readPixel;
/**
* Set the pixel color.
* @param {Pixel} p - The pixel object.
* @param {number[]} raw - The raw pixel data.
*/
private setPixel;
/**
* Is the given file a valid PNG image?
* @param {Uint8Array} bytes - The bytes of the file.
* @returns {boolean} True if the file is valid, false otherwise.
*/
isValidFile(bytes: Uint8Array): boolean;
/**
* Start decoding the data as an animation sequence, but don't actually
* process the frames until they are requested with decodeFrame.
* @param {Uint8Array} bytes - The bytes of the PNG file.
* @returns {PngInfo | undefined} The PNG information if successful, undefined otherwise.
* @throws {LibError} If there is an invalid checksum or invalid chunk.
*/
startDecode(bytes: Uint8Array): PngInfo | undefined;
/**
* Decode the frame (assuming **startDecode** has already been called).
* @param {number} frameIndex - The index of the frame to decode.
* @returns {MemoryImage | undefined} The decoded MemoryImage or undefined if input is not defined.
* @throws {LibError} If an invalid checksum or frame number is encountered.
*/
decodeFrame(frameIndex: number): MemoryImage | undefined;
/**
* Decode the image based on the provided options.
* @param {DecoderDecodeOptions} opt - The options for decoding the image.
* @param {Uint8Array} opt.bytes - The byte array of the image to decode.
* @param {number} [opt.frameIndex] - The index of the frame to decode (optional).
* @returns {MemoryImage | undefined} The decoded MemoryImage or undefined if decoding fails.
*/
decode(opt: DecoderDecodeOptions): MemoryImage | undefined;
}