4 * Copyright (C) 1991-1998, Thomas G. Lane.
5 * This file is part of the Independent JPEG Group's software.
6 * For conditions of distribution and use, see the accompanying README file.
8 * This file provides common declarations for the various JPEG modules.
9 * These declarations are considered internal to the JPEG library; most
10 * applications using the library shouldn't need to include this file.
14 /* Declarations for both compression & decompression */
16 typedef enum { /* Operating modes for buffer controllers */
17 JBUF_PASS_THRU, /* Plain stripwise operation */
18 /* Remaining modes require a full-image buffer to have been created */
19 JBUF_SAVE_SOURCE, /* Run source subobject only, save output */
20 JBUF_CRANK_DEST, /* Run dest subobject only, using saved data */
21 JBUF_SAVE_AND_PASS /* Run both subobjects, save output */
24 /* Values of global_state field (jdapi.c has some dependencies on ordering!) */
25 #define CSTATE_START 100 /* after create_compress */
26 #define CSTATE_SCANNING 101 /* start_compress done, write_scanlines OK */
27 #define CSTATE_RAW_OK 102 /* start_compress done, write_raw_data OK */
28 #define CSTATE_WRCOEFS 103 /* jpeg_write_coefficients done */
29 #define DSTATE_START 200 /* after create_decompress */
30 #define DSTATE_INHEADER 201 /* reading header markers, no SOS yet */
31 #define DSTATE_READY 202 /* found SOS, ready for start_decompress */
32 #define DSTATE_PRELOAD 203 /* reading multiscan file in start_decompress*/
33 #define DSTATE_PRESCAN 204 /* performing dummy pass for 2-pass quant */
34 #define DSTATE_SCANNING 205 /* start_decompress done, read_scanlines OK */
35 #define DSTATE_RAW_OK 206 /* start_decompress done, read_raw_data OK */
36 #define DSTATE_BUFIMAGE 207 /* expecting jpeg_start_output */
37 #define DSTATE_BUFPOST 208 /* looking for SOS/EOI in jpeg_finish_output */
38 #define DSTATE_RDCOEFS 209 /* reading file in jpeg_read_coefficients */
39 #define DSTATE_STOPPING 210 /* looking for EOI in jpeg_finish_decompress */
42 /* Declarations for compression modules */
44 /* Master control module */
45 struct jpeg_comp_master {
46 JMETHOD(void, prepare_for_pass, (j_compress_ptr cinfo));
47 JMETHOD(void, pass_startup, (j_compress_ptr cinfo));
48 JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
50 /* State variables made visible to other modules */
51 boolean call_pass_startup; /* True if pass_startup must be called */
52 boolean is_last_pass; /* True during last pass */
55 /* Main buffer control (downsampled-data buffer) */
56 struct jpeg_c_main_controller {
57 JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
58 JMETHOD(void, process_data, (j_compress_ptr cinfo,
59 JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
60 JDIMENSION in_rows_avail));
63 /* Compression preprocessing (downsampling input buffer control) */
64 struct jpeg_c_prep_controller {
65 JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
66 JMETHOD(void, pre_process_data, (j_compress_ptr cinfo,
68 JDIMENSION *in_row_ctr,
69 JDIMENSION in_rows_avail,
70 JSAMPIMAGE output_buf,
71 JDIMENSION *out_row_group_ctr,
72 JDIMENSION out_row_groups_avail));
75 /* Compression codec (compressor proper) */
77 JMETHOD(void, entropy_start_pass, (j_compress_ptr cinfo,
78 boolean gather_statistics));
79 JMETHOD(void, entropy_finish_pass, (j_compress_ptr cinfo));
80 JMETHOD(boolean, need_optimization_pass, (j_compress_ptr cinfo));
81 JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
82 JMETHOD(boolean, compress_data, (j_compress_ptr cinfo,
83 JSAMPIMAGE input_buf));
86 /* Colorspace conversion */
87 struct jpeg_color_converter {
88 JMETHOD(void, start_pass, (j_compress_ptr cinfo));
89 JMETHOD(void, color_convert, (j_compress_ptr cinfo,
90 JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
91 JDIMENSION output_row, int num_rows));
95 struct jpeg_downsampler {
96 JMETHOD(void, start_pass, (j_compress_ptr cinfo));
97 JMETHOD(void, downsample, (j_compress_ptr cinfo,
98 JSAMPIMAGE input_buf, JDIMENSION in_row_index,
99 JSAMPIMAGE output_buf,
100 JDIMENSION out_row_group_index));
102 boolean need_context_rows; /* TRUE if need rows above & below */
106 struct jpeg_marker_writer {
107 JMETHOD(void, write_file_header, (j_compress_ptr cinfo));
108 JMETHOD(void, write_frame_header, (j_compress_ptr cinfo));
109 JMETHOD(void, write_scan_header, (j_compress_ptr cinfo));
110 JMETHOD(void, write_file_trailer, (j_compress_ptr cinfo));
111 JMETHOD(void, write_tables_only, (j_compress_ptr cinfo));
112 /* These routines are exported to allow insertion of extra markers */
113 /* Probably only COM and APPn markers should be written this way */
114 JMETHOD(void, write_marker_header, (j_compress_ptr cinfo, int marker,
115 unsigned int datalen));
116 JMETHOD(void, write_marker_byte, (j_compress_ptr cinfo, int val));
120 /* Declarations for decompression modules */
122 /* Master control module */
123 struct jpeg_decomp_master {
124 JMETHOD(void, prepare_for_output_pass, (j_decompress_ptr cinfo));
125 JMETHOD(void, finish_output_pass, (j_decompress_ptr cinfo));
127 /* State variables made visible to other modules */
128 boolean is_dummy_pass; /* True during 1st pass for 2-pass quant */
131 /* Input control module */
132 struct jpeg_input_controller {
133 JMETHOD(int, consume_input, (j_decompress_ptr cinfo));
134 JMETHOD(void, reset_input_controller, (j_decompress_ptr cinfo));
135 JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
136 JMETHOD(void, finish_input_pass, (j_decompress_ptr cinfo));
138 /* State variables made visible to other modules */
139 boolean has_multiple_scans; /* True if file has multiple scans */
140 boolean eoi_reached; /* True when EOI has been consumed */
143 /* Main buffer control (downsampled-data buffer) */
144 struct jpeg_d_main_controller {
145 JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
146 JMETHOD(void, process_data, (j_decompress_ptr cinfo,
147 JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
148 JDIMENSION out_rows_avail));
151 /* Decompression codec (decompressor proper) */
152 struct jpeg_d_codec {
153 JMETHOD(void, calc_output_dimensions, (j_decompress_ptr cinfo));
154 JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
155 JMETHOD(int, consume_data, (j_decompress_ptr cinfo));
156 JMETHOD(void, start_output_pass, (j_decompress_ptr cinfo));
157 JMETHOD(int, decompress_data, (j_decompress_ptr cinfo,
158 JSAMPIMAGE output_buf));
161 /* Decompression postprocessing (color quantization buffer control) */
162 struct jpeg_d_post_controller {
163 JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
164 JMETHOD(void, post_process_data, (j_decompress_ptr cinfo,
165 JSAMPIMAGE input_buf,
166 JDIMENSION *in_row_group_ctr,
167 JDIMENSION in_row_groups_avail,
168 JSAMPARRAY output_buf,
169 JDIMENSION *out_row_ctr,
170 JDIMENSION out_rows_avail));
173 /* Marker reading & parsing */
174 struct jpeg_marker_reader {
175 JMETHOD(void, reset_marker_reader, (j_decompress_ptr cinfo));
176 /* Read markers until SOS or EOI.
177 * Returns same codes as are defined for jpeg_consume_input:
178 * JPEG_SUSPENDED, JPEG_REACHED_SOS, or JPEG_REACHED_EOI.
180 JMETHOD(int, read_markers, (j_decompress_ptr cinfo));
181 /* Read a restart marker --- exported for use by entropy decoder only */
182 jpeg_marker_parser_method read_restart_marker;
184 /* State of marker reader --- nominally internal, but applications
185 * supplying COM or APPn handlers might like to know the state.
187 boolean saw_SOI; /* found SOI? */
188 boolean saw_SOF; /* found SOF? */
189 int next_restart_num; /* next restart number expected (0-7) */
190 unsigned int discarded_bytes; /* # of bytes skipped looking for a marker */
193 /* Upsampling (note that upsampler must also call color converter) */
194 struct jpeg_upsampler {
195 JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
196 JMETHOD(void, upsample, (j_decompress_ptr cinfo,
197 JSAMPIMAGE input_buf,
198 JDIMENSION *in_row_group_ctr,
199 JDIMENSION in_row_groups_avail,
200 JSAMPARRAY output_buf,
201 JDIMENSION *out_row_ctr,
202 JDIMENSION out_rows_avail));
204 boolean need_context_rows; /* TRUE if need rows above & below */
207 /* Colorspace conversion */
208 struct jpeg_color_deconverter {
209 JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
210 JMETHOD(void, color_convert, (j_decompress_ptr cinfo,
211 JSAMPIMAGE input_buf, JDIMENSION input_row,
212 JSAMPARRAY output_buf, int num_rows));
215 /* Color quantization or color precision reduction */
216 struct jpeg_color_quantizer {
217 JMETHOD(void, start_pass, (j_decompress_ptr cinfo, boolean is_pre_scan));
218 JMETHOD(void, color_quantize, (j_decompress_ptr cinfo,
219 JSAMPARRAY input_buf, JSAMPARRAY output_buf,
221 JMETHOD(void, finish_pass, (j_decompress_ptr cinfo));
222 JMETHOD(void, new_color_map, (j_decompress_ptr cinfo));
226 /* Miscellaneous useful macros */
229 #define MAX(a,b) ((a) > (b) ? (a) : (b))
231 #define MIN(a,b) ((a) < (b) ? (a) : (b))
234 /* We assume that right shift corresponds to signed division by 2 with
235 * rounding towards minus infinity. This is correct for typical "arithmetic
236 * shift" instructions that shift in copies of the sign bit. But some
237 * C compilers implement >> with an unsigned shift. For these machines you
238 * must define RIGHT_SHIFT_IS_UNSIGNED.
239 * RIGHT_SHIFT provides a proper signed right shift of an INT32 quantity.
240 * It is only applied with constant shift counts. SHIFT_TEMPS must be
241 * included in the variables of any routine using RIGHT_SHIFT.
244 #ifdef RIGHT_SHIFT_IS_UNSIGNED
245 #define SHIFT_TEMPS INT32 shift_temp;
246 #define RIGHT_SHIFT(x,shft) \
247 ((shift_temp = (x)) < 0 ? \
248 (shift_temp >> (shft)) | ((~((INT32) 0)) << (32-(shft))) : \
249 (shift_temp >> (shft)))
252 #define RIGHT_SHIFT(x,shft) ((x) >> (shft))
256 /* Short forms of external names for systems with brain-damaged linkers. */
258 #ifdef NEED_SHORT_EXTERNAL_NAMES
259 #define jinit_c_codec jICCodec
260 #define jinit_c_diff_controller jICDiffC
261 #define jinit_lossy_c_codec jILossyC
262 #define jinit_lossless_c_codec jILosslessC
263 #define jinit_compress_master jICompress
264 #define jinit_c_master_control jICMaster
265 #define jinit_c_main_controller jICMainC
266 #define jinit_c_prep_controller jICPrepC
267 #define jinit_c_coef_controller jICCoefC
268 #define jinit_color_converter jICColor
269 #define jinit_downsampler jIDownsampler
270 #define jinit_forward_dct jIFDCT
271 #define jinit_shuff_encoder jISHEncoder
272 #define jinit_phuff_encoder jIPHEncoder
273 #define jinit_arith_encoder jIAEncoder
274 #define jinit_marker_writer jIMWriter
275 #define jinit_d_codec jIDCodec
276 #define jinit_lossy_d_codec jILossyD
277 #define jinit_lossless_d_codec jILosslsD
278 #define jinit_master_decompress jIDMaster
279 #define jinit_d_main_controller jIDMainC
280 #define jinit_d_coef_controller jIDCoefC
281 #define jinit_d_diff_controller jIDDiffC
282 #define jinit_d_post_controller jIDPostC
283 #define jinit_input_controller jIInCtlr
284 #define jinit_marker_reader jIMReader
285 #define jinit_shuff_decoder jISHDecoder
286 #define jinit_phuff_decoder jIPHDecoder
287 #define jinit_arith_decoder jIADecoder
288 #define jinit_lhuff_decoder jILHDecoder
289 #define jinit_undifferencer jIUndiff
290 #define jinit_d_scaler jIDScaler
291 #define jinit_inverse_dct jIIDCT
292 #define jinit_upsampler jIUpsampler
293 #define jinit_color_deconverter jIDColor
294 #define jinit_1pass_quantizer jI1Quant
295 #define jinit_2pass_quantizer jI2Quant
296 #define jinit_merged_upsampler jIMUpsampler
297 #define jinit_memory_mgr jIMemMgr
298 #define jdiv_round_up jDivRound
299 #define jround_up jRound
300 #define jcopy_sample_rows jCopySamples
301 #define jcopy_block_row jCopyBlocks
302 #define jzero_far jZeroFar
303 #define jpeg_zigzag_order jZIGTable
304 #define jpeg_natural_order jZAGTable
305 #endif /* NEED_SHORT_EXTERNAL_NAMES */
308 /* Compression module initialization routines */
309 EXTERN(void) jinit_c_codec JPP((j_compress_ptr cinfo));
310 EXTERN(void) jinit_c_diff_controller JPP((j_compress_ptr cinfo, boolean need_full_buffer));
311 EXTERN(void) jinit_compress_master JPP((j_compress_ptr cinfo));
312 EXTERN(void) jinit_c_master_control JPP((j_compress_ptr cinfo,
313 boolean transcode_only));
314 EXTERN(void) jinit_c_main_controller JPP((j_compress_ptr cinfo,
315 boolean need_full_buffer));
316 EXTERN(void) jinit_c_prep_controller JPP((j_compress_ptr cinfo,
317 boolean need_full_buffer));
318 EXTERN(void) jinit_compressor JPP((j_compress_ptr cinfo));
319 EXTERN(void) jinit_color_converter JPP((j_compress_ptr cinfo));
320 EXTERN(void) jinit_downsampler JPP((j_compress_ptr cinfo));
321 EXTERN(void) jinit_marker_writer JPP((j_compress_ptr cinfo));
322 EXTERN(void) jinit_arith_encoder JPP((j_compress_ptr cinfo));
323 /* Decompression module initialization routines */
324 EXTERN(void) jinit_d_codec JPP((j_decompress_ptr cinfo));
325 EXTERN(void) jinit_d_diff_controller JPP((j_decompress_ptr cinfo, boolean need_full_buffer));
326 EXTERN(void) jinit_master_decompress JPP((j_decompress_ptr cinfo));
327 EXTERN(void) jinit_d_main_controller JPP((j_decompress_ptr cinfo,
328 boolean need_full_buffer));
329 EXTERN(void) jinit_decompressor JPP((j_decompress_ptr cinfo));
330 EXTERN(void) jinit_d_post_controller JPP((j_decompress_ptr cinfo,
331 boolean need_full_buffer));
332 EXTERN(void) jinit_input_controller JPP((j_decompress_ptr cinfo));
333 EXTERN(void) jinit_marker_reader JPP((j_decompress_ptr cinfo));
334 EXTERN(void) jinit_arith_decoder JPP((j_decompress_ptr cinfo));
335 EXTERN(void) jinit_upsampler JPP((j_decompress_ptr cinfo));
336 EXTERN(void) jinit_color_deconverter JPP((j_decompress_ptr cinfo));
337 EXTERN(void) jinit_1pass_quantizer JPP((j_decompress_ptr cinfo));
338 EXTERN(void) jinit_2pass_quantizer JPP((j_decompress_ptr cinfo));
339 EXTERN(void) jinit_merged_upsampler JPP((j_decompress_ptr cinfo));
340 /* Memory manager initialization */
341 EXTERN(void) jinit_memory_mgr JPP((j_common_ptr cinfo));
343 /* Utility routines in jutils.c */
344 EXTERN(long) jdiv_round_up JPP((long a, long b));
345 EXTERN(long) jround_up JPP((long a, long b));
346 EXTERN(void) jcopy_sample_rows JPP((JSAMPARRAY input_array, int source_row,
347 JSAMPARRAY output_array, int dest_row,
348 int num_rows, JDIMENSION num_cols));
349 EXTERN(void) jcopy_block_row JPP((JBLOCKROW input_row, JBLOCKROW output_row,
350 JDIMENSION num_blocks));
351 EXTERN(void) jzero_far JPP((void FAR * target, size_t bytestozero));
352 /* Constant tables in jutils.c */
353 #if 0 /* This table is not actually needed in v6a */
354 extern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */
356 extern const int jpeg_natural_order[]; /* zigzag coef order to natural order */
358 /* Suppress undefined-structure complaints if necessary. */
360 #ifdef INCOMPLETE_TYPES_BROKEN
361 #ifndef AM_MEMORY_MANAGER /* only jmemmgr.c defines these */
362 struct jvirt_sarray_control { long dummy; };
363 struct jvirt_barray_control { long dummy; };
365 #endif /* INCOMPLETE_TYPES_BROKEN */