/** A bilevel raster, one byte per pixel, 1 = black — JBIG2's own sense. */ export interface Jbig2Bitmap { readonly width: number; readonly height: number; readonly data: Uint8Array; } /** A context's state: the Table E.1 index and which symbol is currently more probable. */ interface Cx { i: Uint8Array; mps: Uint8Array; } /** §E.3.5 — a fresh set of `size` contexts, all at state 0 with MPS 0. */ export declare function newContexts(size: number): Cx; /** * §E.3 — the MQ arithmetic decoder. * * Written as a class with the spec's own register names (`c`, `a`, `ct`) * because the procedures below are transcribed from its flow charts, and a * renaming makes them impossible to check against it. */ export declare class MQDecoder { private readonly data; private bp; private readonly end; private c; private a; private ct; constructor(data: Uint8Array, start?: number, end?: number); private byteAt; /** BYTEIN (§E.3.4) — 0xFF is the marker escape, so it feeds a shorter byte. */ private byteIn; /** * DECODE (§E.3.2) — one bit in context `k`. * * @param cx The context set the caller keeps for this decoding procedure. * @param k Which context within it. */ decode(cx: Cx, k: number): number; } /** An adaptive template pixel — a coordinate the coder may move (§6.2.5.3). */ interface At { readonly x: number; readonly y: number; } /** * §6.2.5.7 — decode a generic region with the arithmetic coder. * * The context for a pixel is the pattern of already-decoded neighbours the * template names, read MSB first in the order the figures give. `TPGDON` adds a * per-row bit that says "this row is the same as the one above", which is what * makes a page of white space nearly free. * * @param mq The decoder, positioned at the region's data. * @param cx The 2^16 generic contexts (shared across a segment's regions). * @param width Region width in pixels. * @param height Region height in pixels. * @param template Which of the four templates (0-3). * @param at The adaptive pixels, one for templates 1-3 and four for 0. * @param tpgdon Whether typical prediction is on. * @param skip A bitmap of pixels to leave white without decoding (halftone). */ export declare function decodeGenericRegion(mq: MQDecoder, cx: Cx, width: number, height: number, template: number, at: ReadonlyArray, tpgdon: boolean, skip?: Jbig2Bitmap): Jbig2Bitmap; /** * §6.3.5.6 — refine `reference` into a bitmap of `width` × `height`. * * Refinement codes a bitmap against one already decoded — the same glyph at a * lower resolution, or the same region in an earlier pass — so only where the * two differ costs anything. * * @param dx Where the reference sits relative to the region (GRREFERENCEDX). * @param dy Likewise, vertically. */ export declare function decodeRefinement(mq: MQDecoder, cx: Cx, width: number, height: number, template: number, reference: Jbig2Bitmap, dx: number, dy: number, at: ReadonlyArray, tpgron: boolean): Jbig2Bitmap; /** * §6.4.5 — draw a text region: a run of strips, each holding instances of the * symbols in `symbols`, placed by running coordinates rather than absolute ones. * * This is what JBIG2 is for. A scanned page is not stored as pixels but as "the * shape called 37, here; the shape called 12, four pixels on" — so the letter * "e" costs its bitmap once and a few bits per occurrence after that. */ /** * §6.4.5 Table 34 — SBSYMCODELEN, how many bits a text region spends naming * one of its symbols. * * `ceil(log2(SBNUMSYMS))`, and for ONE symbol that is ZERO: there is nothing to * choose, so no bits are read and the id is always that symbol. * Rounded up to one — which the HUFFMAN side of the same table does need — the * decoder takes a bit belonging to the next field and reads the id as 1, which * is no symbol at all: bitmap-symbol-big-segmentid.pdf places one instance of * one symbol in each of two regions, and both came back empty. * * @param symbols How many symbols the region has to choose between. * @returns The number of bits an id takes. */ export declare function symbolCodeLength(symbols: number): number; /** * Decode an embedded JBIG2 image. * * @param data The `/JBIG2Decode` stream's own segments. * @param globals The `/JBIG2Globals` stream's segments, when the image names one. * @param width The image's `/Width`, which the page info may not state. * @param height Its `/Height`. * @returns A packed 1-bit-per-pixel bitmap (`rowBytes × height`, bit 1 = black, * MSB first) — the same shape {@link decodeCcitt} returns — or `undefined` * when nothing in the stream could be decoded. */ export declare function decodeJbig2(data: Uint8Array, globals: Uint8Array | undefined, width: number, height: number): Uint8Array | undefined; export {};