Renamed ttcomp module to dclimplode
[deark.git] / src / deark-fmtutil.h
blob990c4dd2ae9df1d0ef39b544214f2d30ceee64fc
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, UI flags);
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 i64 input_file_offset; // Non-critical, may be used by dbg messages
146 u8 finished_flag;
147 void *codec_private;
148 dfilter_codec_addbuf_type codec_addbuf_fn;
149 dfilter_codec_command_type codec_command_fn;
150 dfilter_codec_finish_type codec_finish_fn;
151 dfilter_codec_destroy_type codec_destroy_fn;
154 enum de_lzwfmt_enum {
155 DE_LZWFMT_GENERIC = 0,
156 DE_LZWFMT_UNIXCOMPRESS,
157 DE_LZWFMT_GIF,
158 DE_LZWFMT_ZIPSHRINK,
159 DE_LZWFMT_ZOOLZD,
160 DE_LZWFMT_TIFF,
161 DE_LZWFMT_ARC5
164 struct de_lzw_params {
165 enum de_lzwfmt_enum fmt;
166 #define DE_LZWFLAG_HAS3BYTEHEADER 0x1 // Unix-compress style, use with fmt=UNIXCOMPRESS
167 #define DE_LZWFLAG_HAS1BYTEHEADER 0x2 // ARC style, use with fmt=UNIXCOMPRESS
168 #define DE_LZWFLAG_TOLERATETRAILINGJUNK 0x4
169 UI flags;
170 unsigned int gif_root_code_size;
171 unsigned int max_code_size; // 0 = no info
172 u8 tifflzw_oldversion; // 1 = old version
173 u8 arc5_has_stop_code;
175 void fmtutil_decompress_lzw(deark *c, struct de_dfilter_in_params *dcmpri,
176 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres,
177 struct de_lzw_params *lzwp);
179 void dfilter_lzw_codec(struct de_dfilter_ctx *dfctx, void *codec_private_params);
180 void dfilter_rle90_codec(struct de_dfilter_ctx *dfctx, void *codec_private_params);
181 void dfilter_packbits_codec(struct de_dfilter_ctx *dfctx, void *codec_private_params);
183 struct de_lh5x_params {
184 #define DE_LH5X_FMT_LH5 5
185 #define DE_LH5X_FMT_LH6 6
186 #define DE_LH5X_FMT_LH7 7
187 #define DE_LH5X_FMT_LHARK 100
188 int fmt;
190 // How to handle a block with "0" codes:
191 #define DE_LH5X_ZCB_ERROR 0
192 #define DE_LH5X_ZCB_STOP 1
193 #define DE_LH5X_ZCB_0 2
194 #define DE_LH5X_ZCB_65536 3
195 u8 zero_codes_block_behavior;
196 u8 warn_about_zero_codes_block;
198 u8 history_fill_val; // Set to 0x20 (space) if not sure.
200 void fmtutil_decompress_lh5x(deark *c, struct de_dfilter_in_params *dcmpri,
201 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres,
202 struct de_lh5x_params *lzhp);
203 void fmtutil_lh5x_codectype1(deark *c, struct de_dfilter_in_params *dcmpri,
204 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres,
205 void *codec_private_params);
207 struct de_fax34_params {
208 i64 image_width;
209 i64 image_height;
210 i64 out_rowspan;
211 UI tiff_cmpr_meth;
212 u8 is_lsb;
213 u32 t4options;
214 u32 t6options;
216 void fmtutil_fax34_codectype1(deark *c, struct de_dfilter_in_params *dcmpri,
217 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres,
218 void *codec_private_params);
220 struct de_dfilter_ctx *de_dfilter_create(deark *c,
221 dfilter_codec_type codec_init_fn, void *codec_private_params,
222 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres);
223 void de_dfilter_addbuf(struct de_dfilter_ctx *dfctx,
224 const u8 *buf, i64 buf_len);
225 #define DE_DFILTER_COMMAND_SOFTRESET 1
226 #define DE_DFILTER_COMMAND_REINITIALIZE 2
227 #define DE_DFILTER_COMMAND_FINISH_BLOCK 3
228 #define DE_DFILTER_COMMAND_RESET_COUNTERS 4
229 void de_dfilter_command(struct de_dfilter_ctx *dfctx, int cmd, UI flags);
230 void de_dfilter_addslice(struct de_dfilter_ctx *dfctx,
231 dbuf *inf, i64 pos, i64 len);
232 void de_dfilter_finish(struct de_dfilter_ctx *dfctx);
233 void de_dfilter_destroy(struct de_dfilter_ctx *dfctx);
234 void de_dfilter_transfer_error(deark *c, struct de_dfilter_results *src,
235 struct de_dfilter_results *dst);
237 void de_dfilter_decompress_oneshot(deark *c,
238 dfilter_codec_type codec_init_fn, void *codec_private_params,
239 struct de_dfilter_in_params *dcmpri, struct de_dfilter_out_params *dcmpro,
240 struct de_dfilter_results *dres);
241 struct de_dcmpr_two_layer_params {
242 de_codectype1_type codec1_type1; // Set either this or codec1_pushable
243 dfilter_codec_type codec1_pushable;
244 void *codec1_private_params;
245 dfilter_codec_type codec2;
246 void *codec2_private_params;
247 struct de_dfilter_in_params *dcmpri;
248 struct de_dfilter_out_params *dcmpro;
249 struct de_dfilter_results *dres;
250 u8 intermed_len_known;
251 i64 intermed_expected_len;
253 void de_dfilter_decompress_two_layer(deark *c, struct de_dcmpr_two_layer_params *tlp);
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);
277 void fmtutil_distilled_codectype1(deark *c, struct de_dfilter_in_params *dcmpri,
278 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres,
279 void *codec_private_params);
281 void fmtutil_get_lzhuf_d_code_and_len(UI n, UI *pd_code, UI *pd_len);
283 struct de_lh1_params {
284 u8 is_crlzh11, is_crlzh20;
285 u8 is_arc_trimmed; // (The LZH part of the scheme. Does not do RLE.)
286 u8 is_dms_deep; // (The LZH part of the scheme.)
287 u8 history_fill_val; // Set to 0x20 (space) if not sure.
290 void fmtutil_lh1_codectype1(deark *c, struct de_dfilter_in_params *dcmpri,
291 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres,
292 void *codec_private_params);
293 void dfilter_lh1_codec(struct de_dfilter_ctx *dfctx, void *codec_private_params);
295 // Wrapper for miniz' tdefl functions
297 enum fmtutil_tdefl_status {
298 FMTUTIL_TDEFL_STATUS_BAD_PARAM = -2,
299 FMTUTIL_TDEFL_STATUS_PUT_BUF_FAILED = -1,
300 FMTUTIL_TDEFL_STATUS_OKAY = 0,
301 FMTUTIL_TDEFL_STATUS_DONE = 1
304 enum fmtutil_tdefl_flush {
305 FMTUTIL_TDEFL_NO_FLUSH = 0,
306 FMTUTIL_TDEFL_SYNC_FLUSH = 2,
307 FMTUTIL_TDEFL_FULL_FLUSH = 3,
308 FMTUTIL_TDEFL_FINISH = 4
311 struct fmtutil_tdefl_ctx;
312 struct fmtutil_tdefl_ctx *fmtutil_tdefl_create(deark *c, dbuf *outf, int flags);
313 enum fmtutil_tdefl_status fmtutil_tdefl_compress_buffer(struct fmtutil_tdefl_ctx *tdctx,
314 const void *pIn_buf, size_t in_buf_size, enum fmtutil_tdefl_flush flush);
315 void fmtutil_tdefl_destroy(struct fmtutil_tdefl_ctx *tdctx);
316 unsigned int fmtutil_tdefl_create_comp_flags_from_zip_params(int level, int window_bits,
317 int strategy);
319 struct de_SAUCE_info {
320 int is_valid;
321 de_ucstring *title;
322 de_ucstring *artist;
323 de_ucstring *organization;
324 struct de_timestamp creation_date;
325 i64 original_file_size;
326 u8 data_type;
327 u8 file_type;
328 u8 tflags;
329 i64 width_in_chars; // 0 if unknown
330 i64 number_of_lines; // Reported value. May be incorrect.
331 i64 comment_block_pos; // Valid if num_comments>0.
332 u16 tinfo1, tinfo2, tinfo3, tinfo4;
333 de_ucstring *comment; // NULL if there is no comment
336 int fmtutil_detect_SAUCE(deark *c, dbuf *f, struct de_SAUCE_detection_data *sdd,
337 unsigned int flags);
338 void fmtutil_handle_SAUCE(deark *c, dbuf *f, struct de_SAUCE_info *si);
339 struct de_SAUCE_info *fmtutil_create_SAUCE(deark *c);
340 void fmtutil_free_SAUCE(deark *c, struct de_SAUCE_info *si);
342 struct de_boxesctx;
344 // Return 0 to stop reading
345 typedef int (*de_handle_box_fn)(deark *c, struct de_boxesctx *bctx);
346 typedef void (*de_identify_box_fn)(deark *c, struct de_boxesctx *bctx);
348 struct de_boxdata {
349 // Per-box info supplied to handle_box_fn:
350 struct de_boxdata *parent;
351 int level;
352 u32 boxtype;
353 int is_uuid;
354 u8 uuid[16]; // Valid only if is_uuid is set.
355 i64 box_pos;
356 i64 box_len;
357 // Note: for UUID boxes, payload does not include the UUID
358 i64 payload_pos;
359 i64 payload_len;
361 // To be filled in by identify_box_fn:
362 void *box_userdata;
363 const char *box_name;
365 // To be filled in by handle_box_fn:
366 int handled;
367 int is_superbox;
368 int num_children_is_known;
369 i64 num_children; // valid if (is_superbox) && (num_children_is_known)
370 i64 extra_bytes_before_children; // valid if (is_superbox)
373 struct de_boxesctx {
374 void *userdata;
375 void *private_data; // Used by the parser
376 dbuf *f; // Input file
377 de_identify_box_fn identify_box_fn;
378 de_handle_box_fn handle_box_fn;
380 struct de_boxdata *curbox;
383 double dbuf_fmtutil_read_fixed_16_16(dbuf *f, i64 pos);
384 int fmtutil_default_box_handler(deark *c, struct de_boxesctx *bctx);
385 void fmtutil_read_boxes_format(deark *c, struct de_boxesctx *bctx);
386 void fmtutil_render_uuid(deark *c, const u8 *uuid, char *s, size_t s_len);
387 void fmtutil_guid_to_uuid(u8 *id);
389 struct atari_img_decode_data {
390 i64 bpp;
391 i64 ncolors;
392 i64 w, h;
393 dbuf *unc_pixels;
394 int was_compressed;
395 int is_spectrum512;
396 de_color *pal;
397 de_bitmap *img;
400 #define DE_FLAG_ATARI_15BIT_PAL 0x2
401 void fmtutil_read_atari_palette(deark *c, dbuf *f, i64 pos,
402 de_color *dstpal, i64 ncolors_to_read, i64 ncolors_used, unsigned int flags);
404 int fmtutil_atari_decode_image(deark *c, struct atari_img_decode_data *adata);
405 void fmtutil_atari_set_standard_density(deark *c, struct atari_img_decode_data *adata,
406 de_finfo *fi);
407 void fmtutil_atari_help_palbits(deark *c);
409 // The IFF parser supports IFF and similar formats, including RIFF.
410 struct de_iffctx;
412 // An IFF chunk handler is expected to do one of the following (if it returns 1):
413 // - Set ictx->is_std_container (ictx->handled is ignored).
414 // - Set ictx->is_raw_container (ictx->handled is ignored).
415 // - Handle the chunk, and set ictx->handled.
416 // - Do nothing, and set ictx->handled, to suppress default handling.
417 // - Do nothing, which will result in the default chunk handler being used.
418 // Usually the default handler will do nothing, or a hex dump if the
419 // debug_level is high enough. If the format is known to have standard
420 // IFF chunks or something like that, they may be parsed.
421 // Return value: Normally 1; 0 to immediately stop processing the entire file.
422 typedef int (*de_handle_iff_chunk_fn)(struct de_iffctx *ictx);
424 // Mainly for identifying the chunk.
425 // The user can also adjust ictx->chunkctx->dlen.
426 // Return value: Normally 1 (reserved)
427 typedef int (*de_preprocess_iff_chunk_fn)(struct de_iffctx *ictx);
429 // Return value: Normally 1; 0 to immediately stop processing the entire file.
430 typedef int (*de_on_iff_container_end_fn)(struct de_iffctx *ictx);
432 // Return value: Normally 1; 0 to stop processing this container (the
433 // on_container_end_fn will not be called).
434 typedef int (*de_on_std_iff_container_start_fn)(struct de_iffctx *ictx);
436 // Caller can check for nonstandard non-chunk data at 'pos'. If found, set *plen
437 // to its length, process it if desired, and return 1.
438 typedef int (*de_handle_nonchunk_iff_data_fn)(struct de_iffctx *ictx,
439 i64 pos, i64 *plen);
441 struct de_iffchunkctx {
442 struct de_fourcc chunk4cc;
443 i64 pos;
444 i64 len;
445 i64 dpos;
446 i64 dlen;
447 struct de_iffchunkctx *parent;
449 // To be filled in by identify_chunk_fn:
450 const char *chunk_name;
452 // Other use:
453 u32 user_flags;
456 struct de_iffctx {
457 deark *c;
458 void *private_data; // Used by the parser
460 void *userdata;
461 dbuf *f; // Input file
462 de_handle_iff_chunk_fn handle_chunk_fn;
463 de_preprocess_iff_chunk_fn preprocess_chunk_fn;
465 // Called after the "FORM type" is read
466 de_on_std_iff_container_start_fn on_std_container_start_fn;
468 de_on_iff_container_end_fn on_container_end_fn;
469 de_handle_nonchunk_iff_data_fn handle_nonchunk_data_fn;
470 i64 alignment; // 0 = default
471 i64 sizeof_len; // 0 = default
472 int is_le; // For RIFF format
473 u8 reversed_4cc;
474 u8 has_standard_iff_chunks;
475 de_encoding input_encoding;
477 int level;
479 // Info about the most-recent top-level container:
480 struct de_fourcc main_fmt4cc; // E.g. "FORM"
481 struct de_fourcc main_contentstype4cc; // E.g. "ILBM"
483 // Current container:
484 struct de_fourcc curr_container_fmt4cc;
485 struct de_fourcc curr_container_contentstype4cc;
487 // Per-chunk info supplied to chunk handling functions:
488 struct de_iffchunkctx *chunkctx;
490 // To be filled in by handle_chunk_fn:
491 int handled;
492 int is_std_container;
493 int is_raw_container;
496 struct de_iffctx *fmtutil_create_iff_decoder(deark *c);
497 void fmtutil_destroy_iff_decoder(struct de_iffctx *ictx);
498 void fmtutil_read_iff_format(struct de_iffctx *ictx, i64 pos, i64 len);
500 const char *fmtutil_tiff_orientation_name(i64 n);
501 const char *fmtutil_get_windows_charset_name(u8 cs);
502 const char *fmtutil_get_windows_cb_data_type_name(unsigned int ty);
504 int fmtutil_find_zip_eocd(deark *c, dbuf *f, i64 *foundpos);
506 struct de_id3info {
507 int has_id3v1, has_id3v2;
508 i64 main_start, main_end;
510 void fmtutil_handle_id3(deark *c, dbuf *f, struct de_id3info *id3i,
511 unsigned int flags);
513 struct de_advfile;
515 struct de_advfile_cbparams {
516 #define DE_ADVFILE_WRITEMAIN 1
517 #define DE_ADVFILE_WRITERSRC 2
518 int whattodo;
519 dbuf *outf;
522 typedef int (*de_advfile_cbfn)(deark *c, struct de_advfile *advf,
523 struct de_advfile_cbparams *afp);
525 struct de_advfile_forkinfo {
526 u8 fork_exists;
527 i64 fork_len;
528 de_finfo *fi; // Note: do not set the name; use de_advfile.filename.
529 void *userdata_for_writelistener;
530 de_writelistener_cb_type writelistener_cb;
533 struct de_advfile {
534 deark *c;
535 void *userdata;
536 struct de_advfile_forkinfo mainfork;
537 struct de_advfile_forkinfo rsrcfork;
538 de_advfile_cbfn writefork_cbfn;
539 de_ucstring *filename;
540 unsigned int snflags; // flags for de_finfo_set_name*
541 unsigned int createflags;
542 u8 original_filename_flag;
543 u8 no_applesingle;
544 u8 no_appledouble;
545 u8 has_typecode;
546 u8 has_creatorcode;
547 u8 has_finderflags;
548 u16 finderflags;
549 size_t orig_filename_len;
550 u8 *orig_filename;
551 u8 typecode[4];
552 u8 creatorcode[4];
555 struct de_advfile *de_advfile_create(deark *c);
556 void de_advfile_destroy(struct de_advfile *advf);
557 void de_advfile_set_orig_filename(struct de_advfile *advf, const char *fn, size_t fnlen);
558 void de_advfile_run(struct de_advfile *advf);
560 void de_dfilter_set_errorf(deark *c, struct de_dfilter_results *dres, const char *modname,
561 const char *fmt, ...)
562 de_gnuc_attribute ((format (printf, 4, 5)));
563 void de_dfilter_set_generic_error(deark *c, struct de_dfilter_results *dres, const char *modname);
564 const char *de_dfilter_get_errmsg(deark *c, struct de_dfilter_results *dres);
565 void de_dfilter_results_clear(deark *c, struct de_dfilter_results *dres);
566 void de_dfilter_init_objects(deark *c, struct de_dfilter_in_params *dcmpri,
567 struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres);
569 struct de_riscos_file_attrs {
570 u8 file_type_known;
571 u32 load_addr, exec_addr;
572 u32 attribs;
573 unsigned int file_type;
574 unsigned int lzwmaxbits;
575 u32 crc_from_attribs;
576 struct de_timestamp mod_time;
579 void fmtutil_riscos_read_load_exec(deark *c, dbuf *f, struct de_riscos_file_attrs *rfa, i64 pos1);
580 #define DE_RISCOS_FLAG_HAS_CRC 0x1
581 #define DE_RISCOS_FLAG_HAS_LZWMAXBITS 0x2
582 void fmtutil_riscos_read_attribs_field(deark *c, dbuf *f, struct de_riscos_file_attrs *rfa,
583 i64 pos, unsigned int flags);
584 void fmtutil_riscos_append_type_to_filename(deark *c, de_finfo *fi, de_ucstring *fn,
585 struct de_riscos_file_attrs *rfa, int is_dir, int enabled_by_default);
587 struct fmtutil_macbitmap_info {
588 i64 rowbytes; // The rowBytes field
589 i64 rowspan; // Actual number of bytes/row
590 i64 npwidth, pdwidth, height;
591 int is_uncompressed;
592 i64 packing_type;
593 i64 pixeltype, pixelsize;
594 i64 cmpcount, cmpsize;
595 double hdpi, vdpi;
596 u32 pmTable;
597 int pixmap_flag;
598 int has_colortable; // Does the file contain a colortable for this bitmap?
599 int uses_pal; // Are we using the palette below?
600 i64 num_pal_entries;
601 de_color pal[256];
604 void fmtutil_macbitmap_read_baseaddr(deark *c, dbuf *f,
605 struct fmtutil_macbitmap_info *bi, i64 pos);
606 void fmtutil_macbitmap_read_rowbytes_and_bounds(deark *c, dbuf *f,
607 struct fmtutil_macbitmap_info *bi, i64 pos);
608 void fmtutil_macbitmap_read_pixmap_only_fields(deark *c, dbuf *f,
609 struct fmtutil_macbitmap_info *bi, i64 pos);
610 int fmtutil_macbitmap_read_colortable(deark *c, dbuf *f,
611 struct fmtutil_macbitmap_info *bi, i64 pos, i64 *bytes_used);
613 i64 fmtutil_hlp_get_cus_p(dbuf *f, i64 *ppos);
614 i64 fmtutil_hlp_get_css_p(dbuf *f, i64 *ppos);
615 i64 fmtutil_hlp_get_cul_p(dbuf *f, i64 *ppos);
616 i64 fmtutil_hlp_get_csl_p(dbuf *f, i64 *ppos);
618 #define FMTUTIL_HUFFMAN_MAX_CODE_LENGTH 48
619 typedef i32 fmtutil_huffman_valtype;
620 struct fmtutil_huffman_codebook;
621 struct fmtutil_huffman_cursor;
622 struct fmtutil_huffman_code_builder;
623 struct fmtutil_huffman_decoder {
624 struct fmtutil_huffman_cursor *cursor;
625 struct fmtutil_huffman_codebook *bk;
626 struct fmtutil_huffman_code_builder *builder;
628 struct fmtutil_huffman_decoder *fmtutil_huffman_create_decoder(deark *c, i64 initial_codes, i64 max_codes);
629 void fmtutil_huffman_destroy_decoder(deark *c, struct fmtutil_huffman_decoder *ht);
630 void fmtutil_huffman_reset_cursor(struct fmtutil_huffman_cursor *cursor);
631 int fmtutil_huffman_add_code(deark *c, struct fmtutil_huffman_codebook *bk,
632 u64 code, UI code_nbits, fmtutil_huffman_valtype val);
633 int fmtutil_huffman_decode_bit(struct fmtutil_huffman_codebook *bk, struct fmtutil_huffman_cursor *cursor,
634 u8 bitval, fmtutil_huffman_valtype *pval);
635 int fmtutil_huffman_read_next_value(struct fmtutil_huffman_codebook *bk,
636 struct de_bitreader *bitrd, fmtutil_huffman_valtype *pval, UI *pnbits);
637 UI fmtutil_huffman_get_max_bits(struct fmtutil_huffman_codebook *bk);
638 i64 fmtutil_huffman_get_num_codes(struct fmtutil_huffman_codebook *bk);
639 void fmtutil_huffman_dump(deark *c, struct fmtutil_huffman_decoder *ht);
640 int fmtutil_huffman_record_a_code_length(deark *c, struct fmtutil_huffman_code_builder *builder,
641 fmtutil_huffman_valtype val, UI len);
642 #define FMTUTIL_MCTFLAG_LEFT_ALIGN_LEAVES 0x0 // default
643 #define FMTUTIL_MCTFLAG_LEFT_ALIGN_BRANCHES 0x1
644 #define FMTUTIL_MCTFLAG_LAST_CODE_FIRST 0x2 // Pretend codes were added in the reverse order
645 int fmtutil_huffman_make_canonical_code(deark *c, struct fmtutil_huffman_codebook *bk,
646 struct fmtutil_huffman_code_builder *builder, UI flags);
648 typedef void (*fmtutil_lz77buffer_cb_type)(struct de_lz77buffer *rb, u8 n);
650 struct de_lz77buffer {
651 void *userdata;
652 fmtutil_lz77buffer_cb_type writebyte_cb;
653 UI curpos; // Must be kept valid at all times (0...bufsize-1)
654 UI mask;
655 UI bufsize; // Required to be a power of 2
656 u8 *buf;
658 struct de_lz77buffer *de_lz77buffer_create(deark *c, UI bufsize);
659 void de_lz77buffer_destroy(deark *c, struct de_lz77buffer *rb);
660 void de_lz77buffer_clear(struct de_lz77buffer *rb, UI val);
661 void de_lz77buffer_set_curpos(struct de_lz77buffer *rb, UI newpos);
662 void de_lz77buffer_add_literal_byte(struct de_lz77buffer *rb, u8 b);
663 void de_lz77buffer_copy_from_hist(struct de_lz77buffer *rb, UI startpos, UI count);