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