Debian Codegraph @

converter/other/jbig/libjbig/include/jbig.h

raw
1 /*
2 * Header file for the portable JBIG compression library
3 *
4 * Copyright 1995-2014 -- Markus Kuhn -- http://www.cl.cam.ac.uk/~mgk25/
5 */
6
7 #ifndef JBG_H
8 #define JBG_H
9
10 #include <stddef.h>
11 #include "jbig_ar.h"
12
13 /*
14 * JBIG-KIT version number
15 */
16
17 #define JBG_VERSION "2.1"
18 #define JBG_VERSION_MAJOR 2
19 #define JBG_VERSION_MINOR 1
20
21 /*
22 * JBIG-KIT licence agreement reference code:
23 * If you use JBIG-KIT under a commercial licence, please replace
24 * below the letters GPL with the reference code that you received
25 * with your licence agreement. (This code is typically a letter "A"
26 * followed by four decimal digits, e.g. "A1234".)
27 */
28
29 #define JBG_LICENCE "GPL"
30
31 /*
32 * Buffer block for SDEs which are temporarily stored by encoder
33 */
34
35 #define JBG_BUFSIZE 4000
36
37 struct jbg_buf {
38 unsigned char d[JBG_BUFSIZE]; /* one block of a buffer list */
39 int len; /* length of the data in this block */
40 struct jbg_buf *next; /* pointer to next block */
41 struct jbg_buf *previous; /* pointer to previous block *
42 * (unused in freelist) */
43 struct jbg_buf *last; /* only used in list head: final block of list */
44 struct jbg_buf **free_list; /* pointer to pointer to head of free list */
45 };
46
47 /*
48 * Maximum number of ATMOVEs per stripe that decoder can handle
49 */
50
51 #define JBG_ATMOVES_MAX 64
52
53 /*
54 * Option and order flags
55 */
56
57 #define JBG_HITOLO 0x08
58 #define JBG_SEQ 0x04
59 #define JBG_ILEAVE 0x02
60 #define JBG_SMID 0x01
61
62 #define JBG_LRLTWO 0x40
63 #define JBG_VLENGTH 0x20
64 #define JBG_TPDON 0x10
65 #define JBG_TPBON 0x08
66 #define JBG_DPON 0x04
67 #define JBG_DPPRIV 0x02
68 #define JBG_DPLAST 0x01
69
70 /* encoding options that will not be indicated in the header */
71
72 #define JBG_DELAY_AT 0x100 /* Delay ATMOVE until the first line of the next
73 * stripe. Option available for compatibility
74 * with conformance test example in clause 7.2. */
75
76 #define JBG_SDRST 0x200 /* Use SDRST instead of SDNORM. This option is
77 * there for anyone who needs to generate
78 * test data that covers the SDRST cases. */
79
80 /*
81 * Possible error code return values
82 */
83
84 #define JBG_EOK (0 << 4)
85 #define JBG_EOK_INTR (1 << 4)
86 #define JBG_EAGAIN (2 << 4)
87 #define JBG_ENOMEM (3 << 4)
88 #define JBG_EABORT (4 << 4)
89 #define JBG_EMARKER (5 << 4)
90 #define JBG_EINVAL (6 << 4)
91 #define JBG_EIMPL (7 << 4)
92 #define JBG_ENOCONT (8 << 4)
93
94 /*
95 * Status of a JBIG encoder
96 */
97
98 struct jbg_enc_state {
99 int d; /* resolution layer of the input image */
100 unsigned long xd, yd; /* size of the input image (resolution layer d) */
101 unsigned long yd1; /* BIH announced height of image, use yd1 != yd to
102 emulate T.85-style NEWLEN height updates for tests */
103 int planes; /* number of different bitmap planes */
104 int dl; /* lowest resolution layer in the next BIE */
105 int dh; /* highest resolution layer in the next BIE */
106 unsigned long l0; /* number of lines per stripe at lowest *
107 * resolution layer 0 */
108 unsigned long stripes; /* number of stripes required (determ. by l0) */
109 unsigned char **lhp[2]; /* pointers to lower/higher resolution images */
110 int *highres; /* index [plane] of highres image in lhp[] */
111 int order; /* SDE ordering parameters */
112 int options; /* encoding parameters */
113 unsigned mx, my; /* maximum ATMOVE window size */
114 int *tx; /* array [plane] with x-offset of adaptive template pixel */
115 char *dppriv; /* optional private deterministic prediction table */
116 char *res_tab; /* table for the resolution reduction algorithm */
117 struct jbg_buf ****sde; /* array [stripe][layer][plane] pointers to *
118 * buffers for stored SDEs */
119 struct jbg_arenc_state *s; /* array [planes] for arithm. encoder status */
120 struct jbg_buf *free_list; /* list of currently unused SDE block buffers */
121 void (*data_out)(unsigned char *start, size_t len, void *file);
122 /* data write callback */
123 void *file; /* parameter passed to data_out() */
124 char *tp; /* buffer for temp. values used by diff. typical prediction */
125 unsigned char *comment; /* content of comment marker segment to be added
126 at next opportunity (will be reset to NULL
127 as soon as comment has been written) */
128 unsigned long comment_len; /* length of data pointed to by comment */
129 };
130
131
132 /*
133 * Status of a JBIG decoder
134 */
135
136 struct jbg_dec_state {
137 /* data from BIH */
138 int d; /* resolution layer of the full image */
139 int dl; /* first resolution layer in this BIE */
140 unsigned long xd, yd; /* size of the full image (resolution layer d) */
141 int planes; /* number of different bitmap planes */
142 unsigned long l0; /* number of lines per stripe at lowest *
143 * resolution layer 0 */
144 unsigned long stripes; /* number of stripes required (determ. by l0) */
145 int order; /* SDE ordering parameters */
146 int options; /* encoding parameters */
147 int mx, my; /* maximum ATMOVE window size */
148 char *dppriv; /* optional private deterministic prediction table */
149
150 /* loop variables */
151 unsigned long ii[3]; /* current stripe, layer, plane (outer loop first) */
152
153 /*
154 * Pointers to array [planes] of lower/higher resolution images.
155 * lhp[d & 1] contains image of layer d.
156 */
157 unsigned char **lhp[2];
158
159 /* status information */
160 int **tx, **ty; /* array [plane][layer-dl] with x,y-offset of AT pixel */
161 struct jbg_ardec_state **s; /* array [plane][layer-dl] for arithmetic *
162 * decoder status */
163 int **reset; /* array [plane][layer-dl] remembers if previous stripe *
164 * in that plane/resolution ended with SDRST. */
165 unsigned long bie_len; /* number of bytes read so far */
166 unsigned char buffer[20]; /* used to store BIH or marker segments fragm. */
167 int buf_len; /* number of bytes in buffer */
168 unsigned long comment_skip; /* remaining bytes of a COMMENT segment */
169 unsigned long x; /* x position of next pixel in current SDE */
170 unsigned long i; /* line in current SDE (first line of each stripe is 0) */
171 int at_moves; /* number of AT moves in the current stripe */
172 unsigned long at_line[JBG_ATMOVES_MAX]; /* lines at which an *
173 * AT move will happen */
174 int at_tx[JBG_ATMOVES_MAX], at_ty[JBG_ATMOVES_MAX]; /* ATMOVE offsets in *
175 * current stripe */
176 unsigned long line_h1, line_h2, line_h3; /* variables of decode_pscd */
177 unsigned long line_l1, line_l2, line_l3;
178 int pseudo; /* flag for TPBON/TPDON: next pixel is pseudo pixel */
179 int **lntp; /* flag [plane][layer-dl] for TP: line is not typical */
180
181 unsigned long xmax, ymax; /* if possible abort before image gets *
182 * larger than this size */
183 int dmax; /* abort after this layer */
184 };
185
186
187 /* some macros (too trivial for a function) */
188
189 #define jbg_dec_getplanes(s) ((s)->planes)
190
191
192 /* function prototypes */
193
194 void jbg_enc_init(struct jbg_enc_state *s, unsigned long x, unsigned long y,
195 int planes, unsigned char **p,
196 void (*data_out)(unsigned char *start, size_t len,
197 void *file),
198 void *file);
199 int jbg_enc_lrlmax(struct jbg_enc_state *s, unsigned long mwidth,
200 unsigned long mheight);
201 void jbg_enc_layers(struct jbg_enc_state *s, int d);
202 int jbg_enc_lrange(struct jbg_enc_state *s, int dl, int dh);
203 void jbg_enc_options(struct jbg_enc_state *s, int order, int options,
204 unsigned long l0, int mx, int my);
205 void jbg_enc_out(struct jbg_enc_state *s);
206 void jbg_enc_free(struct jbg_enc_state *s);
207
208 void jbg_dec_init(struct jbg_dec_state *s);
209 void jbg_dec_maxsize(struct jbg_dec_state *s, unsigned long xmax,
210 unsigned long ymax);
211 int jbg_dec_in(struct jbg_dec_state *s, unsigned char *data, size_t len,
212 size_t *cnt);
213 unsigned long jbg_dec_getwidth(const struct jbg_dec_state *s);
214 unsigned long jbg_dec_getheight(const struct jbg_dec_state *s);
215 unsigned char *jbg_dec_getimage(const struct jbg_dec_state *s, int plane);
216 unsigned long jbg_dec_getsize(const struct jbg_dec_state *s);
217 void jbg_dec_merge_planes(const struct jbg_dec_state *s, int use_graycode,
218 void (*data_out)(unsigned char *start, size_t len,
219 void *file), void *file);
220 unsigned long jbg_dec_getsize_merged(const struct jbg_dec_state *s);
221 void jbg_dec_free(struct jbg_dec_state *s);
222
223 const char *jbg_strerror(int errnum);
224 void jbg_int2dppriv(unsigned char *dptable, const char *internal);
225 void jbg_dppriv2int(char *internal, const unsigned char *dptable);
226 unsigned long jbg_ceil_half(unsigned long x, int n);
227 void jbg_split_planes(unsigned long x, unsigned long y, int has_planes,
228 int encode_planes,
229 const unsigned char *src, unsigned char **dest,
230 int use_graycode);
231 int jbg_newlen(unsigned char *bie, size_t len);
232
233 #endif /* JBG_H */