File indexing completed on 2025-01-19 03:55:51
0001 /* 0002 * jpegint.h 0003 * 0004 * SPDX-FileCopyrightText: 1991-1997, Thomas G. Lane. 0005 * This file is part of the Independent JPEG Group's software. 0006 * For conditions of distribution and use, see the accompanying README file. 0007 * 0008 * This file provides common declarations for the various JPEG modules. 0009 * These declarations are considered internal to the JPEG library; most 0010 * applications using the library shouldn't need to include this file. 0011 */ 0012 0013 0014 /* Declarations for both compression & decompression */ 0015 0016 typedef enum { /* Operating modes for buffer controllers */ 0017 JBUF_PASS_THRU, /* Plain stripwise operation */ 0018 /* Remaining modes require a full-image buffer to have been created */ 0019 JBUF_SAVE_SOURCE, /* Run source subobject only, save output */ 0020 JBUF_CRANK_DEST, /* Run dest subobject only, using saved data */ 0021 JBUF_SAVE_AND_PASS /* Run both subobjects, save output */ 0022 } J_BUF_MODE; 0023 0024 /* Values of global_state field (jdapi.c has some dependencies on ordering!) */ 0025 #define CSTATE_START 100 /* after create_compress */ 0026 #define CSTATE_SCANNING 101 /* start_compress done, write_scanlines OK */ 0027 #define CSTATE_RAW_OK 102 /* start_compress done, write_raw_data OK */ 0028 #define CSTATE_WRCOEFS 103 /* jpeg_write_coefficients done */ 0029 #define DSTATE_START 200 /* after create_decompress */ 0030 #define DSTATE_INHEADER 201 /* reading header markers, no SOS yet */ 0031 #define DSTATE_READY 202 /* found SOS, ready for start_decompress */ 0032 #define DSTATE_PRELOAD 203 /* reading multiscan file in start_decompress*/ 0033 #define DSTATE_PRESCAN 204 /* performing dummy pass for 2-pass quant */ 0034 #define DSTATE_SCANNING 205 /* start_decompress done, read_scanlines OK */ 0035 #define DSTATE_RAW_OK 206 /* start_decompress done, read_raw_data OK */ 0036 #define DSTATE_BUFIMAGE 207 /* expecting jpeg_start_output */ 0037 #define DSTATE_BUFPOST 208 /* looking for SOS/EOI in jpeg_finish_output */ 0038 #define DSTATE_RDCOEFS 209 /* reading file in jpeg_read_coefficients */ 0039 #define DSTATE_STOPPING 210 /* looking for EOI in jpeg_finish_decompress */ 0040 0041 0042 /* Declarations for compression modules */ 0043 0044 /* Master control module */ 0045 struct jpeg_comp_master { 0046 JMETHOD(void, prepare_for_pass, (j_compress_ptr cinfo)); 0047 JMETHOD(void, pass_startup, (j_compress_ptr cinfo)); 0048 JMETHOD(void, finish_pass, (j_compress_ptr cinfo)); 0049 0050 /* State variables made visible to other modules */ 0051 boolean call_pass_startup; /* True if pass_startup must be called */ 0052 boolean is_last_pass; /* True during last pass */ 0053 }; 0054 0055 /* Main buffer control (downsampled-data buffer) */ 0056 struct jpeg_c_main_controller { 0057 JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode)); 0058 JMETHOD(void, process_data, (j_compress_ptr cinfo, 0059 JSAMPARRAY input_buf, JDIMENSION *in_row_ctr, 0060 JDIMENSION in_rows_avail)); 0061 }; 0062 0063 /* Compression preprocessing (downsampling input buffer control) */ 0064 struct jpeg_c_prep_controller { 0065 JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode)); 0066 JMETHOD(void, pre_process_data, (j_compress_ptr cinfo, 0067 JSAMPARRAY input_buf, 0068 JDIMENSION *in_row_ctr, 0069 JDIMENSION in_rows_avail, 0070 JSAMPIMAGE output_buf, 0071 JDIMENSION *out_row_group_ctr, 0072 JDIMENSION out_row_groups_avail)); 0073 }; 0074 0075 /* Coefficient buffer control */ 0076 struct jpeg_c_coef_controller { 0077 JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode)); 0078 JMETHOD(boolean, compress_data, (j_compress_ptr cinfo, 0079 JSAMPIMAGE input_buf)); 0080 }; 0081 0082 /* Colorspace conversion */ 0083 struct jpeg_color_converter { 0084 JMETHOD(void, start_pass, (j_compress_ptr cinfo)); 0085 JMETHOD(void, color_convert, (j_compress_ptr cinfo, 0086 JSAMPARRAY input_buf, JSAMPIMAGE output_buf, 0087 JDIMENSION output_row, int num_rows)); 0088 }; 0089 0090 /* Downsampling */ 0091 struct jpeg_downsampler { 0092 JMETHOD(void, start_pass, (j_compress_ptr cinfo)); 0093 JMETHOD(void, downsample, (j_compress_ptr cinfo, 0094 JSAMPIMAGE input_buf, JDIMENSION in_row_index, 0095 JSAMPIMAGE output_buf, 0096 JDIMENSION out_row_group_index)); 0097 0098 boolean need_context_rows; /* TRUE if need rows above & below */ 0099 }; 0100 0101 /* Forward DCT (also controls coefficient quantization) */ 0102 struct jpeg_forward_dct { 0103 JMETHOD(void, start_pass, (j_compress_ptr cinfo)); 0104 /* perhaps this should be an array??? */ 0105 JMETHOD(void, forward_DCT, (j_compress_ptr cinfo, 0106 jpeg_component_info * compptr, 0107 JSAMPARRAY sample_data, JBLOCKROW coef_blocks, 0108 JDIMENSION start_row, JDIMENSION start_col, 0109 JDIMENSION num_blocks)); 0110 }; 0111 0112 /* Entropy encoding */ 0113 struct jpeg_entropy_encoder { 0114 JMETHOD(void, start_pass, (j_compress_ptr cinfo, boolean gather_statistics)); 0115 JMETHOD(boolean, encode_mcu, (j_compress_ptr cinfo, JBLOCKROW *MCU_data)); 0116 JMETHOD(void, finish_pass, (j_compress_ptr cinfo)); 0117 }; 0118 0119 /* Marker writing */ 0120 struct jpeg_marker_writer { 0121 JMETHOD(void, write_file_header, (j_compress_ptr cinfo)); 0122 JMETHOD(void, write_frame_header, (j_compress_ptr cinfo)); 0123 JMETHOD(void, write_scan_header, (j_compress_ptr cinfo)); 0124 JMETHOD(void, write_file_trailer, (j_compress_ptr cinfo)); 0125 JMETHOD(void, write_tables_only, (j_compress_ptr cinfo)); 0126 /* These routines are exported to allow insertion of extra markers */ 0127 /* Probably only COM and APPn markers should be written this way */ 0128 JMETHOD(void, write_marker_header, (j_compress_ptr cinfo, int marker, 0129 unsigned int datalen)); 0130 JMETHOD(void, write_marker_byte, (j_compress_ptr cinfo, int val)); 0131 }; 0132 0133 0134 /* Declarations for decompression modules */ 0135 0136 /* Master control module */ 0137 struct jpeg_decomp_master { 0138 JMETHOD(void, prepare_for_output_pass, (j_decompress_ptr cinfo)); 0139 JMETHOD(void, finish_output_pass, (j_decompress_ptr cinfo)); 0140 0141 /* State variables made visible to other modules */ 0142 boolean is_dummy_pass; /* True during 1st pass for 2-pass quant */ 0143 }; 0144 0145 /* Input control module */ 0146 struct jpeg_input_controller { 0147 JMETHOD(int, consume_input, (j_decompress_ptr cinfo)); 0148 JMETHOD(void, reset_input_controller, (j_decompress_ptr cinfo)); 0149 JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo)); 0150 JMETHOD(void, finish_input_pass, (j_decompress_ptr cinfo)); 0151 0152 /* State variables made visible to other modules */ 0153 boolean has_multiple_scans; /* True if file has multiple scans */ 0154 boolean eoi_reached; /* True when EOI has been consumed */ 0155 }; 0156 0157 /* Main buffer control (downsampled-data buffer) */ 0158 struct jpeg_d_main_controller { 0159 JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)); 0160 JMETHOD(void, process_data, (j_decompress_ptr cinfo, 0161 JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, 0162 JDIMENSION out_rows_avail)); 0163 }; 0164 0165 /* Coefficient buffer control */ 0166 struct jpeg_d_coef_controller { 0167 JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo)); 0168 JMETHOD(int, consume_data, (j_decompress_ptr cinfo)); 0169 JMETHOD(void, start_output_pass, (j_decompress_ptr cinfo)); 0170 JMETHOD(int, decompress_data, (j_decompress_ptr cinfo, 0171 JSAMPIMAGE output_buf)); 0172 /* Pointer to array of coefficient virtual arrays, or NULL if none */ 0173 jvirt_barray_ptr *coef_arrays; 0174 }; 0175 0176 /* Decompression postprocessing (color quantization buffer control) */ 0177 struct jpeg_d_post_controller { 0178 JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)); 0179 JMETHOD(void, post_process_data, (j_decompress_ptr cinfo, 0180 JSAMPIMAGE input_buf, 0181 JDIMENSION *in_row_group_ctr, 0182 JDIMENSION in_row_groups_avail, 0183 JSAMPARRAY output_buf, 0184 JDIMENSION *out_row_ctr, 0185 JDIMENSION out_rows_avail)); 0186 }; 0187 0188 /* Marker reading & parsing */ 0189 struct jpeg_marker_reader { 0190 JMETHOD(void, reset_marker_reader, (j_decompress_ptr cinfo)); 0191 /* Read markers until SOS or EOI. 0192 * Returns same codes as are defined for jpeg_consume_input: 0193 * JPEG_SUSPENDED, JPEG_REACHED_SOS, or JPEG_REACHED_EOI. 0194 */ 0195 JMETHOD(int, read_markers, (j_decompress_ptr cinfo)); 0196 /* Read a restart marker --- exported for use by entropy decoder only */ 0197 jpeg_marker_parser_method read_restart_marker; 0198 0199 /* State of marker reader --- nominally internal, but applications 0200 * supplying COM or APPn handlers might like to know the state. 0201 */ 0202 boolean saw_SOI; /* found SOI? */ 0203 boolean saw_SOF; /* found SOF? */ 0204 int next_restart_num; /* next restart number expected (0-7) */ 0205 unsigned int discarded_bytes; /* # of bytes skipped looking for a marker */ 0206 }; 0207 0208 /* Entropy decoding */ 0209 struct jpeg_entropy_decoder { 0210 JMETHOD(void, start_pass, (j_decompress_ptr cinfo)); 0211 JMETHOD(boolean, decode_mcu, (j_decompress_ptr cinfo, 0212 JBLOCKROW *MCU_data)); 0213 0214 /* This is here to share code between baseline and progressive decoders; */ 0215 /* other modules probably should not use it */ 0216 boolean insufficient_data; /* set TRUE after emitting warning */ 0217 }; 0218 0219 /* Inverse DCT (also performs dequantization) */ 0220 typedef JMETHOD(void, inverse_DCT_method_ptr, 0221 (j_decompress_ptr cinfo, jpeg_component_info * compptr, 0222 JCOEFPTR coef_block, 0223 JSAMPARRAY output_buf, JDIMENSION output_col)); 0224 0225 struct jpeg_inverse_dct { 0226 JMETHOD(void, start_pass, (j_decompress_ptr cinfo)); 0227 /* It is useful to allow each component to have a separate IDCT method. */ 0228 inverse_DCT_method_ptr inverse_DCT[MAX_COMPONENTS]; 0229 }; 0230 0231 /* Upsampling (note that upsampler must also call color converter) */ 0232 struct jpeg_upsampler { 0233 JMETHOD(void, start_pass, (j_decompress_ptr cinfo)); 0234 JMETHOD(void, upsample, (j_decompress_ptr cinfo, 0235 JSAMPIMAGE input_buf, 0236 JDIMENSION *in_row_group_ctr, 0237 JDIMENSION in_row_groups_avail, 0238 JSAMPARRAY output_buf, 0239 JDIMENSION *out_row_ctr, 0240 JDIMENSION out_rows_avail)); 0241 0242 boolean need_context_rows; /* TRUE if need rows above & below */ 0243 }; 0244 0245 /* Colorspace conversion */ 0246 struct jpeg_color_deconverter { 0247 JMETHOD(void, start_pass, (j_decompress_ptr cinfo)); 0248 JMETHOD(void, color_convert, (j_decompress_ptr cinfo, 0249 JSAMPIMAGE input_buf, JDIMENSION input_row, 0250 JSAMPARRAY output_buf, int num_rows)); 0251 }; 0252 0253 /* Color quantization or color precision reduction */ 0254 struct jpeg_color_quantizer { 0255 JMETHOD(void, start_pass, (j_decompress_ptr cinfo, boolean is_pre_scan)); 0256 JMETHOD(void, color_quantize, (j_decompress_ptr cinfo, 0257 JSAMPARRAY input_buf, JSAMPARRAY output_buf, 0258 int num_rows)); 0259 JMETHOD(void, finish_pass, (j_decompress_ptr cinfo)); 0260 JMETHOD(void, new_color_map, (j_decompress_ptr cinfo)); 0261 }; 0262 0263 0264 /* Miscellaneous useful macros */ 0265 0266 #undef MAX 0267 #define MAX(a,b) ((a) > (b) ? (a) : (b)) 0268 #undef MIN 0269 #define MIN(a,b) ((a) < (b) ? (a) : (b)) 0270 0271 0272 /* We assume that right shift corresponds to signed division by 2 with 0273 * rounding towards minus infinity. This is correct for typical "arithmetic 0274 * shift" instructions that shift in copies of the sign bit. But some 0275 * C compilers implement >> with an unsigned shift. For these machines you 0276 * must define RIGHT_SHIFT_IS_UNSIGNED. 0277 * RIGHT_SHIFT provides a proper signed right shift of an INT32 quantity. 0278 * It is only applied with constant shift counts. SHIFT_TEMPS must be 0279 * included in the variables of any routine using RIGHT_SHIFT. 0280 */ 0281 0282 #ifdef RIGHT_SHIFT_IS_UNSIGNED 0283 #define SHIFT_TEMPS INT32 shift_temp; 0284 #define RIGHT_SHIFT(x,shft) \ 0285 ((shift_temp = (x)) < 0 ? \ 0286 (shift_temp >> (shft)) | ((~((INT32) 0)) << (32-(shft))) : \ 0287 (shift_temp >> (shft))) 0288 #else 0289 #define SHIFT_TEMPS 0290 #define RIGHT_SHIFT(x,shft) ((x) >> (shft)) 0291 #endif 0292 0293 0294 /* Short forms of external names for systems with brain-damaged linkers. */ 0295 0296 #ifdef NEED_SHORT_EXTERNAL_NAMES 0297 #define jinit_compress_master jICompress 0298 #define jinit_c_master_control jICMaster 0299 #define jinit_c_main_controller jICMainC 0300 #define jinit_c_prep_controller jICPrepC 0301 #define jinit_c_coef_controller jICCoefC 0302 #define jinit_color_converter jICColor 0303 #define jinit_downsampler jIDownsampler 0304 #define jinit_forward_dct jIFDCT 0305 #define jinit_huff_encoder jIHEncoder 0306 #define jinit_phuff_encoder jIPHEncoder 0307 #define jinit_marker_writer jIMWriter 0308 #define jinit_master_decompress jIDMaster 0309 #define jinit_d_main_controller jIDMainC 0310 #define jinit_d_coef_controller jIDCoefC 0311 #define jinit_d_post_controller jIDPostC 0312 #define jinit_input_controller jIInCtlr 0313 #define jinit_marker_reader jIMReader 0314 #define jinit_huff_decoder jIHDecoder 0315 #define jinit_phuff_decoder jIPHDecoder 0316 #define jinit_inverse_dct jIIDCT 0317 #define jinit_upsampler jIUpsampler 0318 #define jinit_color_deconverter jIDColor 0319 #define jinit_1pass_quantizer jI1Quant 0320 #define jinit_2pass_quantizer jI2Quant 0321 #define jinit_merged_upsampler jIMUpsampler 0322 #define jinit_memory_mgr jIMemMgr 0323 #define jdiv_round_up jDivRound 0324 #define jround_up jRound 0325 #define jcopy_sample_rows jCopySamples 0326 #define jcopy_block_row jCopyBlocks 0327 #define jzero_far jZeroFar 0328 #define jpeg_zigzag_order jZIGTable 0329 #define jpeg_natural_order jZAGTable 0330 #endif /* NEED_SHORT_EXTERNAL_NAMES */ 0331 0332 0333 /* Compression module initialization routines */ 0334 EXTERN(void) jinit_compress_master JPP((j_compress_ptr cinfo)); 0335 EXTERN(void) jinit_c_master_control JPP((j_compress_ptr cinfo, 0336 boolean transcode_only)); 0337 EXTERN(void) jinit_c_main_controller JPP((j_compress_ptr cinfo, 0338 boolean need_full_buffer)); 0339 EXTERN(void) jinit_c_prep_controller JPP((j_compress_ptr cinfo, 0340 boolean need_full_buffer)); 0341 EXTERN(void) jinit_c_coef_controller JPP((j_compress_ptr cinfo, 0342 boolean need_full_buffer)); 0343 EXTERN(void) jinit_color_converter JPP((j_compress_ptr cinfo)); 0344 EXTERN(void) jinit_downsampler JPP((j_compress_ptr cinfo)); 0345 EXTERN(void) jinit_forward_dct JPP((j_compress_ptr cinfo)); 0346 EXTERN(void) jinit_huff_encoder JPP((j_compress_ptr cinfo)); 0347 EXTERN(void) jinit_phuff_encoder JPP((j_compress_ptr cinfo)); 0348 EXTERN(void) jinit_marker_writer JPP((j_compress_ptr cinfo)); 0349 /* Decompression module initialization routines */ 0350 EXTERN(void) jinit_master_decompress JPP((j_decompress_ptr cinfo)); 0351 EXTERN(void) jinit_d_main_controller JPP((j_decompress_ptr cinfo, 0352 boolean need_full_buffer)); 0353 EXTERN(void) jinit_d_coef_controller JPP((j_decompress_ptr cinfo, 0354 boolean need_full_buffer)); 0355 EXTERN(void) jinit_d_post_controller JPP((j_decompress_ptr cinfo, 0356 boolean need_full_buffer)); 0357 EXTERN(void) jinit_input_controller JPP((j_decompress_ptr cinfo)); 0358 EXTERN(void) jinit_marker_reader JPP((j_decompress_ptr cinfo)); 0359 EXTERN(void) jinit_huff_decoder JPP((j_decompress_ptr cinfo)); 0360 EXTERN(void) jinit_phuff_decoder JPP((j_decompress_ptr cinfo)); 0361 EXTERN(void) jinit_inverse_dct JPP((j_decompress_ptr cinfo)); 0362 EXTERN(void) jinit_upsampler JPP((j_decompress_ptr cinfo)); 0363 EXTERN(void) jinit_color_deconverter JPP((j_decompress_ptr cinfo)); 0364 EXTERN(void) jinit_1pass_quantizer JPP((j_decompress_ptr cinfo)); 0365 EXTERN(void) jinit_2pass_quantizer JPP((j_decompress_ptr cinfo)); 0366 EXTERN(void) jinit_merged_upsampler JPP((j_decompress_ptr cinfo)); 0367 /* Memory manager initialization */ 0368 EXTERN(void) jinit_memory_mgr JPP((j_common_ptr cinfo)); 0369 0370 /* Utility routines in jutils.c */ 0371 EXTERN(long) jdiv_round_up JPP((long a, long b)); 0372 EXTERN(long) jround_up JPP((long a, long b)); 0373 EXTERN(void) jcopy_sample_rows JPP((JSAMPARRAY input_array, int source_row, 0374 JSAMPARRAY output_array, int dest_row, 0375 int num_rows, JDIMENSION num_cols)); 0376 EXTERN(void) jcopy_block_row JPP((JBLOCKROW input_row, JBLOCKROW output_row, 0377 JDIMENSION num_blocks)); 0378 EXTERN(void) jzero_far JPP((void FAR * target, size_t bytestozero)); 0379 /* Constant tables in jutils.c */ 0380 #if 0 /* This table is not actually needed in v6a */ 0381 extern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */ 0382 #endif 0383 extern const int jpeg_natural_order[]; /* zigzag coef order to natural order */ 0384 0385 /* Suppress undefined-structure complaints if necessary. */ 0386 0387 #ifdef INCOMPLETE_TYPES_BROKEN 0388 #ifndef AM_MEMORY_MANAGER /* only jmemmgr.c defines these */ 0389 struct jvirt_sarray_control { long dummy; }; 0390 struct jvirt_barray_control { long dummy; }; 0391 #endif 0392 #endif /* INCOMPLETE_TYPES_BROKEN */