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)

191 lines (190 loc) 7.04 kB
/** @format */ import { InputBuffer } from '../../common/input-buffer.js'; import { JpegComponentData } from './jpeg-component-data.js'; import { JpegAdobe } from './jpeg-adobe.js'; import { JpegFrame } from './jpeg-frame.js'; import { JpegInfo } from './jpeg-info.js'; import { JpegJfif } from './jpeg-jfif.js'; import { ExifData } from '../../exif/exif-data.js'; import { MemoryImage } from '../../image/image.js'; import { HuffmanNode } from './huffman-node.js'; import { IccProfile } from '../../image/icc-profile.js'; /** * Class representing JPEG data. */ export declare class JpegData { /** * Zigzag order for DCT coefficients. */ static readonly dctZigZag: number[]; /** * The basic DCT block is 8x8 samples. */ static readonly dctSize = 8; /** * DCTSIZE squared; # of elements in a block. */ static readonly dctSize2 = 64; /** * Quantization tables are 0..3. */ static readonly numQuantizationTables = 4; /** * Huffman tables are numbered 0..3. */ static readonly numHuffmanTables = 4; /** * Arith-coding tables are numbered 0..15. */ static readonly numArithTables = 16; /** * JPEG limit on # of components in one scan. */ static readonly maxCompsInScan = 4; /** * JPEG limit on sampling factors. */ static readonly maxSamplingFactor = 4; private _input; get input(): InputBuffer<Uint8Array>; private _jfif; get jfif(): JpegJfif; private _adobe; get adobe(): JpegAdobe; private _frame?; get frame(): JpegFrame | undefined; private _resetInterval; get resetInterval(): number; private _comment?; get comment(): string | undefined; private _iccProfile?; get iccProfile(): IccProfile | undefined; private readonly _exifData; get exifData(): ExifData; private readonly _quantizationTables; get quantizationTables(): Array<Int16Array | undefined>; private readonly _frames; get frames(): Array<JpegFrame | undefined>; private readonly _huffmanTablesAC; get huffmanTablesAC(): Array<Array<HuffmanNode | undefined> | undefined>; private readonly _huffmanTablesDC; get huffmanTablesDC(): Array<Array<HuffmanNode | undefined> | undefined>; private readonly _components; get components(): Array<JpegComponentData>; get width(): number; get height(): number; /** * Reads JPEG markers from the input buffer. */ private readMarkers; /** * Skips a block in the input buffer. */ private skipBlock; /** * Validates the JPEG data. * @param {Uint8Array} bytes - The input byte array. * @returns {boolean} True if the data is valid JPEG, otherwise false. */ validate(bytes: Uint8Array): boolean; /** * Reads JPEG information from the input byte array. * @param {Uint8Array} bytes - The input byte array. * @returns {JpegInfo | undefined} The JPEG information or undefined if invalid. */ readInfo(bytes: Uint8Array): JpegInfo | undefined; /** * Reads JPEG data from the input byte array. * @param {Uint8Array} bytes - The input byte array. * @throws {LibError} Only single frame JPEGs supported. */ read(bytes: Uint8Array): void; /** * Gets the image from the JPEG data. * @returns {MemoryImage} The memory image. */ getImage(): MemoryImage; /** * Builds a Huffman table. * @param {Uint8Array} codeLengths - The code lengths. * @param {Uint8Array} values - The values. * @returns {Array<HuffmanNode | undefined>} The Huffman table. */ private static buildHuffmanTable; /** * Builds component data. * @param {JpegComponent} component - The JPEG component. * @returns {Array<Uint8Array | undefined>} The component data. */ private static buildComponentData; /** * Converts a value to fixed-point representation. * @param {number} val - The value to convert. * @returns {number} The fixed-point representation. */ static toFix(val: number): number; /** * Reads a block from the input buffer. * @returns {InputBuffer<Uint8Array>} The input buffer containing the block. * @throws {LibError} If the block length is invalid. */ private readBlock; /** * Reads the next marker from the input buffer. * @returns {number} The next marker. */ private nextMarker; /** * Reads the ICC profile data from the provided input buffer. * @param {InputBuffer<Uint8Array>} block - The input buffer containing the ICC profile data. */ private readIccProfile; /** * Reads the EXIF data from the provided input buffer. * @param {InputBuffer<Uint8Array>} block - The input buffer containing the EXIF data. */ private readExifData; /** * Reads application-specific data from the JPEG file based on the marker provided. * @param {number} marker - The marker indicating the type of application data. * @param {InputBuffer<Uint8Array>} block - The input buffer containing the application data. */ private readAppData; /** * Reads the Define Quantization Table (DQT) from the provided input buffer. * This method processes the DQT block, extracting quantization tables and storing them. * @param {InputBuffer<Uint8Array>} block - The input buffer containing the DQT block data. * @throws {LibError} If the number of quantization tables is invalid or if the DQT block length is incorrect. */ private readDQT; /** * Reads a JPEG frame from the input buffer and initializes the frame data. * Throws an error if a duplicate frame is found. * @param {number} marker - The JPEG marker indicating the type of frame. * @param {InputBuffer<Uint8Array>} block - The input buffer containing the frame data. * @throws {LibError} If duplicate JPEG frame data is found. */ private readFrame; /** * Reads the Define Huffman Table (DHT) segment from the input buffer. * This method processes the Huffman table definitions used for decoding * JPEG images, distinguishing between AC and DC tables. * * @param {InputBuffer<Uint8Array>} block - The input buffer containing the DHT segment data. */ private readDHT; /** * Reads the Define Restart Interval (DRI) marker segment from the input buffer. * This marker segment specifies the interval between restart markers in the compressed data stream. * * @param {InputBuffer<Uint8Array>} block - The input buffer containing the DRI marker segment. */ private readDRI; /** * Reads the Start of Scan (SOS) block from the input buffer and decodes the scan. * * @param {InputBuffer<Uint8Array>} block - The input buffer containing the SOS block data. * @throws {LibError} - Throws an error if the SOS block is invalid or if a component is invalid. */ private readSOS; }