1 // This file is part of Deark.
2 // Copyright (C) 2016 Jason Summers
3 // See the file COPYING for terms of use.
7 struct de_dfilter_in_params
{
13 struct de_dfilter_out_params
{
19 struct de_dfilter_results
{
20 // Note: If this struct is changed, also update de_dfilter_results_clear().
22 u8 bytes_consumed_valid
;
28 #define DE_BMPINFO_FMT_BMP 0
29 #define DE_BMPINFO_FMT_PNG 1
32 int hotspot_x
, hotspot_y
;
33 i64 bitsoffset
; // Literal value from FILEHEADER
38 u32 compression_field
;
41 i64 bytes_per_pal_entry
;
43 i64 num_colors
; // For use in ICO/CUR file headers.
50 i64 pal_bytes
; // Size of palette in bytes
51 i64 size_of_headers_and_pal
; // Relative offset to bitmap (bitsoffset might be absolute)
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
,
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
,
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
,
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
{
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
{
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
,
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
,
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
{
143 struct de_dfilter_results
*dres
;
144 struct de_dfilter_out_params
*dcmpro
;
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
,
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
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
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
{
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
,
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
;
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
,
302 struct de_SAUCE_info
{
306 de_ucstring
*organization
;
307 struct de_timestamp creation_date
;
308 i64 original_file_size
;
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
,
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
);
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
);
332 // Per-box info supplied to handle_box_fn:
333 struct de_boxdata
*parent
;
337 u8 uuid
[16]; // Valid only if is_uuid is set.
340 // Note: for UUID boxes, payload does not include the UUID
344 // To be filled in by identify_box_fn:
346 const char *box_name
;
348 // To be filled in by handle_box_fn:
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)
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
{
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
,
389 void fmtutil_atari_help_palbits(deark
*c
);
391 // The IFF parser supports IFF and similar formats, including RIFF.
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
,
421 struct de_iffchunkctx
{
422 struct de_fourcc chunk4cc
;
428 // To be filled in by identify_chunk_fn:
429 void *chunk_userdata
;
430 const char *chunk_name
;
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
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:
462 int is_std_container
;
463 int is_raw_container
;
466 void fmtutil_read_iff_format(deark
*c
, struct de_iffctx
*ictx
,
468 int fmtutil_is_standard_iff_chunk(deark
*c
, struct de_iffctx
*ictx
,
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
);
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
,
487 struct de_advfile_cbparams
{
488 #define DE_ADVFILE_WRITEMAIN 1
489 #define DE_ADVFILE_WRITERSRC 2
494 typedef int (*de_advfile_cbfn
)(deark
*c
, struct de_advfile
*advf
,
495 struct de_advfile_cbparams
*afp
);
497 struct de_advfile_forkinfo
{
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
;
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
;
521 size_t orig_filename_len
;
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
{
543 u32 load_addr
, exec_addr
;
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
;
563 i64 pixeltype
, pixelsize
;
564 i64 cmpcount
, cmpsize
;
568 int has_colortable
; // Does the file contain a colortable for this bitmap?
569 int uses_pal
; // Are we using the palette below?
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
{
622 fmtutil_lz77buffer_cb_type writebyte_cb
;
623 UI curpos
; // Must be kept valid at all times (0...bufsize-1)
625 UI bufsize
; // Required to be a power of 2
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
);