reamkit 1.25.1 → 1.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,86 @@
1
+ /** A bilevel raster, one byte per pixel, 1 = black — JBIG2's own sense. */
2
+ export interface Jbig2Bitmap {
3
+ readonly width: number;
4
+ readonly height: number;
5
+ readonly data: Uint8Array;
6
+ }
7
+ /** A context's state: the Table E.1 index and which symbol is currently more probable. */
8
+ interface Cx {
9
+ i: Uint8Array;
10
+ mps: Uint8Array;
11
+ }
12
+ /** §E.3.5 — a fresh set of `size` contexts, all at state 0 with MPS 0. */
13
+ export declare function newContexts(size: number): Cx;
14
+ /**
15
+ * §E.3 — the MQ arithmetic decoder.
16
+ *
17
+ * Written as a class with the spec's own register names (`c`, `a`, `ct`)
18
+ * because the procedures below are transcribed from its flow charts, and a
19
+ * renaming makes them impossible to check against it.
20
+ */
21
+ export declare class MQDecoder {
22
+ private readonly data;
23
+ private bp;
24
+ private readonly end;
25
+ private c;
26
+ private a;
27
+ private ct;
28
+ constructor(data: Uint8Array, start?: number, end?: number);
29
+ private byteAt;
30
+ /** BYTEIN (§E.3.4) — 0xFF is the marker escape, so it feeds a shorter byte. */
31
+ private byteIn;
32
+ /**
33
+ * DECODE (§E.3.2) — one bit in context `k`.
34
+ *
35
+ * @param cx The context set the caller keeps for this decoding procedure.
36
+ * @param k Which context within it.
37
+ */
38
+ decode(cx: Cx, k: number): number;
39
+ }
40
+ /** An adaptive template pixel — a coordinate the coder may move (§6.2.5.3). */
41
+ interface At {
42
+ readonly x: number;
43
+ readonly y: number;
44
+ }
45
+ /**
46
+ * §6.2.5.7 — decode a generic region with the arithmetic coder.
47
+ *
48
+ * The context for a pixel is the pattern of already-decoded neighbours the
49
+ * template names, read MSB first in the order the figures give. `TPGDON` adds a
50
+ * per-row bit that says "this row is the same as the one above", which is what
51
+ * makes a page of white space nearly free.
52
+ *
53
+ * @param mq The decoder, positioned at the region's data.
54
+ * @param cx The 2^16 generic contexts (shared across a segment's regions).
55
+ * @param width Region width in pixels.
56
+ * @param height Region height in pixels.
57
+ * @param template Which of the four templates (0-3).
58
+ * @param at The adaptive pixels, one for templates 1-3 and four for 0.
59
+ * @param tpgdon Whether typical prediction is on.
60
+ * @param skip A bitmap of pixels to leave white without decoding (halftone).
61
+ */
62
+ export declare function decodeGenericRegion(mq: MQDecoder, cx: Cx, width: number, height: number, template: number, at: ReadonlyArray<At>, tpgdon: boolean, skip?: Jbig2Bitmap): Jbig2Bitmap;
63
+ /**
64
+ * §6.3.5.6 — refine `reference` into a bitmap of `width` × `height`.
65
+ *
66
+ * Refinement codes a bitmap against one already decoded — the same glyph at a
67
+ * lower resolution, or the same region in an earlier pass — so only where the
68
+ * two differ costs anything.
69
+ *
70
+ * @param dx Where the reference sits relative to the region (GRREFERENCEDX).
71
+ * @param dy Likewise, vertically.
72
+ */
73
+ export declare function decodeRefinement(mq: MQDecoder, cx: Cx, width: number, height: number, template: number, reference: Jbig2Bitmap, dx: number, dy: number, at: ReadonlyArray<At>, tpgron: boolean): Jbig2Bitmap;
74
+ /**
75
+ * Decode an embedded JBIG2 image.
76
+ *
77
+ * @param data The `/JBIG2Decode` stream's own segments.
78
+ * @param globals The `/JBIG2Globals` stream's segments, when the image names one.
79
+ * @param width The image's `/Width`, which the page info may not state.
80
+ * @param height Its `/Height`.
81
+ * @returns A packed 1-bit-per-pixel bitmap (`rowBytes × height`, bit 1 = black,
82
+ * MSB first) — the same shape {@link decodeCcitt} returns — or `undefined`
83
+ * when nothing in the stream could be decoded.
84
+ */
85
+ export declare function decodeJbig2(data: Uint8Array, globals: Uint8Array | undefined, width: number, height: number): Uint8Array | undefined;
86
+ export {};