UNPKG

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)

118 lines (117 loc) 4.06 kB
/** @format */ import { MemoryImage } from '../image/image.js'; import { Decoder, DecoderDecodeOptions } from './decoder.js'; import { ImageFormat } from './image-format.js'; import { WebPInfo } from './webp/webp-info.js'; /** * Decode a WebP formatted image. This supports lossless (vp8l), lossy (vp8), * lossy+alpha, and animated WebP images. */ export declare class WebPDecoder implements Decoder { /** * Input buffer for the WebPDecoder. * @private */ private _input; /** * Internal WebP information. * @private */ private _info; /** * Get the WebP information. * @returns {WebPInfo | undefined} The WebP information. */ get info(): WebPInfo | undefined; /** * Get the image format. * @returns {ImageFormat} The image format. */ get format(): ImageFormat; /** * Get the number of frames available to decode. * @returns {number} The number of frames. */ get numFrames(): number; /** * Constructor for WebPDecoder. * @param {Uint8Array} [bytes] - Optional bytes to start decoding. */ constructor(bytes?: Uint8Array); /** * Decode a frame internally. * @private * @param {InputBuffer<Uint8Array>} input - The input buffer. * @param {number} [frameIndex=0] - The frame index. * @returns {MemoryImage | undefined} The decoded image. */ private decodeFrameInternal; /** * Validate the WebP format header. * @private * @param {InputBuffer<Uint8Array>} input - The input buffer. * @returns {boolean} True if valid, false otherwise. */ private getHeader; /** * Get information about the WebP image. * @private * @param {InputBuffer<Uint8Array>} input - The input buffer. * @param {WebPInfoInternal} webp - The WebP information. * @returns {boolean} True if successful, false otherwise. */ private getInfo; /** * Get VP8X information. * @private * @param {InputBuffer<Uint8Array>} input - The input buffer. * @param {WebPInfo} [webp] - The WebP information. * @returns {boolean} True if successful, false otherwise. */ private getVp8xInfo; /** * Get animation information. * @private * @param {InputBuffer<Uint8Array>} input - The input buffer. * @param {WebPInfo} webp - The WebP information. * @returns {boolean} True if successful, false otherwise. */ private getAnimInfo; /** * Get animation frame information. * @private * @param {InputBuffer<Uint8Array>} input - The input buffer. * @param {WebPInfo} webp - The WebP information. * @param {number} size - The size of the frame. * @returns {boolean} True if successful, false otherwise. */ private getAnimFrameInfo; /** * Is the given file a valid WebP image? * @param {Uint8Array} bytes - The file bytes. * @returns {boolean} True if valid, false otherwise. */ isValidFile(bytes: Uint8Array): boolean; /** * Validate the file is a WebP image and get information about it. * If the file is not a valid WebP image, undefined is returned. * @param {Uint8Array} bytes - The file bytes. * @returns {WebPInfo | undefined} The WebP information. */ startDecode(bytes: Uint8Array): WebPInfo | undefined; /** * Decode a WebP formatted file stored in **bytes** into an Image. * If it's not a valid WebP file, undefined is returned. * @param {DecoderDecodeOptions} opt - The decode options. * @param {Uint8Array} opt.bytes - The file bytes. * @param {number} [opt.frameIndex] - The frame index to decode. * @returns {MemoryImage | undefined} The decoded image. */ decode(opt: DecoderDecodeOptions): MemoryImage | undefined; /** * Decode a specific frame. * @param {number} frameIndex - The frame index. * @returns {MemoryImage | undefined} The decoded image. */ decodeFrame(frameIndex: number): MemoryImage | undefined; }