1 | /* |
2 | * reserved comment block |
3 | * DO NOT REMOVE OR ALTER! |
4 | */ |
5 | /* |
6 | * jpegint.h |
7 | * |
8 | * Copyright (C) 1991-1997, 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. |
11 | * |
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. |
15 | */ |
16 | |
17 | |
18 | /* Declarations for both compression & decompression */ |
19 | |
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 */ |
26 | } J_BUF_MODE; |
27 | |
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 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 */ |
44 | |
45 | |
46 | /* Declarations for compression modules */ |
47 | |
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)); |
53 | |
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 */ |
57 | }; |
58 | |
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)); |
65 | }; |
66 | |
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, |
71 | JSAMPARRAY input_buf, |
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)); |
77 | }; |
78 | |
79 | /* Coefficient buffer control */ |
80 | struct jpeg_c_coef_controller { |
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)); |
84 | }; |
85 | |
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)); |
92 | }; |
93 | |
94 | /* Downsampling */ |
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)); |
101 | |
102 | boolean need_context_rows; /* TRUE if need rows above & below */ |
103 | }; |
104 | |
105 | /* Forward DCT (also controls coefficient quantization) */ |
106 | struct jpeg_forward_dct { |
107 | JMETHOD(void, start_pass, (j_compress_ptr cinfo)); |
108 | /* perhaps this should be an array??? */ |
109 | JMETHOD(void, forward_DCT, (j_compress_ptr cinfo, |
110 | jpeg_component_info * compptr, |
111 | JSAMPARRAY sample_data, JBLOCKROW coef_blocks, |
112 | JDIMENSION start_row, JDIMENSION start_col, |
113 | JDIMENSION num_blocks)); |
114 | }; |
115 | |
116 | /* Entropy encoding */ |
117 | struct jpeg_entropy_encoder { |
118 | JMETHOD(void, start_pass, (j_compress_ptr cinfo, boolean gather_statistics)); |
119 | JMETHOD(boolean, encode_mcu, (j_compress_ptr cinfo, JBLOCKROW *MCU_data)); |
120 | JMETHOD(void, finish_pass, (j_compress_ptr cinfo)); |
121 | }; |
122 | |
123 | /* Marker writing */ |
124 | struct jpeg_marker_writer { |
125 | JMETHOD(void, , (j_compress_ptr cinfo)); |
126 | JMETHOD(void, , (j_compress_ptr cinfo)); |
127 | JMETHOD(void, , (j_compress_ptr cinfo)); |
128 | JMETHOD(void, write_file_trailer, (j_compress_ptr cinfo)); |
129 | JMETHOD(void, write_tables_only, (j_compress_ptr cinfo)); |
130 | /* These routines are exported to allow insertion of extra markers */ |
131 | /* Probably only COM and APPn markers should be written this way */ |
132 | JMETHOD(void, , (j_compress_ptr cinfo, int marker, |
133 | unsigned int datalen)); |
134 | JMETHOD(void, write_marker_byte, (j_compress_ptr cinfo, int val)); |
135 | }; |
136 | |
137 | |
138 | /* Declarations for decompression modules */ |
139 | |
140 | /* Master control module */ |
141 | struct jpeg_decomp_master { |
142 | JMETHOD(void, prepare_for_output_pass, (j_decompress_ptr cinfo)); |
143 | JMETHOD(void, finish_output_pass, (j_decompress_ptr cinfo)); |
144 | |
145 | /* State variables made visible to other modules */ |
146 | boolean is_dummy_pass; /* True during 1st pass for 2-pass quant */ |
147 | }; |
148 | |
149 | /* Input control module */ |
150 | struct jpeg_input_controller { |
151 | JMETHOD(int, consume_input, (j_decompress_ptr cinfo)); |
152 | JMETHOD(void, reset_input_controller, (j_decompress_ptr cinfo)); |
153 | JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo)); |
154 | JMETHOD(void, finish_input_pass, (j_decompress_ptr cinfo)); |
155 | |
156 | /* State variables made visible to other modules */ |
157 | boolean has_multiple_scans; /* True if file has multiple scans */ |
158 | boolean eoi_reached; /* True when EOI has been consumed */ |
159 | }; |
160 | |
161 | /* Main buffer control (downsampled-data buffer) */ |
162 | struct jpeg_d_main_controller { |
163 | JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)); |
164 | JMETHOD(void, process_data, (j_decompress_ptr cinfo, |
165 | JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, |
166 | JDIMENSION out_rows_avail)); |
167 | }; |
168 | |
169 | /* Coefficient buffer control */ |
170 | struct jpeg_d_coef_controller { |
171 | JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo)); |
172 | JMETHOD(int, consume_data, (j_decompress_ptr cinfo)); |
173 | JMETHOD(void, start_output_pass, (j_decompress_ptr cinfo)); |
174 | JMETHOD(int, decompress_data, (j_decompress_ptr cinfo, |
175 | JSAMPIMAGE output_buf)); |
176 | /* Pointer to array of coefficient virtual arrays, or NULL if none */ |
177 | jvirt_barray_ptr *coef_arrays; |
178 | }; |
179 | |
180 | /* Decompression postprocessing (color quantization buffer control) */ |
181 | struct jpeg_d_post_controller { |
182 | JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)); |
183 | JMETHOD(void, post_process_data, (j_decompress_ptr cinfo, |
184 | JSAMPIMAGE input_buf, |
185 | JDIMENSION *in_row_group_ctr, |
186 | JDIMENSION in_row_groups_avail, |
187 | JSAMPARRAY output_buf, |
188 | JDIMENSION *out_row_ctr, |
189 | JDIMENSION out_rows_avail)); |
190 | }; |
191 | |
192 | /* Marker reading & parsing */ |
193 | struct jpeg_marker_reader { |
194 | JMETHOD(void, reset_marker_reader, (j_decompress_ptr cinfo)); |
195 | /* Read markers until SOS or EOI. |
196 | * Returns same codes as are defined for jpeg_consume_input: |
197 | * JPEG_SUSPENDED, JPEG_REACHED_SOS, or JPEG_REACHED_EOI. |
198 | */ |
199 | JMETHOD(int, read_markers, (j_decompress_ptr cinfo)); |
200 | /* Read a restart marker --- exported for use by entropy decoder only */ |
201 | jpeg_marker_parser_method read_restart_marker; |
202 | |
203 | /* State of marker reader --- nominally internal, but applications |
204 | * supplying COM or APPn handlers might like to know the state. |
205 | */ |
206 | boolean saw_SOI; /* found SOI? */ |
207 | boolean saw_SOF; /* found SOF? */ |
208 | int next_restart_num; /* next restart number expected (0-7) */ |
209 | unsigned int discarded_bytes; /* # of bytes skipped looking for a marker */ |
210 | }; |
211 | |
212 | /* Entropy decoding */ |
213 | struct jpeg_entropy_decoder { |
214 | JMETHOD(void, start_pass, (j_decompress_ptr cinfo)); |
215 | JMETHOD(boolean, decode_mcu, (j_decompress_ptr cinfo, |
216 | JBLOCKROW *MCU_data)); |
217 | |
218 | /* This is here to share code between baseline and progressive decoders; */ |
219 | /* other modules probably should not use it */ |
220 | boolean insufficient_data; /* set TRUE after emitting warning */ |
221 | }; |
222 | |
223 | /* Inverse DCT (also performs dequantization) */ |
224 | typedef JMETHOD(void, inverse_DCT_method_ptr, |
225 | (j_decompress_ptr cinfo, jpeg_component_info * compptr, |
226 | JCOEFPTR coef_block, |
227 | JSAMPARRAY output_buf, JDIMENSION output_col)); |
228 | |
229 | struct jpeg_inverse_dct { |
230 | JMETHOD(void, start_pass, (j_decompress_ptr cinfo)); |
231 | /* It is useful to allow each component to have a separate IDCT method. */ |
232 | inverse_DCT_method_ptr inverse_DCT[MAX_COMPONENTS]; |
233 | }; |
234 | |
235 | /* Upsampling (note that upsampler must also call color converter) */ |
236 | struct jpeg_upsampler { |
237 | JMETHOD(void, start_pass, (j_decompress_ptr cinfo)); |
238 | JMETHOD(void, upsample, (j_decompress_ptr cinfo, |
239 | JSAMPIMAGE input_buf, |
240 | JDIMENSION *in_row_group_ctr, |
241 | JDIMENSION in_row_groups_avail, |
242 | JSAMPARRAY output_buf, |
243 | JDIMENSION *out_row_ctr, |
244 | JDIMENSION out_rows_avail)); |
245 | |
246 | boolean need_context_rows; /* TRUE if need rows above & below */ |
247 | }; |
248 | |
249 | /* Colorspace conversion */ |
250 | struct jpeg_color_deconverter { |
251 | JMETHOD(void, start_pass, (j_decompress_ptr cinfo)); |
252 | JMETHOD(void, color_convert, (j_decompress_ptr cinfo, |
253 | JSAMPIMAGE input_buf, JDIMENSION input_row, |
254 | JSAMPARRAY output_buf, int num_rows)); |
255 | }; |
256 | |
257 | /* Color quantization or color precision reduction */ |
258 | struct jpeg_color_quantizer { |
259 | JMETHOD(void, start_pass, (j_decompress_ptr cinfo, boolean is_pre_scan)); |
260 | JMETHOD(void, color_quantize, (j_decompress_ptr cinfo, |
261 | JSAMPARRAY input_buf, JSAMPARRAY output_buf, |
262 | int num_rows)); |
263 | JMETHOD(void, finish_pass, (j_decompress_ptr cinfo)); |
264 | JMETHOD(void, new_color_map, (j_decompress_ptr cinfo)); |
265 | }; |
266 | |
267 | |
268 | /* Miscellaneous useful macros */ |
269 | |
270 | #undef MAX |
271 | #define MAX(a,b) ((a) > (b) ? (a) : (b)) |
272 | #undef MIN |
273 | #define MIN(a,b) ((a) < (b) ? (a) : (b)) |
274 | |
275 | |
276 | /* We assume that right shift corresponds to signed division by 2 with |
277 | * rounding towards minus infinity. This is correct for typical "arithmetic |
278 | * shift" instructions that shift in copies of the sign bit. But some |
279 | * C compilers implement >> with an unsigned shift. For these machines you |
280 | * must define RIGHT_SHIFT_IS_UNSIGNED. |
281 | * RIGHT_SHIFT provides a proper signed right shift of an INT32 quantity. |
282 | * It is only applied with constant shift counts. SHIFT_TEMPS must be |
283 | * included in the variables of any routine using RIGHT_SHIFT. |
284 | */ |
285 | |
286 | #ifdef RIGHT_SHIFT_IS_UNSIGNED |
287 | #define SHIFT_TEMPS INT32 shift_temp; |
288 | #define RIGHT_SHIFT(x,shft) \ |
289 | ((shift_temp = (x)) < 0 ? \ |
290 | (shift_temp >> (shft)) | ((~((INT32) 0)) << (32-(shft))) : \ |
291 | (shift_temp >> (shft))) |
292 | #else |
293 | #define SHIFT_TEMPS |
294 | #define RIGHT_SHIFT(x,shft) ((x) >> (shft)) |
295 | #endif |
296 | |
297 | |
298 | /* Short forms of external names for systems with brain-damaged linkers. */ |
299 | |
300 | #ifdef NEED_SHORT_EXTERNAL_NAMES |
301 | #define jinit_compress_master jICompress |
302 | #define jinit_c_master_control jICMaster |
303 | #define jinit_c_main_controller jICMainC |
304 | #define jinit_c_prep_controller jICPrepC |
305 | #define jinit_c_coef_controller jICCoefC |
306 | #define jinit_color_converter jICColor |
307 | #define jinit_downsampler jIDownsampler |
308 | #define jinit_forward_dct jIFDCT |
309 | #define jinit_huff_encoder jIHEncoder |
310 | #define jinit_phuff_encoder jIPHEncoder |
311 | #define jinit_marker_writer jIMWriter |
312 | #define jinit_master_decompress jIDMaster |
313 | #define jinit_d_main_controller jIDMainC |
314 | #define jinit_d_coef_controller jIDCoefC |
315 | #define jinit_d_post_controller jIDPostC |
316 | #define jinit_input_controller jIInCtlr |
317 | #define jinit_marker_reader jIMReader |
318 | #define jinit_huff_decoder jIHDecoder |
319 | #define jinit_phuff_decoder jIPHDecoder |
320 | #define jinit_inverse_dct jIIDCT |
321 | #define jinit_upsampler jIUpsampler |
322 | #define jinit_color_deconverter jIDColor |
323 | #define jinit_1pass_quantizer jI1Quant |
324 | #define jinit_2pass_quantizer jI2Quant |
325 | #define jinit_merged_upsampler jIMUpsampler |
326 | #define jinit_memory_mgr jIMemMgr |
327 | #define jdiv_round_up jDivRound |
328 | #define jround_up jRound |
329 | #define jcopy_sample_rows jCopySamples |
330 | #define jcopy_block_row jCopyBlocks |
331 | #define jzero_far jZeroFar |
332 | #define jpeg_zigzag_order jZIGTable |
333 | #define jpeg_natural_order jZAGTable |
334 | #endif /* NEED_SHORT_EXTERNAL_NAMES */ |
335 | |
336 | |
337 | /* Compression module initialization routines */ |
338 | EXTERN(void) jinit_compress_master JPP((j_compress_ptr cinfo)); |
339 | EXTERN(void) jinit_c_master_control JPP((j_compress_ptr cinfo, |
340 | boolean transcode_only)); |
341 | EXTERN(void) jinit_c_main_controller JPP((j_compress_ptr cinfo, |
342 | boolean need_full_buffer)); |
343 | EXTERN(void) jinit_c_prep_controller JPP((j_compress_ptr cinfo, |
344 | boolean need_full_buffer)); |
345 | EXTERN(void) jinit_c_coef_controller JPP((j_compress_ptr cinfo, |
346 | boolean need_full_buffer)); |
347 | EXTERN(void) jinit_color_converter JPP((j_compress_ptr cinfo)); |
348 | EXTERN(void) jinit_downsampler JPP((j_compress_ptr cinfo)); |
349 | EXTERN(void) jinit_forward_dct JPP((j_compress_ptr cinfo)); |
350 | EXTERN(void) jinit_huff_encoder JPP((j_compress_ptr cinfo)); |
351 | EXTERN(void) jinit_phuff_encoder JPP((j_compress_ptr cinfo)); |
352 | EXTERN(void) jinit_marker_writer JPP((j_compress_ptr cinfo)); |
353 | /* Decompression module initialization routines */ |
354 | EXTERN(void) jinit_master_decompress JPP((j_decompress_ptr cinfo)); |
355 | EXTERN(void) jinit_d_main_controller JPP((j_decompress_ptr cinfo, |
356 | boolean need_full_buffer)); |
357 | EXTERN(void) jinit_d_coef_controller JPP((j_decompress_ptr cinfo, |
358 | boolean need_full_buffer)); |
359 | EXTERN(void) jinit_d_post_controller JPP((j_decompress_ptr cinfo, |
360 | boolean need_full_buffer)); |
361 | EXTERN(void) jinit_input_controller JPP((j_decompress_ptr cinfo)); |
362 | EXTERN(void) jinit_marker_reader JPP((j_decompress_ptr cinfo)); |
363 | EXTERN(void) jinit_huff_decoder JPP((j_decompress_ptr cinfo)); |
364 | EXTERN(void) jinit_phuff_decoder JPP((j_decompress_ptr cinfo)); |
365 | EXTERN(void) jinit_inverse_dct JPP((j_decompress_ptr cinfo)); |
366 | EXTERN(void) jinit_upsampler JPP((j_decompress_ptr cinfo)); |
367 | EXTERN(void) jinit_color_deconverter JPP((j_decompress_ptr cinfo)); |
368 | EXTERN(void) jinit_1pass_quantizer JPP((j_decompress_ptr cinfo)); |
369 | EXTERN(void) jinit_2pass_quantizer JPP((j_decompress_ptr cinfo)); |
370 | EXTERN(void) jinit_merged_upsampler JPP((j_decompress_ptr cinfo)); |
371 | /* Memory manager initialization */ |
372 | EXTERN(void) jinit_memory_mgr JPP((j_common_ptr cinfo)); |
373 | |
374 | /* Utility routines in jutils.c */ |
375 | EXTERN(long) jdiv_round_up JPP((long a, long b)); |
376 | EXTERN(long) jround_up JPP((long a, long b)); |
377 | EXTERN(void) jcopy_sample_rows JPP((JSAMPARRAY input_array, int source_row, |
378 | JSAMPARRAY output_array, int dest_row, |
379 | int num_rows, JDIMENSION num_cols)); |
380 | EXTERN(void) jcopy_block_row JPP((JBLOCKROW input_row, JBLOCKROW output_row, |
381 | JDIMENSION num_blocks)); |
382 | EXTERN(void) jzero_far JPP((void FAR * target, size_t bytestozero)); |
383 | /* Constant tables in jutils.c */ |
384 | #if 0 /* This table is not actually needed in v6a */ |
385 | extern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */ |
386 | #endif |
387 | extern const int jpeg_natural_order[]; /* zigzag coef order to natural order */ |
388 | |
389 | /* Suppress undefined-structure complaints if necessary. */ |
390 | |
391 | #ifdef INCOMPLETE_TYPES_BROKEN |
392 | #ifndef AM_MEMORY_MANAGER /* only jmemmgr.c defines these */ |
393 | struct jvirt_sarray_control { long dummy; }; |
394 | struct jvirt_barray_control { long dummy; }; |
395 | #endif |
396 | #endif /* INCOMPLETE_TYPES_BROKEN */ |
397 | |