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)

112 lines (111 loc) 3.87 kB
/** @format */ import { Color } from '../color/color.js'; import { MemoryImage } from './image.js'; import { PaletteUint8 } from './palette-uint8.js'; import { Quantizer } from './quantizer.js'; /** * Color quantization using octree, * from https://rosettacode.org/wiki/Color_quantization/C */ export declare class OctreeQuantizer implements Quantizer { /** * A constant representing the node is in the heap. */ private static readonly _inHeap; /** * The root node of the octree. */ private readonly _root; /** * The palette generated by the quantizer. */ private _palette; /** * Gets the palette generated by the quantizer. */ get palette(): PaletteUint8; /** * Constructs an OctreeQuantizer. * @param {MemoryImage} image - The image to be quantized. * @param {number} [numberOfColors=256] - The number of colors to reduce the image to. */ constructor(image: MemoryImage, numberOfColors?: number); /** * Inserts a color into the octree. * @param {OctreeNode} root - The root node of the octree. * @param {number} r - The red component of the color. * @param {number} g - The green component of the color. * @param {number} b - The blue component of the color. * @returns {OctreeNode} The inserted node. */ private nodeInsert; /** * Pops the top node from the heap. * @param {HeapNode} h - The heap. * @returns {OctreeNode | undefined} The popped node or undefined if the heap is empty. */ private popHeap; /** * Adds a node to the heap. * @param {HeapNode} h - The heap. * @param {OctreeNode} p - The node to add. */ private heapAdd; /** * Moves a node down the heap to maintain heap property. * @param {HeapNode} h - The heap. * @param {OctreeNode} p - The node to move. */ private downHeap; /** * Moves a node up the heap to maintain heap property. * @param {HeapNode} h - The heap. * @param {OctreeNode} p - The node to move. */ private upHeap; /** * Folds a node into its parent. * @param {OctreeNode} p - The node to fold. * @returns {OctreeNode | undefined} The parent node or undefined if the node has children. */ private nodeFold; /** * Compares two nodes. * @param {OctreeNode} a - The first node. * @param {OctreeNode} b - The second node. * @returns {number} A negative number if a < b, a positive number if a > b, or 0 if they are equal. */ private compareNode; /** * Gets all leaf nodes of the octree. * @param {OctreeNode[]} nodes - The array to store the nodes. * @param {OctreeNode} node - The current node. */ private getNodes; /** * Gets the index of the color in the palette. * @param {Color} c - The color. * @returns {number} The index of the color in the palette. */ getColorIndex(c: Color): number; /** * Gets the index of the color in the palette using RGB values. * @param {number} r - The red component of the color. * @param {number} g - The green component of the color. * @param {number} b - The blue component of the color. * @returns {number} The index of the color in the palette. */ getColorIndexRgb(r: number, g: number, b: number): number; /** * Find the index of the closest color to **c** in the **palette**. * @param {Color} c - The color to find the closest match for. * @returns {Color} The closest color in the palette. */ getQuantizedColor(c: Color): Color; /** * Convert the **image** to a palette image. * @param {MemoryImage} image - The image to convert. * @returns {MemoryImage} The palette image. */ getIndexImage(image: MemoryImage): MemoryImage; }