-
Notifications
You must be signed in to change notification settings - Fork 27
/
jbig2_huffman.h
110 lines (82 loc) · 3.77 KB
/
jbig2_huffman.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/* Copyright (C) 2001-2023 Artifex Software, Inc.
All Rights Reserved.
This software is provided AS-IS with no warranty, either express or
implied.
This software is distributed under license and may not be copied,
modified or distributed except as expressly authorized under the terms
of the license contained in the file LICENSE in this distribution.
Refer to licensing information at http://www.artifex.com or contact
Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
CA 94129, USA, for further information.
*/
/*
jbig2dec
*/
#ifndef _JBIG2_HUFFMAN_H
#define _JBIG2_HUFFMAN_H
/* Huffman coder interface */
typedef struct _Jbig2HuffmanEntry Jbig2HuffmanEntry;
typedef struct _Jbig2HuffmanState Jbig2HuffmanState;
typedef struct _Jbig2HuffmanTable Jbig2HuffmanTable;
typedef struct _Jbig2HuffmanParams Jbig2HuffmanParams;
struct _Jbig2HuffmanEntry {
union {
int32_t RANGELOW;
Jbig2HuffmanTable *ext_table;
} u;
byte PREFLEN;
byte RANGELEN;
byte flags;
};
struct _Jbig2HuffmanTable {
int log_table_size;
Jbig2HuffmanEntry *entries;
};
typedef struct _Jbig2HuffmanLine Jbig2HuffmanLine;
struct _Jbig2HuffmanLine {
int PREFLEN;
int RANGELEN;
int RANGELOW;
};
struct _Jbig2HuffmanParams {
bool HTOOB;
int n_lines;
const Jbig2HuffmanLine *lines;
};
Jbig2HuffmanState *jbig2_huffman_new(Jbig2Ctx *ctx, Jbig2WordStream *ws);
void jbig2_huffman_free(Jbig2Ctx *ctx, Jbig2HuffmanState *hs);
int jbig2_huffman_skip(Jbig2HuffmanState *hs);
int jbig2_huffman_advance(Jbig2HuffmanState *hs, size_t advance);
uint32_t jbig2_huffman_offset(Jbig2HuffmanState *hs);
int32_t jbig2_huffman_get(Jbig2HuffmanState *hs, const Jbig2HuffmanTable *table, bool *oob);
int32_t jbig2_huffman_get_bits(Jbig2HuffmanState *hs, const int bits, int *err);
#ifdef JBIG2_DEBUG
void jbig2_dump_huffman_state(Jbig2HuffmanState *hs);
void jbig2_dump_huffman_binary(Jbig2HuffmanState *hs);
#endif
Jbig2HuffmanTable *jbig2_build_huffman_table(Jbig2Ctx *ctx, const Jbig2HuffmanParams *params);
void jbig2_release_huffman_table(Jbig2Ctx *ctx, Jbig2HuffmanTable *table);
/* standard Huffman templates defined by the specification */
extern const Jbig2HuffmanParams jbig2_huffman_params_A; /* Table B.1 */
extern const Jbig2HuffmanParams jbig2_huffman_params_B; /* Table B.2 */
extern const Jbig2HuffmanParams jbig2_huffman_params_C; /* Table B.3 */
extern const Jbig2HuffmanParams jbig2_huffman_params_D; /* Table B.4 */
extern const Jbig2HuffmanParams jbig2_huffman_params_E; /* Table B.5 */
extern const Jbig2HuffmanParams jbig2_huffman_params_F; /* Table B.6 */
extern const Jbig2HuffmanParams jbig2_huffman_params_G; /* Table B.7 */
extern const Jbig2HuffmanParams jbig2_huffman_params_H; /* Table B.8 */
extern const Jbig2HuffmanParams jbig2_huffman_params_I; /* Table B.9 */
extern const Jbig2HuffmanParams jbig2_huffman_params_J; /* Table B.10 */
extern const Jbig2HuffmanParams jbig2_huffman_params_K; /* Table B.11 */
extern const Jbig2HuffmanParams jbig2_huffman_params_L; /* Table B.12 */
extern const Jbig2HuffmanParams jbig2_huffman_params_M; /* Table B.13 */
extern const Jbig2HuffmanParams jbig2_huffman_params_N; /* Table B.14 */
extern const Jbig2HuffmanParams jbig2_huffman_params_O; /* Table B.15 */
/* Routines to handle "code table segment (53)" */
/* Parse a code table segment, store Jbig2HuffmanParams in segment->result */
int jbig2_table(Jbig2Ctx *ctx, Jbig2Segment *segment, const byte *segment_data);
/* free Jbig2HuffmanParams allocated by jbig2_huffman_table() */
void jbig2_table_free(Jbig2Ctx *ctx, Jbig2HuffmanParams *params);
/* find a user supplied table used by 'segment' and by 'index' */
const Jbig2HuffmanParams *jbig2_find_table(Jbig2Ctx *ctx, Jbig2Segment *segment, int index);
#endif /* _JBIG2_HUFFMAN_H */