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)

184 lines (183 loc) 5.45 kB
/** @format */ import { VP8LBitReader } from './vp8l-bit-reader.js'; /** * Class representing a Huffman Tree. */ export declare class HuffmanTree { /** * Fast lookup for short bit lengths. * @private */ private readonly _lutBits; /** * Fast lookup for symbols. * @private */ private readonly _lutSymbol; /** * Fast lookup for jump values. * @private */ private readonly _lutJump; /** * All the nodes, starting at root, stored as a single int array, where * each node occupies two ints as [symbol, children]. * @private */ private _tree; /** * Maximum number of nodes. * @private */ private _maxNodes; /** * Number of currently occupied nodes. * @private */ private _numNodes; /** * Gets the number of currently occupied nodes. * @returns {number} The number of nodes. */ get numNodes(): number; /** * Checks if the tree is full. * @returns {boolean} True if the tree is full, false otherwise. */ get isFull(): boolean; /** * Creates an instance of HuffmanTree. * @param {number} [numLeaves=0] - The number of leaves. */ constructor(numLeaves?: number); /** * Adds a symbol to the Huffman tree. * @private * @param {number} symbol - The symbol to add. * @param {number} code - The code for the symbol. * @param {number} codeLength - The length of the code. * @returns {boolean} True if the symbol was added successfully, false otherwise. */ private addSymbol; /** * Reverses the bits of a short integer. * @private * @param {number} bits - The bits to reverse. * @param {number} numBits - The number of bits. * @returns {number} The reversed bits. */ private reverseBitsShort; /** * Gets the next node in the tree. * @private * @param {number} node - The current node. * @param {number} rightChild - The right child. * @returns {number} The next node. */ private nextNode; /** * Gets the symbol of a node. * @private * @param {number} node - The node. * @returns {number} The symbol. */ private nodeSymbol; /** * Sets the symbol of a node. * @private * @param {number} node - The node. * @param {number} symbol - The symbol. */ private nodeSetSymbol; /** * Gets the children of a node. * @private * @param {number} node - The node. * @returns {number} The children. */ private nodeChildren; /** * Sets the children of a node. * @private * @param {number} node - The node. * @param {number} children - The children. */ private nodeSetChildren; /** * Checks if a node is not a leaf. * @private * @param {number} node - The node. * @returns {boolean} True if the node is not a leaf, false otherwise. */ private nodeIsNotLeaf; /** * Checks if a node is empty. * @private * @param {number} node - The node. * @returns {boolean} True if the node is empty, false otherwise. */ private nodeIsEmpty; /** * Assigns children to a node. * @private * @param {number} node - The node. */ private assignChildren; /** * Converts Huffman code lengths to codes. * @private * @param {Int32Array} codeLengths - The code lengths. * @param {number} codeLengthsSize - The size of the code lengths. * @param {Int32Array} huffCodes - The Huffman codes. * @returns {boolean} True if the conversion was successful, false otherwise. */ private huffmanCodeLengthsToCodes; /** * Initializes the Huffman tree. * @private * @param {number} numLeaves - The number of leaves. * @returns {boolean} True if the initialization was successful, false otherwise. */ private init; /** * Builds the Huffman tree implicitly. * @param {Int32Array} codeLengths - The code lengths. * @param {number} codeLengthsSize - The size of the code lengths. * @returns {boolean} True if the tree was built successfully, false otherwise. */ buildImplicit(codeLengths: Int32Array, codeLengthsSize: number): boolean; /** * Builds the Huffman tree explicitly. * @param {number[]} codeLengths - The code lengths. * @param {number[]} codes - The codes. * @param {number[]} symbols - The symbols. * @param {number} maxSymbol - The maximum symbol. * @param {number} numSymbols - The number of symbols. * @returns {boolean} True if the tree was built successfully, false otherwise. */ buildExplicit(codeLengths: number[], codes: number[], symbols: number[], maxSymbol: number, numSymbols: number): boolean; /** * Decodes the next Huffman code from bit-stream. * @param {VP8LBitReader} br - The bit reader. * @returns {number} The decoded symbol. */ readSymbol(br: VP8LBitReader): number; /** * Number of bits for Huffman lookup table. * @private * @static */ private static readonly huffmanLutBits; /** * Size of Huffman lookup table. * @private * @static */ private static readonly huffmanLut; /** * Pre-reversed 4-bit values. * @private * @static */ private static readonly reversedBits; }