Edited some module descriptions
[deark.git] / src / deark-fmtutil.h
blob98401e663c207b4be6879c09a8865ab2783e325c
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);
249 void de_dfilter_decompress_two_layer_type2(deark *c,
250 dfilter_codec_type codec1, void *codec1_private_params,
251 dfilter_codec_type codec2, void *codec2_private_params,
252 struct de_dfilter_in_params *dcmpri, struct de_dfilter_out_params *dcmpro,
253 struct de_dfilter_results *dres);
255 void fmtutil_decompress_zip_shrink(deark *c, struct de_dfilter_in_params *dcmpri,
256 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres,
257 void *params);
259 struct de_zipreduce_params {
260 unsigned int cmpr_factor;
262 void fmtutil_decompress_zip_reduce(deark *c, struct de_dfilter_in_params *dcmpri,
263 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres,
264 struct de_zipreduce_params *params);
266 struct de_zipimplode_params {
267 unsigned int bit_flags;
268 u8 mml_bug;
270 void fmtutil_decompress_zip_implode(deark *c, struct de_dfilter_in_params *dcmpri,
271 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres,
272 struct de_zipimplode_params *params);
274 void fmtutil_dclimplode_codectype1(deark *c, struct de_dfilter_in_params *dcmpri,
275 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres,
276 void *codec_private_params);
278 // Wrapper for miniz' tdefl functions
280 enum fmtutil_tdefl_status {
281 FMTUTIL_TDEFL_STATUS_BAD_PARAM = -2,
282 FMTUTIL_TDEFL_STATUS_PUT_BUF_FAILED = -1,
283 FMTUTIL_TDEFL_STATUS_OKAY = 0,
284 FMTUTIL_TDEFL_STATUS_DONE = 1
287 enum fmtutil_tdefl_flush {
288 FMTUTIL_TDEFL_NO_FLUSH = 0,
289 FMTUTIL_TDEFL_SYNC_FLUSH = 2,
290 FMTUTIL_TDEFL_FULL_FLUSH = 3,
291 FMTUTIL_TDEFL_FINISH = 4
294 struct fmtutil_tdefl_ctx;
295 struct fmtutil_tdefl_ctx *fmtutil_tdefl_create(deark *c, dbuf *outf, int flags);
296 enum fmtutil_tdefl_status fmtutil_tdefl_compress_buffer(struct fmtutil_tdefl_ctx *tdctx,
297 const void *pIn_buf, size_t in_buf_size, enum fmtutil_tdefl_flush flush);
298 void fmtutil_tdefl_destroy(struct fmtutil_tdefl_ctx *tdctx);
299 unsigned int fmtutil_tdefl_create_comp_flags_from_zip_params(int level, int window_bits,
300 int strategy);
302 struct de_SAUCE_info {
303 int is_valid;
304 de_ucstring *title;
305 de_ucstring *artist;
306 de_ucstring *organization;
307 struct de_timestamp creation_date;
308 i64 original_file_size;
309 u8 data_type;
310 u8 file_type;
311 u8 tflags;
312 i64 width_in_chars; // 0 if unknown
313 i64 number_of_lines; // Reported value. May be incorrect.
314 i64 comment_block_pos; // Valid if num_comments>0.
315 u16 tinfo1, tinfo2, tinfo3, tinfo4;
316 de_ucstring *comment; // NULL if there is no comment
319 int fmtutil_detect_SAUCE(deark *c, dbuf *f, struct de_SAUCE_detection_data *sdd,
320 unsigned int flags);
321 void fmtutil_handle_SAUCE(deark *c, dbuf *f, struct de_SAUCE_info *si);
322 struct de_SAUCE_info *fmtutil_create_SAUCE(deark *c);
323 void fmtutil_free_SAUCE(deark *c, struct de_SAUCE_info *si);
325 struct de_boxesctx;
327 // Return 0 to stop reading
328 typedef int (*de_handle_box_fn)(deark *c, struct de_boxesctx *bctx);
329 typedef void (*de_identify_box_fn)(deark *c, struct de_boxesctx *bctx);
331 struct de_boxdata {
332 // Per-box info supplied to handle_box_fn:
333 struct de_boxdata *parent;
334 int level;
335 u32 boxtype;
336 int is_uuid;
337 u8 uuid[16]; // Valid only if is_uuid is set.
338 i64 box_pos;
339 i64 box_len;
340 // Note: for UUID boxes, payload does not include the UUID
341 i64 payload_pos;
342 i64 payload_len;
344 // To be filled in by identify_box_fn:
345 void *box_userdata;
346 const char *box_name;
348 // To be filled in by handle_box_fn:
349 int handled;
350 int is_superbox;
351 int num_children_is_known;
352 i64 num_children; // valid if (is_superbox) && (num_children_is_known)
353 i64 extra_bytes_before_children; // valid if (is_superbox)
356 struct de_boxesctx {
357 void *userdata;
358 dbuf *f; // Input file
359 de_identify_box_fn identify_box_fn;
360 de_handle_box_fn handle_box_fn;
362 struct de_boxdata *curbox;
365 double dbuf_fmtutil_read_fixed_16_16(dbuf *f, i64 pos);
366 int fmtutil_default_box_handler(deark *c, struct de_boxesctx *bctx);
367 void fmtutil_read_boxes_format(deark *c, struct de_boxesctx *bctx);
368 void fmtutil_render_uuid(deark *c, const u8 *uuid, char *s, size_t s_len);
369 void fmtutil_guid_to_uuid(u8 *id);
371 struct atari_img_decode_data {
372 i64 bpp;
373 i64 ncolors;
374 i64 w, h;
375 dbuf *unc_pixels;
376 int was_compressed;
377 int is_spectrum512;
378 de_color *pal;
379 de_bitmap *img;
382 #define DE_FLAG_ATARI_15BIT_PAL 0x2
383 void fmtutil_read_atari_palette(deark *c, dbuf *f, i64 pos,
384 de_color *dstpal, i64 ncolors_to_read, i64 ncolors_used, unsigned int flags);
386 int fmtutil_atari_decode_image(deark *c, struct atari_img_decode_data *adata);
387 void fmtutil_atari_set_standard_density(deark *c, struct atari_img_decode_data *adata,
388 de_finfo *fi);
389 void fmtutil_atari_help_palbits(deark *c);
391 // The IFF parser supports IFF and similar formats, including RIFF.
392 struct de_iffctx;
394 // An IFF chunk handler is expected to do one of the following:
395 // - Set ictx->is_std_container (ictx->handled is ignored).
396 // - Set ictx->is_raw_container (ictx->handled is ignored).
397 // - Handle the chunk, and set ictx->handled.
398 // - Do nothing, and set ictx->handled, to suppress default handling.
399 // - Do nothing, in which case standard IFF chunks (ANNO, at least) will
400 // handled by the IFF parser.
401 // Return value: Normally 1; 0 to immediately stop processing the entire file.
402 typedef int (*de_handle_iff_chunk_fn)(deark *c, struct de_iffctx *ictx);
404 // Mainly for identifying the chunk.
405 // The user can also adjust ictx->chunkctx->dlen.
406 // Return value: Normally 1 (reserved)
407 typedef int (*de_preprocess_iff_chunk_fn)(deark *c, struct de_iffctx *ictx);
409 // Return value: Normally 1; 0 to immediately stop processing the entire file.
410 typedef int (*de_on_iff_container_end_fn)(deark *c, struct de_iffctx *ictx);
412 // Return value: Normally 1; 0 to stop processing this container (the
413 // on_container_end_fn will not be called).
414 typedef int (*de_on_std_iff_container_start_fn)(deark *c, struct de_iffctx *ictx);
416 // Caller can check for nonstandard non-chunk data at 'pos'. If found, set *plen
417 // to its length, process it if desired, and return 1.
418 typedef int (*de_handle_nonchunk_iff_data_fn)(deark *c, struct de_iffctx *ictx,
419 i64 pos, i64 *plen);
421 struct de_iffchunkctx {
422 struct de_fourcc chunk4cc;
423 i64 pos;
424 i64 len;
425 i64 dpos;
426 i64 dlen;
428 // To be filled in by identify_chunk_fn:
429 void *chunk_userdata;
430 const char *chunk_name;
433 struct de_iffctx {
434 void *userdata;
435 dbuf *f; // Input file
436 de_handle_iff_chunk_fn handle_chunk_fn;
437 de_preprocess_iff_chunk_fn preprocess_chunk_fn;
438 de_on_std_iff_container_start_fn on_std_container_start_fn;
439 de_on_iff_container_end_fn on_container_end_fn;
440 de_handle_nonchunk_iff_data_fn handle_nonchunk_data_fn;
441 i64 alignment; // 0 = default
442 i64 sizeof_len; // 0 = default
443 int is_le; // For RIFF format
444 int reversed_4cc;
445 int input_encoding;
447 int level;
449 // Top-level container type:
450 struct de_fourcc main_fmt4cc; // E.g. "FORM"
451 struct de_fourcc main_contentstype4cc; // E.g. "ILBM"
453 // Current container type:
454 struct de_fourcc curr_container_fmt4cc;
455 struct de_fourcc curr_container_contentstype4cc;
457 // Per-chunk info supplied to handle_chunk_fn:
458 struct de_iffchunkctx *chunkctx;
460 // To be filled in by handle_chunk_fn:
461 int handled;
462 int is_std_container;
463 int is_raw_container;
466 void fmtutil_read_iff_format(deark *c, struct de_iffctx *ictx,
467 i64 pos, i64 len);
468 int fmtutil_is_standard_iff_chunk(deark *c, struct de_iffctx *ictx,
469 u32 ct);
470 void fmtutil_default_iff_chunk_identify(deark *c, struct de_iffctx *ictx);
472 const char *fmtutil_tiff_orientation_name(i64 n);
473 const char *fmtutil_get_windows_charset_name(u8 cs);
474 const char *fmtutil_get_windows_cb_data_type_name(unsigned int ty);
476 int fmtutil_find_zip_eocd(deark *c, dbuf *f, i64 *foundpos);
478 struct de_id3info {
479 int has_id3v1, has_id3v2;
480 i64 main_start, main_end;
482 void fmtutil_handle_id3(deark *c, dbuf *f, struct de_id3info *id3i,
483 unsigned int flags);
485 struct de_advfile;
487 struct de_advfile_cbparams {
488 #define DE_ADVFILE_WRITEMAIN 1
489 #define DE_ADVFILE_WRITERSRC 2
490 int whattodo;
491 dbuf *outf;
494 typedef int (*de_advfile_cbfn)(deark *c, struct de_advfile *advf,
495 struct de_advfile_cbparams *afp);
497 struct de_advfile_forkinfo {
498 u8 fork_exists;
499 i64 fork_len;
500 de_finfo *fi; // Note: do not set the name; use de_advfile.filename.
501 void *userdata_for_writelistener;
502 de_writelistener_cb_type writelistener_cb;
505 struct de_advfile {
506 deark *c;
507 void *userdata;
508 struct de_advfile_forkinfo mainfork;
509 struct de_advfile_forkinfo rsrcfork;
510 de_advfile_cbfn writefork_cbfn;
511 de_ucstring *filename;
512 unsigned int snflags; // flags for de_finfo_set_name*
513 unsigned int createflags;
514 u8 original_filename_flag;
515 u8 no_applesingle;
516 u8 no_appledouble;
517 u8 has_typecode;
518 u8 has_creatorcode;
519 u8 has_finderflags;
520 u16 finderflags;
521 size_t orig_filename_len;
522 u8 *orig_filename;
523 u8 typecode[4];
524 u8 creatorcode[4];
527 struct de_advfile *de_advfile_create(deark *c);
528 void de_advfile_destroy(struct de_advfile *advf);
529 void de_advfile_set_orig_filename(struct de_advfile *advf, const char *fn, size_t fnlen);
530 void de_advfile_run(struct de_advfile *advf);
532 void de_dfilter_set_errorf(deark *c, struct de_dfilter_results *dres, const char *modname,
533 const char *fmt, ...)
534 de_gnuc_attribute ((format (printf, 4, 5)));
535 void de_dfilter_set_generic_error(deark *c, struct de_dfilter_results *dres, const char *modname);
536 const char *de_dfilter_get_errmsg(deark *c, struct de_dfilter_results *dres);
537 void de_dfilter_results_clear(deark *c, struct de_dfilter_results *dres);
538 void de_dfilter_init_objects(deark *c, struct de_dfilter_in_params *dcmpri,
539 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres);
541 struct de_riscos_file_attrs {
542 u8 file_type_known;
543 u32 load_addr, exec_addr;
544 u32 attribs;
545 unsigned int file_type;
546 unsigned int lzwmaxbits;
547 u32 crc_from_attribs;
548 struct de_timestamp mod_time;
551 void fmtutil_riscos_read_load_exec(deark *c, dbuf *f, struct de_riscos_file_attrs *rfa, i64 pos1);
552 #define DE_RISCOS_FLAG_HAS_CRC 0x1
553 #define DE_RISCOS_FLAG_HAS_LZWMAXBITS 0x2
554 void fmtutil_riscos_read_attribs_field(deark *c, dbuf *f, struct de_riscos_file_attrs *rfa,
555 i64 pos, unsigned int flags);
557 struct fmtutil_macbitmap_info {
558 i64 rowbytes; // The rowBytes field
559 i64 rowspan; // Actual number of bytes/row
560 i64 npwidth, pdwidth, height;
561 int is_uncompressed;
562 i64 packing_type;
563 i64 pixeltype, pixelsize;
564 i64 cmpcount, cmpsize;
565 double hdpi, vdpi;
566 u32 pmTable;
567 int pixmap_flag;
568 int has_colortable; // Does the file contain a colortable for this bitmap?
569 int uses_pal; // Are we using the palette below?
570 i64 num_pal_entries;
571 de_color pal[256];
574 void fmtutil_macbitmap_read_baseaddr(deark *c, dbuf *f,
575 struct fmtutil_macbitmap_info *bi, i64 pos);
576 void fmtutil_macbitmap_read_rowbytes_and_bounds(deark *c, dbuf *f,
577 struct fmtutil_macbitmap_info *bi, i64 pos);
578 void fmtutil_macbitmap_read_pixmap_only_fields(deark *c, dbuf *f,
579 struct fmtutil_macbitmap_info *bi, i64 pos);
580 int fmtutil_macbitmap_read_colortable(deark *c, dbuf *f,
581 struct fmtutil_macbitmap_info *bi, i64 pos, i64 *bytes_used);
583 i64 fmtutil_hlp_get_cus_p(dbuf *f, i64 *ppos);
584 i64 fmtutil_hlp_get_css_p(dbuf *f, i64 *ppos);
585 i64 fmtutil_hlp_get_cul_p(dbuf *f, i64 *ppos);
586 i64 fmtutil_hlp_get_csl_p(dbuf *f, i64 *ppos);
588 #define FMTUTIL_HUFFMAN_MAX_CODE_LENGTH 48
589 typedef i32 fmtutil_huffman_valtype;
590 struct fmtutil_huffman_codebook;
591 struct fmtutil_huffman_cursor;
592 struct fmtutil_huffman_code_builder;
593 struct fmtutil_huffman_decoder {
594 struct fmtutil_huffman_cursor *cursor;
595 struct fmtutil_huffman_codebook *bk;
596 struct fmtutil_huffman_code_builder *builder;
598 struct fmtutil_huffman_decoder *fmtutil_huffman_create_decoder(deark *c, i64 initial_codes, i64 max_codes);
599 void fmtutil_huffman_destroy_decoder(deark *c, struct fmtutil_huffman_decoder *ht);
600 void fmtutil_huffman_reset_cursor(struct fmtutil_huffman_cursor *cursor);
601 int fmtutil_huffman_add_code(deark *c, struct fmtutil_huffman_codebook *bk,
602 u64 code, UI code_nbits, fmtutil_huffman_valtype val);
603 int fmtutil_huffman_decode_bit(struct fmtutil_huffman_codebook *bk, struct fmtutil_huffman_cursor *cursor,
604 u8 bitval, fmtutil_huffman_valtype *pval);
605 int fmtutil_huffman_read_next_value(struct fmtutil_huffman_codebook *bk,
606 struct de_bitreader *bitrd, fmtutil_huffman_valtype *pval, UI *pnbits);
607 UI fmtutil_huffman_get_max_bits(struct fmtutil_huffman_codebook *bk);
608 i64 fmtutil_huffman_get_num_codes(struct fmtutil_huffman_codebook *bk);
609 void fmtutil_huffman_dump(deark *c, struct fmtutil_huffman_decoder *ht);
610 int fmtutil_huffman_record_a_code_length(deark *c, struct fmtutil_huffman_code_builder *builder,
611 fmtutil_huffman_valtype val, UI len);
612 #define FMTUTIL_MCTFLAG_LEFT_ALIGN_LEAVES 0x0 // default
613 #define FMTUTIL_MCTFLAG_LEFT_ALIGN_BRANCHES 0x1
614 #define FMTUTIL_MCTFLAG_LAST_CODE_FIRST 0x2 // Pretend codes were added in the reverse order
615 int fmtutil_huffman_make_canonical_code(deark *c, struct fmtutil_huffman_codebook *bk,
616 struct fmtutil_huffman_code_builder *builder, UI flags);
618 typedef void (*fmtutil_lz77buffer_cb_type)(struct de_lz77buffer *rb, u8 n);
620 struct de_lz77buffer {
621 void *userdata;
622 fmtutil_lz77buffer_cb_type writebyte_cb;
623 UI curpos; // Must be kept valid at all times (0...bufsize-1)
624 UI mask;
625 UI bufsize; // Required to be a power of 2
626 u8 *buf;
628 struct de_lz77buffer *de_lz77buffer_create(deark *c, UI bufsize);
629 void de_lz77buffer_destroy(deark *c, struct de_lz77buffer *rb);
630 void de_lz77buffer_clear(struct de_lz77buffer *rb, UI val);
631 void de_lz77buffer_set_curpos(struct de_lz77buffer *rb, UI newpos);
632 void de_lz77buffer_add_literal_byte(struct de_lz77buffer *rb, u8 b);
633 void de_lz77buffer_copy_from_hist(struct de_lz77buffer *rb, UI startpos, UI count);