Minor refactoring, related to lzah
[deark.git] / src / deark-fmtutil.h
blobcc28c0cd968ca0f3ecfd4087f3b7ae0114af36d5
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_lz77buffer;
7 struct de_dfilter_in_params {
8 dbuf *f;
9 i64 pos;
10 i64 len;
13 struct de_dfilter_out_params {
14 dbuf *f;
15 u8 len_known;
16 i64 expected_len;
19 struct de_dfilter_results {
20 // Note: If this struct is changed, also update de_dfilter_results_clear().
21 int errcode;
22 u8 bytes_consumed_valid;
23 i64 bytes_consumed;
24 char errmsg[80];
27 struct de_bmpinfo {
28 #define DE_BMPINFO_FMT_BMP 0
29 #define DE_BMPINFO_FMT_PNG 1
30 int file_format;
32 int hotspot_x, hotspot_y;
33 i64 bitsoffset; // Literal value from FILEHEADER
34 i64 infohdrsize;
35 i64 width;
36 i64 height;
37 i64 bitcount;
38 u32 compression_field;
39 i64 sizeImage_field;
41 i64 bytes_per_pal_entry;
42 i64 pal_entries;
43 i64 num_colors; // For use in ICO/CUR file headers.
44 i64 rowspan;
46 i64 foreground_size;
47 i64 mask_rowspan;
48 i64 mask_size;
50 i64 pal_bytes; // Size of palette in bytes
51 i64 size_of_headers_and_pal; // Relative offset to bitmap (bitsoffset might be absolute)
52 i64 total_size;
54 int is_compressed;
55 int is_topdown;
58 #define DE_BMPINFO_HAS_FILEHEADER 0x1
59 #define DE_BMPINFO_ICO_FORMAT 0x2
60 #define DE_BMPINFO_HAS_HOTSPOT 0x4
61 #define DE_BMPINFO_CMPR_IS_4CC 0x8
63 void fmtutil_get_bmp_compression_name(u32 code, char *s, size_t s_len,
64 int is_os2v2);
65 int fmtutil_get_bmpinfo(deark *c, dbuf *f, struct de_bmpinfo *bi, i64 pos,
66 i64 len, unsigned int flags);
67 void fmtutil_generate_bmpfileheader(deark *c, dbuf *outf, const struct de_bmpinfo *bi,
68 i64 file_size_override);
70 void fmtutil_handle_exif2(deark *c, i64 pos, i64 len,
71 u32 *returned_flags, u32 *orientation, u32 *exifversion);
72 void fmtutil_handle_exif(deark *c, i64 pos, i64 len);
74 void fmtutil_handle_iptc(deark *c, dbuf *f, i64 pos, i64 len,
75 unsigned int flags);
77 void fmtutil_handle_photoshop_rsrc2(deark *c, dbuf *f, i64 pos, i64 len,
78 unsigned int flags, struct de_module_out_params *oparams);
79 void fmtutil_handle_photoshop_rsrc(deark *c, dbuf *f, i64 pos, i64 len,
80 unsigned int flags);
82 void fmtutil_handle_plist(deark *c, dbuf *f, i64 pos, i64 len,
83 de_finfo *fi, unsigned int flags);
85 // Definition of a "simple" (non-pushable) codec
86 typedef void (*de_codectype1_type)(deark *c, struct de_dfilter_in_params *dcmpri,
87 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres,
88 void *codec_private_params);
90 void fmtutil_decompress_uncompressed(deark *c, struct de_dfilter_in_params *dcmpri,
91 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres, UI flags);
93 #define DE_DEFLATEFLAG_ISZLIB 0x1
94 #define DE_DEFLATEFLAG_USEMAXUNCMPRSIZE 0x2 // only used with fmtutil_decompress_deflate()
95 #define DE_DEFLATEFLAG_DEFLATE64 0x4
96 struct de_deflate_params {
97 unsigned int flags;
98 struct de_lz77buffer *ringbuf_to_use; // (Uses the data only, not the callback)
100 int fmtutil_decompress_deflate(dbuf *inf, i64 inputstart, i64 inputsize, dbuf *outf,
101 i64 maxuncmprsize, i64 *bytes_consumed, unsigned int flags);
102 void fmtutil_decompress_deflate_ex(deark *c, struct de_dfilter_in_params *dcmpri,
103 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres,
104 struct de_deflate_params *params);
105 void fmtutil_deflate_codectype1_miniz(deark *c, struct de_dfilter_in_params *dcmpri,
106 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres,
107 void *codec_private_params);
108 void fmtutil_deflate_codectype1(deark *c, struct de_dfilter_in_params *dcmpri,
109 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres,
110 void *codec_private_params);
112 struct de_packbits_params {
113 u8 is_packbits16;
115 void fmtutil_decompress_packbits_ex(deark *c, struct de_dfilter_in_params *dcmpri,
116 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres,
117 struct de_packbits_params *pbparams);
118 int fmtutil_decompress_packbits(dbuf *f, i64 pos1, i64 len,
119 dbuf *unc_pixels, i64 *cmpr_bytes_consumed);
120 void fmtutil_decompress_rle90_ex(deark *c, struct de_dfilter_in_params *dcmpri,
121 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres,
122 unsigned int flags);
123 void fmtutil_decompress_szdd(deark *c, struct de_dfilter_in_params *dcmpri,
124 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres,
125 unsigned int flags);
126 void fmtutil_hlp_lz77_codectype1(deark *c, struct de_dfilter_in_params *dcmpri,
127 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres,
128 void *codec_private_params);
129 void fmtutil_huff_squeeze_codectype1(deark *c, struct de_dfilter_in_params *dcmpri,
130 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres,
131 void *codec_private_params);
133 struct de_dfilter_ctx;
134 typedef void (*dfilter_codec_type)(struct de_dfilter_ctx *dfctx, void *codec_private_params);
135 typedef void (*dfilter_codec_addbuf_type)(struct de_dfilter_ctx *dfctx,
136 const u8 *buf, i64 buf_len);
137 typedef void (*dfilter_codec_command_type)(struct de_dfilter_ctx *dfctx, int cmd);
138 typedef void (*dfilter_codec_finish_type)(struct de_dfilter_ctx *dfctx);
139 typedef void (*dfilter_codec_destroy_type)(struct de_dfilter_ctx *dfctx);
141 struct de_dfilter_ctx {
142 deark *c;
143 struct de_dfilter_results *dres;
144 struct de_dfilter_out_params *dcmpro;
145 u8 finished_flag;
146 void *codec_private;
147 dfilter_codec_addbuf_type codec_addbuf_fn;
148 dfilter_codec_command_type codec_command_fn;
149 dfilter_codec_finish_type codec_finish_fn;
150 dfilter_codec_destroy_type codec_destroy_fn;
153 enum de_lzwfmt_enum {
154 DE_LZWFMT_GENERIC = 0,
155 DE_LZWFMT_UNIXCOMPRESS,
156 DE_LZWFMT_GIF,
157 DE_LZWFMT_ZIPSHRINK,
158 DE_LZWFMT_ZOOLZD,
159 DE_LZWFMT_TIFF,
160 DE_LZWFMT_ARC5
163 struct de_lzw_params {
164 enum de_lzwfmt_enum fmt;
165 #define DE_LZWFLAG_HAS3BYTEHEADER 0x1 // Unix-compress style, use with fmt=UNIXCOMPRESS
166 #define DE_LZWFLAG_HAS1BYTEHEADER 0x2 // ARC style, use with fmt=UNIXCOMPRESS
167 #define DE_LZWFLAG_TOLERATETRAILINGJUNK 0x4
168 UI flags;
169 unsigned int gif_root_code_size;
170 unsigned int max_code_size; // 0 = no info
171 u8 tifflzw_oldversion; // 1 = old version
172 u8 arc5_has_stop_code;
174 void fmtutil_decompress_lzw(deark *c, struct de_dfilter_in_params *dcmpri,
175 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres,
176 struct de_lzw_params *lzwp);
178 void dfilter_lzw_codec(struct de_dfilter_ctx *dfctx, void *codec_private_params);
179 void dfilter_rle90_codec(struct de_dfilter_ctx *dfctx, void *codec_private_params);
180 void dfilter_packbits_codec(struct de_dfilter_ctx *dfctx, void *codec_private_params);
182 struct de_lh5x_params {
183 #define DE_LH5X_FMT_LH5 5
184 #define DE_LH5X_FMT_LH6 6
185 #define DE_LH5X_FMT_LH7 7
186 #define DE_LH5X_FMT_LHARK 100
187 int fmt;
189 // How to handle a block with "0" codes:
190 #define DE_LH5X_ZCB_ERROR 0
191 #define DE_LH5X_ZCB_STOP 1
192 #define DE_LH5X_ZCB_0 2
193 #define DE_LH5X_ZCB_65536 3
194 u8 zero_codes_block_behavior;
195 u8 warn_about_zero_codes_block;
197 u8 history_fill_val; // Set to 0x20 (space) if not sure.
199 void fmtutil_decompress_lh5x(deark *c, struct de_dfilter_in_params *dcmpri,
200 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres,
201 struct de_lh5x_params *lzhp);
202 void fmtutil_lh5x_codectype1(deark *c, struct de_dfilter_in_params *dcmpri,
203 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres,
204 void *codec_private_params);
206 struct de_fax34_params {
207 i64 image_width;
208 i64 image_height;
209 i64 out_rowspan;
210 UI tiff_cmpr_meth;
211 u8 is_lsb;
212 u32 t4options;
213 u32 t6options;
215 void fmtutil_fax34_codectype1(deark *c, struct de_dfilter_in_params *dcmpri,
216 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres,
217 void *codec_private_params);
219 struct de_dfilter_ctx *de_dfilter_create(deark *c,
220 dfilter_codec_type codec_init_fn, void *codec_private_params,
221 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres);
222 void de_dfilter_addbuf(struct de_dfilter_ctx *dfctx,
223 const u8 *buf, i64 buf_len);
224 #define DE_DFILTER_COMMAND_SOFTRESET 1
225 #define DE_DFILTER_COMMAND_REINITIALIZE 2
226 void de_dfilter_command(struct de_dfilter_ctx *dfctx, int cmd, UI flags);
227 void de_dfilter_addslice(struct de_dfilter_ctx *dfctx,
228 dbuf *inf, i64 pos, i64 len);
229 void de_dfilter_finish(struct de_dfilter_ctx *dfctx);
230 void de_dfilter_destroy(struct de_dfilter_ctx *dfctx);
232 void de_dfilter_decompress_oneshot(deark *c,
233 dfilter_codec_type codec_init_fn, void *codec_private_params,
234 struct de_dfilter_in_params *dcmpri, struct de_dfilter_out_params *dcmpro,
235 struct de_dfilter_results *dres);
236 struct de_dcmpr_two_layer_params {
237 de_codectype1_type codec1_type1; // Set either this or codec1_pushable
238 dfilter_codec_type codec1_pushable;
239 void *codec1_private_params;
240 dfilter_codec_type codec2;
241 void *codec2_private_params;
242 struct de_dfilter_in_params *dcmpri;
243 struct de_dfilter_out_params *dcmpro;
244 struct de_dfilter_results *dres;
245 u8 intermed_len_known;
246 i64 intermed_expected_len;
248 void de_dfilter_decompress_two_layer(deark *c, struct de_dcmpr_two_layer_params *tlp);
250 void fmtutil_decompress_zip_shrink(deark *c, struct de_dfilter_in_params *dcmpri,
251 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres,
252 void *params);
254 struct de_zipreduce_params {
255 unsigned int cmpr_factor;
257 void fmtutil_decompress_zip_reduce(deark *c, struct de_dfilter_in_params *dcmpri,
258 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres,
259 struct de_zipreduce_params *params);
261 struct de_zipimplode_params {
262 unsigned int bit_flags;
263 u8 mml_bug;
265 void fmtutil_decompress_zip_implode(deark *c, struct de_dfilter_in_params *dcmpri,
266 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres,
267 struct de_zipimplode_params *params);
269 void fmtutil_dclimplode_codectype1(deark *c, struct de_dfilter_in_params *dcmpri,
270 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres,
271 void *codec_private_params);
273 void fmtutil_get_lzhuf_d_code_and_len(UI n, UI *pd_code, UI *pd_len);
275 struct de_lh1_params {
276 u8 is_crlzh11, is_crlzh20;
277 u8 is_arc_trimmed; // (The LZH part of the scheme. Does not do RLE.)
278 u8 history_fill_val; // Set to 0x20 (space) if not sure.
281 void fmtutil_lh1_codectype1(deark *c, struct de_dfilter_in_params *dcmpri,
282 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres,
283 void *codec_private_params);
285 // Wrapper for miniz' tdefl functions
287 enum fmtutil_tdefl_status {
288 FMTUTIL_TDEFL_STATUS_BAD_PARAM = -2,
289 FMTUTIL_TDEFL_STATUS_PUT_BUF_FAILED = -1,
290 FMTUTIL_TDEFL_STATUS_OKAY = 0,
291 FMTUTIL_TDEFL_STATUS_DONE = 1
294 enum fmtutil_tdefl_flush {
295 FMTUTIL_TDEFL_NO_FLUSH = 0,
296 FMTUTIL_TDEFL_SYNC_FLUSH = 2,
297 FMTUTIL_TDEFL_FULL_FLUSH = 3,
298 FMTUTIL_TDEFL_FINISH = 4
301 struct fmtutil_tdefl_ctx;
302 struct fmtutil_tdefl_ctx *fmtutil_tdefl_create(deark *c, dbuf *outf, int flags);
303 enum fmtutil_tdefl_status fmtutil_tdefl_compress_buffer(struct fmtutil_tdefl_ctx *tdctx,
304 const void *pIn_buf, size_t in_buf_size, enum fmtutil_tdefl_flush flush);
305 void fmtutil_tdefl_destroy(struct fmtutil_tdefl_ctx *tdctx);
306 unsigned int fmtutil_tdefl_create_comp_flags_from_zip_params(int level, int window_bits,
307 int strategy);
309 struct de_SAUCE_info {
310 int is_valid;
311 de_ucstring *title;
312 de_ucstring *artist;
313 de_ucstring *organization;
314 struct de_timestamp creation_date;
315 i64 original_file_size;
316 u8 data_type;
317 u8 file_type;
318 u8 tflags;
319 i64 width_in_chars; // 0 if unknown
320 i64 number_of_lines; // Reported value. May be incorrect.
321 i64 comment_block_pos; // Valid if num_comments>0.
322 u16 tinfo1, tinfo2, tinfo3, tinfo4;
323 de_ucstring *comment; // NULL if there is no comment
326 int fmtutil_detect_SAUCE(deark *c, dbuf *f, struct de_SAUCE_detection_data *sdd,
327 unsigned int flags);
328 void fmtutil_handle_SAUCE(deark *c, dbuf *f, struct de_SAUCE_info *si);
329 struct de_SAUCE_info *fmtutil_create_SAUCE(deark *c);
330 void fmtutil_free_SAUCE(deark *c, struct de_SAUCE_info *si);
332 struct de_boxesctx;
334 // Return 0 to stop reading
335 typedef int (*de_handle_box_fn)(deark *c, struct de_boxesctx *bctx);
336 typedef void (*de_identify_box_fn)(deark *c, struct de_boxesctx *bctx);
338 struct de_boxdata {
339 // Per-box info supplied to handle_box_fn:
340 struct de_boxdata *parent;
341 int level;
342 u32 boxtype;
343 int is_uuid;
344 u8 uuid[16]; // Valid only if is_uuid is set.
345 i64 box_pos;
346 i64 box_len;
347 // Note: for UUID boxes, payload does not include the UUID
348 i64 payload_pos;
349 i64 payload_len;
351 // To be filled in by identify_box_fn:
352 void *box_userdata;
353 const char *box_name;
355 // To be filled in by handle_box_fn:
356 int handled;
357 int is_superbox;
358 int num_children_is_known;
359 i64 num_children; // valid if (is_superbox) && (num_children_is_known)
360 i64 extra_bytes_before_children; // valid if (is_superbox)
363 struct de_boxesctx {
364 void *userdata;
365 dbuf *f; // Input file
366 de_identify_box_fn identify_box_fn;
367 de_handle_box_fn handle_box_fn;
369 struct de_boxdata *curbox;
372 double dbuf_fmtutil_read_fixed_16_16(dbuf *f, i64 pos);
373 int fmtutil_default_box_handler(deark *c, struct de_boxesctx *bctx);
374 void fmtutil_read_boxes_format(deark *c, struct de_boxesctx *bctx);
375 void fmtutil_render_uuid(deark *c, const u8 *uuid, char *s, size_t s_len);
376 void fmtutil_guid_to_uuid(u8 *id);
378 struct atari_img_decode_data {
379 i64 bpp;
380 i64 ncolors;
381 i64 w, h;
382 dbuf *unc_pixels;
383 int was_compressed;
384 int is_spectrum512;
385 de_color *pal;
386 de_bitmap *img;
389 #define DE_FLAG_ATARI_15BIT_PAL 0x2
390 void fmtutil_read_atari_palette(deark *c, dbuf *f, i64 pos,
391 de_color *dstpal, i64 ncolors_to_read, i64 ncolors_used, unsigned int flags);
393 int fmtutil_atari_decode_image(deark *c, struct atari_img_decode_data *adata);
394 void fmtutil_atari_set_standard_density(deark *c, struct atari_img_decode_data *adata,
395 de_finfo *fi);
396 void fmtutil_atari_help_palbits(deark *c);
398 // The IFF parser supports IFF and similar formats, including RIFF.
399 struct de_iffctx;
401 // An IFF chunk handler is expected to do one of the following:
402 // - Set ictx->is_std_container (ictx->handled is ignored).
403 // - Set ictx->is_raw_container (ictx->handled is ignored).
404 // - Handle the chunk, and set ictx->handled.
405 // - Do nothing, and set ictx->handled, to suppress default handling.
406 // - Do nothing, in which case standard IFF chunks (ANNO, at least) will
407 // handled by the IFF parser.
408 // Return value: Normally 1; 0 to immediately stop processing the entire file.
409 typedef int (*de_handle_iff_chunk_fn)(deark *c, struct de_iffctx *ictx);
411 // Mainly for identifying the chunk.
412 // The user can also adjust ictx->chunkctx->dlen.
413 // Return value: Normally 1 (reserved)
414 typedef int (*de_preprocess_iff_chunk_fn)(deark *c, struct de_iffctx *ictx);
416 // Return value: Normally 1; 0 to immediately stop processing the entire file.
417 typedef int (*de_on_iff_container_end_fn)(deark *c, struct de_iffctx *ictx);
419 // Return value: Normally 1; 0 to stop processing this container (the
420 // on_container_end_fn will not be called).
421 typedef int (*de_on_std_iff_container_start_fn)(deark *c, struct de_iffctx *ictx);
423 // Caller can check for nonstandard non-chunk data at 'pos'. If found, set *plen
424 // to its length, process it if desired, and return 1.
425 typedef int (*de_handle_nonchunk_iff_data_fn)(deark *c, struct de_iffctx *ictx,
426 i64 pos, i64 *plen);
428 struct de_iffchunkctx {
429 struct de_fourcc chunk4cc;
430 i64 pos;
431 i64 len;
432 i64 dpos;
433 i64 dlen;
435 // To be filled in by identify_chunk_fn:
436 void *chunk_userdata;
437 const char *chunk_name;
440 struct de_iffctx {
441 void *userdata;
442 dbuf *f; // Input file
443 de_handle_iff_chunk_fn handle_chunk_fn;
444 de_preprocess_iff_chunk_fn preprocess_chunk_fn;
445 de_on_std_iff_container_start_fn on_std_container_start_fn;
446 de_on_iff_container_end_fn on_container_end_fn;
447 de_handle_nonchunk_iff_data_fn handle_nonchunk_data_fn;
448 i64 alignment; // 0 = default
449 i64 sizeof_len; // 0 = default
450 int is_le; // For RIFF format
451 int reversed_4cc;
452 int input_encoding;
454 int level;
456 // Top-level container type:
457 struct de_fourcc main_fmt4cc; // E.g. "FORM"
458 struct de_fourcc main_contentstype4cc; // E.g. "ILBM"
460 // Current container type:
461 struct de_fourcc curr_container_fmt4cc;
462 struct de_fourcc curr_container_contentstype4cc;
464 // Per-chunk info supplied to handle_chunk_fn:
465 struct de_iffchunkctx *chunkctx;
467 // To be filled in by handle_chunk_fn:
468 int handled;
469 int is_std_container;
470 int is_raw_container;
473 void fmtutil_read_iff_format(deark *c, struct de_iffctx *ictx,
474 i64 pos, i64 len);
475 int fmtutil_is_standard_iff_chunk(deark *c, struct de_iffctx *ictx,
476 u32 ct);
477 void fmtutil_default_iff_chunk_identify(deark *c, struct de_iffctx *ictx);
479 const char *fmtutil_tiff_orientation_name(i64 n);
480 const char *fmtutil_get_windows_charset_name(u8 cs);
481 const char *fmtutil_get_windows_cb_data_type_name(unsigned int ty);
483 int fmtutil_find_zip_eocd(deark *c, dbuf *f, i64 *foundpos);
485 struct de_id3info {
486 int has_id3v1, has_id3v2;
487 i64 main_start, main_end;
489 void fmtutil_handle_id3(deark *c, dbuf *f, struct de_id3info *id3i,
490 unsigned int flags);
492 struct de_advfile;
494 struct de_advfile_cbparams {
495 #define DE_ADVFILE_WRITEMAIN 1
496 #define DE_ADVFILE_WRITERSRC 2
497 int whattodo;
498 dbuf *outf;
501 typedef int (*de_advfile_cbfn)(deark *c, struct de_advfile *advf,
502 struct de_advfile_cbparams *afp);
504 struct de_advfile_forkinfo {
505 u8 fork_exists;
506 i64 fork_len;
507 de_finfo *fi; // Note: do not set the name; use de_advfile.filename.
508 void *userdata_for_writelistener;
509 de_writelistener_cb_type writelistener_cb;
512 struct de_advfile {
513 deark *c;
514 void *userdata;
515 struct de_advfile_forkinfo mainfork;
516 struct de_advfile_forkinfo rsrcfork;
517 de_advfile_cbfn writefork_cbfn;
518 de_ucstring *filename;
519 unsigned int snflags; // flags for de_finfo_set_name*
520 unsigned int createflags;
521 u8 original_filename_flag;
522 u8 no_applesingle;
523 u8 no_appledouble;
524 u8 has_typecode;
525 u8 has_creatorcode;
526 u8 has_finderflags;
527 u16 finderflags;
528 size_t orig_filename_len;
529 u8 *orig_filename;
530 u8 typecode[4];
531 u8 creatorcode[4];
534 struct de_advfile *de_advfile_create(deark *c);
535 void de_advfile_destroy(struct de_advfile *advf);
536 void de_advfile_set_orig_filename(struct de_advfile *advf, const char *fn, size_t fnlen);
537 void de_advfile_run(struct de_advfile *advf);
539 void de_dfilter_set_errorf(deark *c, struct de_dfilter_results *dres, const char *modname,
540 const char *fmt, ...)
541 de_gnuc_attribute ((format (printf, 4, 5)));
542 void de_dfilter_set_generic_error(deark *c, struct de_dfilter_results *dres, const char *modname);
543 const char *de_dfilter_get_errmsg(deark *c, struct de_dfilter_results *dres);
544 void de_dfilter_results_clear(deark *c, struct de_dfilter_results *dres);
545 void de_dfilter_init_objects(deark *c, struct de_dfilter_in_params *dcmpri,
546 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres);
548 struct de_riscos_file_attrs {
549 u8 file_type_known;
550 u32 load_addr, exec_addr;
551 u32 attribs;
552 unsigned int file_type;
553 unsigned int lzwmaxbits;
554 u32 crc_from_attribs;
555 struct de_timestamp mod_time;
558 void fmtutil_riscos_read_load_exec(deark *c, dbuf *f, struct de_riscos_file_attrs *rfa, i64 pos1);
559 #define DE_RISCOS_FLAG_HAS_CRC 0x1
560 #define DE_RISCOS_FLAG_HAS_LZWMAXBITS 0x2
561 void fmtutil_riscos_read_attribs_field(deark *c, dbuf *f, struct de_riscos_file_attrs *rfa,
562 i64 pos, unsigned int flags);
564 struct fmtutil_macbitmap_info {
565 i64 rowbytes; // The rowBytes field
566 i64 rowspan; // Actual number of bytes/row
567 i64 npwidth, pdwidth, height;
568 int is_uncompressed;
569 i64 packing_type;
570 i64 pixeltype, pixelsize;
571 i64 cmpcount, cmpsize;
572 double hdpi, vdpi;
573 u32 pmTable;
574 int pixmap_flag;
575 int has_colortable; // Does the file contain a colortable for this bitmap?
576 int uses_pal; // Are we using the palette below?
577 i64 num_pal_entries;
578 de_color pal[256];
581 void fmtutil_macbitmap_read_baseaddr(deark *c, dbuf *f,
582 struct fmtutil_macbitmap_info *bi, i64 pos);
583 void fmtutil_macbitmap_read_rowbytes_and_bounds(deark *c, dbuf *f,
584 struct fmtutil_macbitmap_info *bi, i64 pos);
585 void fmtutil_macbitmap_read_pixmap_only_fields(deark *c, dbuf *f,
586 struct fmtutil_macbitmap_info *bi, i64 pos);
587 int fmtutil_macbitmap_read_colortable(deark *c, dbuf *f,
588 struct fmtutil_macbitmap_info *bi, i64 pos, i64 *bytes_used);
590 i64 fmtutil_hlp_get_cus_p(dbuf *f, i64 *ppos);
591 i64 fmtutil_hlp_get_css_p(dbuf *f, i64 *ppos);
592 i64 fmtutil_hlp_get_cul_p(dbuf *f, i64 *ppos);
593 i64 fmtutil_hlp_get_csl_p(dbuf *f, i64 *ppos);
595 #define FMTUTIL_HUFFMAN_MAX_CODE_LENGTH 48
596 typedef i32 fmtutil_huffman_valtype;
597 struct fmtutil_huffman_codebook;
598 struct fmtutil_huffman_cursor;
599 struct fmtutil_huffman_code_builder;
600 struct fmtutil_huffman_decoder {
601 struct fmtutil_huffman_cursor *cursor;
602 struct fmtutil_huffman_codebook *bk;
603 struct fmtutil_huffman_code_builder *builder;
605 struct fmtutil_huffman_decoder *fmtutil_huffman_create_decoder(deark *c, i64 initial_codes, i64 max_codes);
606 void fmtutil_huffman_destroy_decoder(deark *c, struct fmtutil_huffman_decoder *ht);
607 void fmtutil_huffman_reset_cursor(struct fmtutil_huffman_cursor *cursor);
608 int fmtutil_huffman_add_code(deark *c, struct fmtutil_huffman_codebook *bk,
609 u64 code, UI code_nbits, fmtutil_huffman_valtype val);
610 int fmtutil_huffman_decode_bit(struct fmtutil_huffman_codebook *bk, struct fmtutil_huffman_cursor *cursor,
611 u8 bitval, fmtutil_huffman_valtype *pval);
612 int fmtutil_huffman_read_next_value(struct fmtutil_huffman_codebook *bk,
613 struct de_bitreader *bitrd, fmtutil_huffman_valtype *pval, UI *pnbits);
614 UI fmtutil_huffman_get_max_bits(struct fmtutil_huffman_codebook *bk);
615 i64 fmtutil_huffman_get_num_codes(struct fmtutil_huffman_codebook *bk);
616 void fmtutil_huffman_dump(deark *c, struct fmtutil_huffman_decoder *ht);
617 int fmtutil_huffman_record_a_code_length(deark *c, struct fmtutil_huffman_code_builder *builder,
618 fmtutil_huffman_valtype val, UI len);
619 #define FMTUTIL_MCTFLAG_LEFT_ALIGN_LEAVES 0x0 // default
620 #define FMTUTIL_MCTFLAG_LEFT_ALIGN_BRANCHES 0x1
621 #define FMTUTIL_MCTFLAG_LAST_CODE_FIRST 0x2 // Pretend codes were added in the reverse order
622 int fmtutil_huffman_make_canonical_code(deark *c, struct fmtutil_huffman_codebook *bk,
623 struct fmtutil_huffman_code_builder *builder, UI flags);
625 typedef void (*fmtutil_lz77buffer_cb_type)(struct de_lz77buffer *rb, u8 n);
627 struct de_lz77buffer {
628 void *userdata;
629 fmtutil_lz77buffer_cb_type writebyte_cb;
630 UI curpos; // Must be kept valid at all times (0...bufsize-1)
631 UI mask;
632 UI bufsize; // Required to be a power of 2
633 u8 *buf;
635 struct de_lz77buffer *de_lz77buffer_create(deark *c, UI bufsize);
636 void de_lz77buffer_destroy(deark *c, struct de_lz77buffer *rb);
637 void de_lz77buffer_clear(struct de_lz77buffer *rb, UI val);
638 void de_lz77buffer_set_curpos(struct de_lz77buffer *rb, UI newpos);
639 void de_lz77buffer_add_literal_byte(struct de_lz77buffer *rb, u8 b);
640 void de_lz77buffer_copy_from_hist(struct de_lz77buffer *rb, UI startpos, UI count);