/** * Packing factor for palette sizes ≤ 16: how many pixel indices share * a single byte. The spec is fixed; this is a lookup-table summary. */ export declare function packingFactor(paletteSize: number): number; /** * Try to apply the forward color-indexing transform to an ARGB image. * * Returns `null` if the image has more than 256 distinct colors (the * transform isn't applicable). Otherwise mutates `argb` in place: each * pixel becomes `(0xFF << 24) | (paletteIndex << 8)`. For small palettes, * the caller also gets back an "encoded width" smaller than the input — * pixels in `argb[0..encodedWidth*height]` then hold up-to-`packingFactor` * indices each, packed in the green channel low bits. * * Layout of palette indices in a packed pixel's green channel: * bit 0..(bpp-1) = first sub-pixel (leftmost in unpacked coords) * bit bpp..(2bpp-1) = second sub-pixel * ... * where `bpp = 8 / packingFactor`. * * The palette is delta-encoded by the caller (the bitstream uses * `palette[i] - palette[i-1]` so the wire-form palette compresses * better; we leave that delta encoding to the bitstream emitter). */ export declare function applyColorIndexTransform(argb: Uint32Array, width: number, height: number): { palette: Uint32Array, encodedWidth: number, encodedArgb: Uint32Array } | null; /** * Apply the inverse color-indexing transform: take the decoded encoded * image (whose green channel carries packed indices) and the palette, * and produce a fresh ARGB array of original-width pixels. * * The caller passes in the post-delta-decode palette (i.e. already- * accumulated absolute palette values, not the wire-form deltas). */ export declare function inverseColorIndexTransform(encodedArgb: Uint32Array, encodedWidth: number, width: number, height: number, palette: Uint32Array): Uint32Array; /** * Delta-encode a palette for the wire. The bitstream stores * `palette[0]` directly and then each `palette[i] - palette[i-1]` * (channel-wise mod 256). On a smoothly-varying palette (typical of * antialiased UI / iconography) this leaves the differences with * many zero or near-zero channels — much cheaper Huffman codes. */ export declare function deltaEncodePalette(palette: Uint32Array): Uint32Array; /** Reverse of `deltaEncodePalette`. */ export declare function deltaDecodePalette(deltaPalette: Uint32Array): Uint32Array; /** * VP8L color-indexing transform (transform type 3). * * When an image has at most 256 distinct ARGB values — typical of icons, * UI assets, screenshots, and most non-photo content — replace each * pixel with its index into a palette. The 256-entry palette is sent * once at the start of the bitstream as a 1-row sub-image; the main * pixel stream then carries indices in the green channel only. * * For palettes of size ≤ 16 there's an extra trick: pack multiple * indices into a single output pixel, shrinking the encoded image's * width by the corresponding factor. A 4-color palette packs 4 pixels * into one byte (2 bits each); the encoded width becomes * `ceil(width / 4)`. The decoder un-packs after pixel decode. * * Reference: WebP Lossless Bitstream Specification §3.4. */ /** Maximum palette size the spec allows (8-bit `color_table_size - 1`). */ export declare const MAX_PALETTE_SIZE: 256;