Updated version number to 1.5.6
[deark.git] / src / deark-fmtutil.h
blobf4eab2e70eedb68721ab78049d923c75cd85b3ef
1 // This file is part of Deark.
2 // Copyright (C) 2016 Jason Summers
3 // See the file COPYING for terms of use.
5 struct de_dfilter_in_params {
6 dbuf *f;
7 i64 pos;
8 i64 len;
9 };
11 struct de_dfilter_out_params {
12 dbuf *f;
13 u8 len_known;
14 i64 expected_len;
17 struct de_dfilter_results {
18 int errcode;
19 u8 bytes_consumed_valid;
20 i64 bytes_consumed;
21 char errmsg[80];
24 struct de_bmpinfo {
25 #define DE_BMPINFO_FMT_BMP 0
26 #define DE_BMPINFO_FMT_PNG 1
27 int file_format;
29 int hotspot_x, hotspot_y;
30 i64 bitsoffset; // Literal value from FILEHEADER
31 i64 infohdrsize;
32 i64 width;
33 i64 height;
34 i64 bitcount;
35 u32 compression_field;
36 i64 sizeImage_field;
38 i64 bytes_per_pal_entry;
39 i64 pal_entries;
40 i64 num_colors; // For use in ICO/CUR file headers.
41 i64 rowspan;
43 i64 foreground_size;
44 i64 mask_rowspan;
45 i64 mask_size;
47 i64 pal_bytes; // Size of palette in bytes
48 i64 size_of_headers_and_pal; // Relative offset to bitmap (bitsoffset might be absolute)
49 i64 total_size;
51 int is_compressed;
52 int is_topdown;
55 #define DE_BMPINFO_HAS_FILEHEADER 0x1
56 #define DE_BMPINFO_ICO_FORMAT 0x2
57 #define DE_BMPINFO_HAS_HOTSPOT 0x4
58 #define DE_BMPINFO_CMPR_IS_4CC 0x8
60 void fmtutil_get_bmp_compression_name(u32 code, char *s, size_t s_len,
61 int is_os2v2);
62 int fmtutil_get_bmpinfo(deark *c, dbuf *f, struct de_bmpinfo *bi, i64 pos,
63 i64 len, unsigned int flags);
64 void fmtutil_generate_bmpfileheader(deark *c, dbuf *outf, const struct de_bmpinfo *bi,
65 i64 file_size_override);
67 void fmtutil_handle_exif2(deark *c, i64 pos, i64 len,
68 u32 *returned_flags, u32 *orientation, u32 *exifversion);
69 void fmtutil_handle_exif(deark *c, i64 pos, i64 len);
71 void fmtutil_handle_iptc(deark *c, dbuf *f, i64 pos, i64 len,
72 unsigned int flags);
74 void fmtutil_handle_photoshop_rsrc2(deark *c, dbuf *f, i64 pos, i64 len,
75 unsigned int flags, struct de_module_out_params *oparams);
76 void fmtutil_handle_photoshop_rsrc(deark *c, dbuf *f, i64 pos, i64 len,
77 unsigned int flags);
79 void fmtutil_handle_plist(deark *c, dbuf *f, i64 pos, i64 len,
80 de_finfo *fi, unsigned int flags);
82 // Definition of a "simple" (non-pushable) codec
83 typedef void (*de_codectype1_type)(deark *c, struct de_dfilter_in_params *dcmpri,
84 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres,
85 void *codec_private_params);
87 void fmtutil_decompress_uncompressed(deark *c, struct de_dfilter_in_params *dcmpri,
88 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres, UI flags);
90 #define DE_DEFLATEFLAG_ISZLIB 0x1
91 #define DE_DEFLATEFLAG_USEMAXUNCMPRSIZE 0x2
92 struct de_inflate_params {
93 unsigned int flags;
94 const u8 *starting_dict;
96 int fmtutil_decompress_deflate(dbuf *inf, i64 inputstart, i64 inputsize, dbuf *outf,
97 i64 maxuncmprsize, i64 *bytes_consumed, unsigned int flags);
98 void fmtutil_decompress_deflate_ex(deark *c, struct de_dfilter_in_params *dcmpri,
99 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres,
100 unsigned int flags);
101 void fmtutil_inflate_codectype1(deark *c, struct de_dfilter_in_params *dcmpri,
102 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres,
103 void *codec_private_params);
105 void fmtutil_decompress_packbits_ex(deark *c, struct de_dfilter_in_params *dcmpri,
106 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres);
107 int fmtutil_decompress_packbits(dbuf *f, i64 pos1, i64 len,
108 dbuf *unc_pixels, i64 *cmpr_bytes_consumed);
109 void fmtutil_decompress_packbits16_ex(deark *c, struct de_dfilter_in_params *dcmpri,
110 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres);
111 int fmtutil_decompress_packbits16(dbuf *f, i64 pos1, i64 len,
112 dbuf *unc_pixels, i64 *cmpr_bytes_consumed);
113 void fmtutil_decompress_rle90_ex(deark *c, struct de_dfilter_in_params *dcmpri,
114 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres,
115 unsigned int flags);
116 void fmtutil_decompress_szdd(deark *c, struct de_dfilter_in_params *dcmpri,
117 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres,
118 unsigned int flags);
119 void fmtutil_hlp_lz77_codectype1(deark *c, struct de_dfilter_in_params *dcmpri,
120 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres,
121 void *codec_private_params);
122 void fmtutil_huff_squeeze_codectype1(deark *c, struct de_dfilter_in_params *dcmpri,
123 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres,
124 void *codec_private_params);
126 struct de_dfilter_ctx;
127 typedef void (*dfilter_codec_type)(struct de_dfilter_ctx *dfctx, void *codec_private_params);
128 typedef void (*dfilter_codec_addbuf_type)(struct de_dfilter_ctx *dfctx,
129 const u8 *buf, i64 buf_len);
130 typedef void (*dfilter_codec_finish_type)(struct de_dfilter_ctx *dfctx);
131 typedef void (*dfilter_codec_destroy_type)(struct de_dfilter_ctx *dfctx);
133 struct de_dfilter_ctx {
134 deark *c;
135 struct de_dfilter_results *dres;
136 struct de_dfilter_out_params *dcmpro;
137 u8 finished_flag;
138 void *codec_private;
139 dfilter_codec_addbuf_type codec_addbuf_fn;
140 dfilter_codec_finish_type codec_finish_fn;
141 dfilter_codec_destroy_type codec_destroy_fn;
144 enum de_lzwfmt_enum {
145 DE_LZWFMT_GENERIC = 0,
146 DE_LZWFMT_UNIXCOMPRESS,
147 DE_LZWFMT_GIF,
148 DE_LZWFMT_ZIPSHRINK,
149 DE_LZWFMT_ZOOLZD
152 struct de_lzw_params {
153 enum de_lzwfmt_enum fmt;
154 #define DE_LZWFLAG_HAS3BYTEHEADER 0x1 // Unix-compress style, use with fmt=UNIXCOMPRESS
155 #define DE_LZWFLAG_HAS1BYTEHEADER 0x2 // ARC style, use with fmt=UNIXCOMPRESS
156 #define DE_LZWFLAG_TOLERATETRAILINGJUNK 0x4
157 UI flags;
158 unsigned int gif_root_code_size;
159 unsigned int max_code_size; // 0 = no info
161 void fmtutil_decompress_lzw(deark *c, struct de_dfilter_in_params *dcmpri,
162 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres,
163 struct de_lzw_params *lzwp);
165 void dfilter_lzw_codec(struct de_dfilter_ctx *dfctx, void *codec_private_params);
166 void dfilter_rle90_codec(struct de_dfilter_ctx *dfctx, void *codec_private_params);
168 struct de_lzh_params {
169 #define DE_LZH_FMT_LH5LIKE 1 // subfmt=='5' (etc.)
170 int fmt;
171 int subfmt;
172 // How to handle a block with "0" codes:
173 // 0 = treat as 65536, with warning
174 // 1 = stop, no warning
175 u8 zero_codes_block_behavior;
176 u8 use_history_fill_val;
177 u8 history_fill_val;
179 void fmtutil_decompress_lzh(deark *c, struct de_dfilter_in_params *dcmpri,
180 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres,
181 struct de_lzh_params *lzhp);
182 void fmtutil_lzh_codectype1(deark *c, struct de_dfilter_in_params *dcmpri,
183 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres,
184 void *codec_private_params);
186 struct de_dfilter_ctx *de_dfilter_create(deark *c,
187 dfilter_codec_type codec_init_fn, void *codec_private_params,
188 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres);
189 void de_dfilter_addbuf(struct de_dfilter_ctx *dfctx,
190 const u8 *buf, i64 buf_len);
191 void de_dfilter_finish(struct de_dfilter_ctx *dfctx);
192 void de_dfilter_destroy(struct de_dfilter_ctx *dfctx);
194 void de_dfilter_decompress_oneshot(deark *c,
195 dfilter_codec_type codec_init_fn, void *codec_private_params,
196 struct de_dfilter_in_params *dcmpri, struct de_dfilter_out_params *dcmpro,
197 struct de_dfilter_results *dres);
198 struct de_dcmpr_two_layer_params {
199 de_codectype1_type codec1_type1; // Set either this or codec1_pushable
200 dfilter_codec_type codec1_pushable;
201 void *codec1_private_params;
202 dfilter_codec_type codec2;
203 void *codec2_private_params;
204 struct de_dfilter_in_params *dcmpri;
205 struct de_dfilter_out_params *dcmpro;
206 struct de_dfilter_results *dres;
207 u8 intermed_len_known;
208 i64 intermed_expected_len;
210 void de_dfilter_decompress_two_layer(deark *c, struct de_dcmpr_two_layer_params *tlp);
211 void de_dfilter_decompress_two_layer_type2(deark *c,
212 dfilter_codec_type codec1, void *codec1_private_params,
213 dfilter_codec_type codec2, void *codec2_private_params,
214 struct de_dfilter_in_params *dcmpri, struct de_dfilter_out_params *dcmpro,
215 struct de_dfilter_results *dres);
217 void fmtutil_decompress_zip_shrink(deark *c, struct de_dfilter_in_params *dcmpri,
218 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres,
219 unsigned int flags);
220 void fmtutil_decompress_zip_reduce(deark *c, struct de_dfilter_in_params *dcmpri,
221 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres,
222 unsigned int cmpr_factor, unsigned int flags);
223 void fmtutil_decompress_zip_implode(deark *c, struct de_dfilter_in_params *dcmpri,
224 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres,
225 unsigned int bit_flags, unsigned int flags);
227 // Wrapper for miniz' tdefl functions
229 enum fmtutil_tdefl_status {
230 FMTUTIL_TDEFL_STATUS_BAD_PARAM = -2,
231 FMTUTIL_TDEFL_STATUS_PUT_BUF_FAILED = -1,
232 FMTUTIL_TDEFL_STATUS_OKAY = 0,
233 FMTUTIL_TDEFL_STATUS_DONE = 1
236 enum fmtutil_tdefl_flush {
237 FMTUTIL_TDEFL_NO_FLUSH = 0,
238 FMTUTIL_TDEFL_SYNC_FLUSH = 2,
239 FMTUTIL_TDEFL_FULL_FLUSH = 3,
240 FMTUTIL_TDEFL_FINISH = 4
243 struct fmtutil_tdefl_ctx;
244 struct fmtutil_tdefl_ctx *fmtutil_tdefl_create(deark *c, dbuf *outf, int flags);
245 enum fmtutil_tdefl_status fmtutil_tdefl_compress_buffer(struct fmtutil_tdefl_ctx *tdctx,
246 const void *pIn_buf, size_t in_buf_size, enum fmtutil_tdefl_flush flush);
247 void fmtutil_tdefl_destroy(struct fmtutil_tdefl_ctx *tdctx);
248 unsigned int fmtutil_tdefl_create_comp_flags_from_zip_params(int level, int window_bits,
249 int strategy);
251 struct de_SAUCE_info {
252 int is_valid;
253 de_ucstring *title;
254 de_ucstring *artist;
255 de_ucstring *organization;
256 struct de_timestamp creation_date;
257 i64 original_file_size;
258 u8 data_type;
259 u8 file_type;
260 u8 tflags;
261 i64 width_in_chars; // 0 if unknown
262 i64 number_of_lines; // Reported value. May be incorrect.
263 i64 comment_block_pos; // Valid if num_comments>0.
264 u16 tinfo1, tinfo2, tinfo3, tinfo4;
265 de_ucstring *comment; // NULL if there is no comment
268 int fmtutil_detect_SAUCE(deark *c, dbuf *f, struct de_SAUCE_detection_data *sdd,
269 unsigned int flags);
270 void fmtutil_handle_SAUCE(deark *c, dbuf *f, struct de_SAUCE_info *si);
271 struct de_SAUCE_info *fmtutil_create_SAUCE(deark *c);
272 void fmtutil_free_SAUCE(deark *c, struct de_SAUCE_info *si);
274 struct de_boxesctx;
276 // Return 0 to stop reading
277 typedef int (*de_handle_box_fn)(deark *c, struct de_boxesctx *bctx);
278 typedef void (*de_identify_box_fn)(deark *c, struct de_boxesctx *bctx);
280 struct de_boxdata {
281 // Per-box info supplied to handle_box_fn:
282 struct de_boxdata *parent;
283 int level;
284 u32 boxtype;
285 int is_uuid;
286 u8 uuid[16]; // Valid only if is_uuid is set.
287 i64 box_pos;
288 i64 box_len;
289 // Note: for UUID boxes, payload does not include the UUID
290 i64 payload_pos;
291 i64 payload_len;
293 // To be filled in by identify_box_fn:
294 void *box_userdata;
295 const char *box_name;
297 // To be filled in by handle_box_fn:
298 int handled;
299 int is_superbox;
300 int num_children_is_known;
301 i64 num_children; // valid if (is_superbox) && (num_children_is_known)
302 i64 extra_bytes_before_children; // valid if (is_superbox)
305 struct de_boxesctx {
306 void *userdata;
307 dbuf *f; // Input file
308 de_identify_box_fn identify_box_fn;
309 de_handle_box_fn handle_box_fn;
311 struct de_boxdata *curbox;
314 double dbuf_fmtutil_read_fixed_16_16(dbuf *f, i64 pos);
315 int fmtutil_default_box_handler(deark *c, struct de_boxesctx *bctx);
316 void fmtutil_read_boxes_format(deark *c, struct de_boxesctx *bctx);
317 void fmtutil_render_uuid(deark *c, const u8 *uuid, char *s, size_t s_len);
318 void fmtutil_guid_to_uuid(u8 *id);
320 struct atari_img_decode_data {
321 i64 bpp;
322 i64 ncolors;
323 i64 w, h;
324 dbuf *unc_pixels;
325 int was_compressed;
326 int is_spectrum512;
327 de_color *pal;
328 de_bitmap *img;
331 #define DE_FLAG_ATARI_15BIT_PAL 0x2
332 void fmtutil_read_atari_palette(deark *c, dbuf *f, i64 pos,
333 de_color *dstpal, i64 ncolors_to_read, i64 ncolors_used, unsigned int flags);
335 int fmtutil_atari_decode_image(deark *c, struct atari_img_decode_data *adata);
336 void fmtutil_atari_set_standard_density(deark *c, struct atari_img_decode_data *adata,
337 de_finfo *fi);
338 void fmtutil_atari_help_palbits(deark *c);
340 // The IFF parser supports IFF and similar formats, including RIFF.
341 struct de_iffctx;
343 // An IFF chunk handler is expected to do one of the following:
344 // - Set ictx->is_std_container (ictx->handled is ignored).
345 // - Set ictx->is_raw_container (ictx->handled is ignored).
346 // - Handle the chunk, and set ictx->handled.
347 // - Do nothing, and set ictx->handled, to suppress default handling.
348 // - Do nothing, in which case standard IFF chunks (ANNO, at least) will
349 // handled by the IFF parser.
350 // Return value: Normally 1; 0 to immediately stop processing the entire file.
351 typedef int (*de_handle_iff_chunk_fn)(deark *c, struct de_iffctx *ictx);
353 // Mainly for identifying the chunk.
354 // The user can also adjust ictx->chunkctx->dlen.
355 // Return value: Normally 1 (reserved)
356 typedef int (*de_preprocess_iff_chunk_fn)(deark *c, struct de_iffctx *ictx);
358 // Return value: Normally 1; 0 to immediately stop processing the entire file.
359 typedef int (*de_on_iff_container_end_fn)(deark *c, struct de_iffctx *ictx);
361 // Return value: Normally 1; 0 to stop processing this container (the
362 // on_container_end_fn will not be called).
363 typedef int (*de_on_std_iff_container_start_fn)(deark *c, struct de_iffctx *ictx);
365 // Caller can check for nonstandard non-chunk data at 'pos'. If found, set *plen
366 // to its length, process it if desired, and return 1.
367 typedef int (*de_handle_nonchunk_iff_data_fn)(deark *c, struct de_iffctx *ictx,
368 i64 pos, i64 *plen);
370 struct de_iffchunkctx {
371 struct de_fourcc chunk4cc;
372 i64 pos;
373 i64 len;
374 i64 dpos;
375 i64 dlen;
377 // To be filled in by identify_chunk_fn:
378 void *chunk_userdata;
379 const char *chunk_name;
382 struct de_iffctx {
383 void *userdata;
384 dbuf *f; // Input file
385 de_handle_iff_chunk_fn handle_chunk_fn;
386 de_preprocess_iff_chunk_fn preprocess_chunk_fn;
387 de_on_std_iff_container_start_fn on_std_container_start_fn;
388 de_on_iff_container_end_fn on_container_end_fn;
389 de_handle_nonchunk_iff_data_fn handle_nonchunk_data_fn;
390 i64 alignment; // 0 = default
391 i64 sizeof_len; // 0 = default
392 int is_le; // For RIFF format
393 int reversed_4cc;
394 int input_encoding;
396 int level;
398 // Top-level container type:
399 struct de_fourcc main_fmt4cc; // E.g. "FORM"
400 struct de_fourcc main_contentstype4cc; // E.g. "ILBM"
402 // Current container type:
403 struct de_fourcc curr_container_fmt4cc;
404 struct de_fourcc curr_container_contentstype4cc;
406 // Per-chunk info supplied to handle_chunk_fn:
407 struct de_iffchunkctx *chunkctx;
409 // To be filled in by handle_chunk_fn:
410 int handled;
411 int is_std_container;
412 int is_raw_container;
415 void fmtutil_read_iff_format(deark *c, struct de_iffctx *ictx,
416 i64 pos, i64 len);
417 int fmtutil_is_standard_iff_chunk(deark *c, struct de_iffctx *ictx,
418 u32 ct);
419 void fmtutil_default_iff_chunk_identify(deark *c, struct de_iffctx *ictx);
421 const char *fmtutil_tiff_orientation_name(i64 n);
422 const char *fmtutil_get_windows_charset_name(u8 cs);
423 const char *fmtutil_get_windows_cb_data_type_name(unsigned int ty);
425 int fmtutil_find_zip_eocd(deark *c, dbuf *f, i64 *foundpos);
427 struct de_id3info {
428 int has_id3v1, has_id3v2;
429 i64 main_start, main_end;
431 void fmtutil_handle_id3(deark *c, dbuf *f, struct de_id3info *id3i,
432 unsigned int flags);
434 struct de_advfile;
436 struct de_advfile_cbparams {
437 #define DE_ADVFILE_WRITEMAIN 1
438 #define DE_ADVFILE_WRITERSRC 2
439 int whattodo;
440 dbuf *outf;
443 typedef int (*de_advfile_cbfn)(deark *c, struct de_advfile *advf,
444 struct de_advfile_cbparams *afp);
446 struct de_advfile_forkinfo {
447 u8 fork_exists;
448 i64 fork_len;
449 de_finfo *fi; // Note: do not set the name; use de_advfile.filename.
450 void *userdata_for_writelistener;
451 de_writelistener_cb_type writelistener_cb;
454 struct de_advfile {
455 deark *c;
456 void *userdata;
457 struct de_advfile_forkinfo mainfork;
458 struct de_advfile_forkinfo rsrcfork;
459 de_advfile_cbfn writefork_cbfn;
460 de_ucstring *filename;
461 unsigned int snflags; // flags for de_finfo_set_name*
462 unsigned int createflags;
463 u8 original_filename_flag;
464 u8 no_applesingle;
465 u8 no_appledouble;
466 u8 has_typecode;
467 u8 has_creatorcode;
468 u8 has_finderflags;
469 u16 finderflags;
470 size_t orig_filename_len;
471 u8 *orig_filename;
472 u8 typecode[4];
473 u8 creatorcode[4];
476 struct de_advfile *de_advfile_create(deark *c);
477 void de_advfile_destroy(struct de_advfile *advf);
478 void de_advfile_set_orig_filename(struct de_advfile *advf, const char *fn, size_t fnlen);
479 void de_advfile_run(struct de_advfile *advf);
481 void de_dfilter_set_errorf(deark *c, struct de_dfilter_results *dres, const char *modname,
482 const char *fmt, ...)
483 de_gnuc_attribute ((format (printf, 4, 5)));
484 void de_dfilter_set_generic_error(deark *c, struct de_dfilter_results *dres, const char *modname);
485 const char *de_dfilter_get_errmsg(deark *c, struct de_dfilter_results *dres);
486 void de_dfilter_results_clear(deark *c, struct de_dfilter_results *dres);
487 void de_dfilter_init_objects(deark *c, struct de_dfilter_in_params *dcmpri,
488 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres);
490 struct de_riscos_file_attrs {
491 u8 file_type_known;
492 u32 load_addr, exec_addr;
493 u32 attribs;
494 unsigned int file_type;
495 unsigned int lzwmaxbits;
496 u32 crc_from_attribs;
497 struct de_timestamp mod_time;
500 void fmtutil_riscos_read_load_exec(deark *c, dbuf *f, struct de_riscos_file_attrs *rfa, i64 pos1);
501 #define DE_RISCOS_FLAG_HAS_CRC 0x1
502 #define DE_RISCOS_FLAG_HAS_LZWMAXBITS 0x2
503 void fmtutil_riscos_read_attribs_field(deark *c, dbuf *f, struct de_riscos_file_attrs *rfa,
504 i64 pos, unsigned int flags);
506 struct fmtutil_macbitmap_info {
507 i64 rowbytes; // The rowBytes field
508 i64 rowspan; // Actual number of bytes/row
509 i64 width, height;
510 int is_uncompressed;
511 i64 packing_type;
512 i64 pixeltype, pixelsize;
513 i64 cmpcount, cmpsize;
514 double hdpi, vdpi;
515 u32 pmTable;
516 int pixmap_flag;
517 int has_colortable; // Does the file contain a colortable for this bitmap?
518 int uses_pal; // Are we using the palette below?
519 i64 num_pal_entries;
520 de_color pal[256];
523 void fmtutil_macbitmap_read_baseaddr(deark *c, dbuf *f,
524 struct fmtutil_macbitmap_info *bi, i64 pos);
525 void fmtutil_macbitmap_read_rowbytes_and_bounds(deark *c, dbuf *f,
526 struct fmtutil_macbitmap_info *bi, i64 pos);
527 void fmtutil_macbitmap_read_pixmap_only_fields(deark *c, dbuf *f,
528 struct fmtutil_macbitmap_info *bi, i64 pos);
529 int fmtutil_macbitmap_read_colortable(deark *c, dbuf *f,
530 struct fmtutil_macbitmap_info *bi, i64 pos, i64 *bytes_used);
532 i64 fmtutil_hlp_get_cus_p(dbuf *f, i64 *ppos);
533 i64 fmtutil_hlp_get_css_p(dbuf *f, i64 *ppos);
534 i64 fmtutil_hlp_get_cul_p(dbuf *f, i64 *ppos);
535 i64 fmtutil_hlp_get_csl_p(dbuf *f, i64 *ppos);
537 typedef i32 fmtutil_huffman_valtype;
538 struct fmtutil_huffman_tree;
539 struct fmtutil_huffman_tree *fmtutil_huffman_create_tree(deark *c, i64 initial_codes, i64 max_codes);
540 void fmtutil_huffman_destroy_tree(deark *c, struct fmtutil_huffman_tree *ht);
541 void fmtutil_huffman_reset_cursor(struct fmtutil_huffman_tree *ht);
542 int fmtutil_huffman_add_code(deark *c, struct fmtutil_huffman_tree *ht,
543 u64 code, UI code_nbits, fmtutil_huffman_valtype val);
544 int fmtutil_huffman_decode_bit(struct fmtutil_huffman_tree *ht, u8 bitval, fmtutil_huffman_valtype *pval);
545 int fmtutil_huffman_read_next_value(struct fmtutil_huffman_tree *ht,
546 struct de_bitreader *bitrd, fmtutil_huffman_valtype *pval, UI *pnbits);
547 UI fmtutil_huffman_get_max_bits(struct fmtutil_huffman_tree *ht);
548 i64 fmtutil_huffman_get_num_codes(struct fmtutil_huffman_tree *ht);
549 void fmtutil_huffman_dump(deark *c, struct fmtutil_huffman_tree *ht);
550 int fmtutil_huffman_record_a_code_length(deark *c, struct fmtutil_huffman_tree *ht,
551 fmtutil_huffman_valtype val, UI len);
552 int fmtutil_huffman_make_canonical_tree(deark *c, struct fmtutil_huffman_tree *ht);
554 struct de_lz77buffer;
555 typedef void (*fmtutil_lz77buffer_cb_type)(struct de_lz77buffer *rb, u8 n);
557 struct de_lz77buffer {
558 void *userdata;
559 fmtutil_lz77buffer_cb_type writebyte_cb;
560 UI curpos; // Must be kept valid at all times (0...bufsize-1)
561 UI mask;
562 UI bufsize; // Required to be a power of 2
563 u8 *buf;
565 struct de_lz77buffer *de_lz77buffer_create(deark *c, UI bufsize);
566 void de_lz77buffer_destroy(deark *c, struct de_lz77buffer *rb);
567 void de_lz77buffer_clear(struct de_lz77buffer *rb, UI val);
568 void de_lz77buffer_set_curpos(struct de_lz77buffer *rb, UI newpos);
569 void de_lz77buffer_add_literal_byte(struct de_lz77buffer *rb, u8 b);
570 void de_lz77buffer_copy_from_hist(struct de_lz77buffer *rb, UI startpos, UI count);