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