nuclear@26: /* nuclear@26: * jpegint.h nuclear@26: * nuclear@26: * Copyright (C) 1991-1997, Thomas G. Lane. nuclear@26: * This file is part of the Independent JPEG Group's software. nuclear@26: * For conditions of distribution and use, see the accompanying README file. nuclear@26: * nuclear@26: * This file provides common declarations for the various JPEG modules. nuclear@26: * These declarations are considered internal to the JPEG library; most nuclear@26: * applications using the library shouldn't need to include this file. nuclear@26: */ nuclear@26: nuclear@26: nuclear@26: /* Declarations for both compression & decompression */ nuclear@26: nuclear@26: typedef enum { /* Operating modes for buffer controllers */ nuclear@26: JBUF_PASS_THRU, /* Plain stripwise operation */ nuclear@26: /* Remaining modes require a full-image buffer to have been created */ nuclear@26: JBUF_SAVE_SOURCE, /* Run source subobject only, save output */ nuclear@26: JBUF_CRANK_DEST, /* Run dest subobject only, using saved data */ nuclear@26: JBUF_SAVE_AND_PASS /* Run both subobjects, save output */ nuclear@26: } J_BUF_MODE; nuclear@26: nuclear@26: /* Values of global_state field (jdapi.c has some dependencies on ordering!) */ nuclear@26: #define CSTATE_START 100 /* after create_compress */ nuclear@26: #define CSTATE_SCANNING 101 /* start_compress done, write_scanlines OK */ nuclear@26: #define CSTATE_RAW_OK 102 /* start_compress done, write_raw_data OK */ nuclear@26: #define CSTATE_WRCOEFS 103 /* jpeg_write_coefficients done */ nuclear@26: #define DSTATE_START 200 /* after create_decompress */ nuclear@26: #define DSTATE_INHEADER 201 /* reading header markers, no SOS yet */ nuclear@26: #define DSTATE_READY 202 /* found SOS, ready for start_decompress */ nuclear@26: #define DSTATE_PRELOAD 203 /* reading multiscan file in start_decompress*/ nuclear@26: #define DSTATE_PRESCAN 204 /* performing dummy pass for 2-pass quant */ nuclear@26: #define DSTATE_SCANNING 205 /* start_decompress done, read_scanlines OK */ nuclear@26: #define DSTATE_RAW_OK 206 /* start_decompress done, read_raw_data OK */ nuclear@26: #define DSTATE_BUFIMAGE 207 /* expecting jpeg_start_output */ nuclear@26: #define DSTATE_BUFPOST 208 /* looking for SOS/EOI in jpeg_finish_output */ nuclear@26: #define DSTATE_RDCOEFS 209 /* reading file in jpeg_read_coefficients */ nuclear@26: #define DSTATE_STOPPING 210 /* looking for EOI in jpeg_finish_decompress */ nuclear@26: nuclear@26: nuclear@26: /* Declarations for compression modules */ nuclear@26: nuclear@26: /* Master control module */ nuclear@26: struct jpeg_comp_master { nuclear@26: JMETHOD(void, prepare_for_pass, (j_compress_ptr cinfo)); nuclear@26: JMETHOD(void, pass_startup, (j_compress_ptr cinfo)); nuclear@26: JMETHOD(void, finish_pass, (j_compress_ptr cinfo)); nuclear@26: nuclear@26: /* State variables made visible to other modules */ nuclear@26: boolean call_pass_startup; /* True if pass_startup must be called */ nuclear@26: boolean is_last_pass; /* True during last pass */ nuclear@26: }; nuclear@26: nuclear@26: /* Main buffer control (downsampled-data buffer) */ nuclear@26: struct jpeg_c_main_controller { nuclear@26: JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode)); nuclear@26: JMETHOD(void, process_data, (j_compress_ptr cinfo, nuclear@26: JSAMPARRAY input_buf, JDIMENSION *in_row_ctr, nuclear@26: JDIMENSION in_rows_avail)); nuclear@26: }; nuclear@26: nuclear@26: /* Compression preprocessing (downsampling input buffer control) */ nuclear@26: struct jpeg_c_prep_controller { nuclear@26: JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode)); nuclear@26: JMETHOD(void, pre_process_data, (j_compress_ptr cinfo, nuclear@26: JSAMPARRAY input_buf, nuclear@26: JDIMENSION *in_row_ctr, nuclear@26: JDIMENSION in_rows_avail, nuclear@26: JSAMPIMAGE output_buf, nuclear@26: JDIMENSION *out_row_group_ctr, nuclear@26: JDIMENSION out_row_groups_avail)); nuclear@26: }; nuclear@26: nuclear@26: /* Coefficient buffer control */ nuclear@26: struct jpeg_c_coef_controller { nuclear@26: JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode)); nuclear@26: JMETHOD(boolean, compress_data, (j_compress_ptr cinfo, nuclear@26: JSAMPIMAGE input_buf)); nuclear@26: }; nuclear@26: nuclear@26: /* Colorspace conversion */ nuclear@26: struct jpeg_color_converter { nuclear@26: JMETHOD(void, start_pass, (j_compress_ptr cinfo)); nuclear@26: JMETHOD(void, color_convert, (j_compress_ptr cinfo, nuclear@26: JSAMPARRAY input_buf, JSAMPIMAGE output_buf, nuclear@26: JDIMENSION output_row, int num_rows)); nuclear@26: }; nuclear@26: nuclear@26: /* Downsampling */ nuclear@26: struct jpeg_downsampler { nuclear@26: JMETHOD(void, start_pass, (j_compress_ptr cinfo)); nuclear@26: JMETHOD(void, downsample, (j_compress_ptr cinfo, nuclear@26: JSAMPIMAGE input_buf, JDIMENSION in_row_index, nuclear@26: JSAMPIMAGE output_buf, nuclear@26: JDIMENSION out_row_group_index)); nuclear@26: nuclear@26: boolean need_context_rows; /* TRUE if need rows above & below */ nuclear@26: }; nuclear@26: nuclear@26: /* Forward DCT (also controls coefficient quantization) */ nuclear@26: struct jpeg_forward_dct { nuclear@26: JMETHOD(void, start_pass, (j_compress_ptr cinfo)); nuclear@26: /* perhaps this should be an array??? */ nuclear@26: JMETHOD(void, forward_DCT, (j_compress_ptr cinfo, nuclear@26: jpeg_component_info * compptr, nuclear@26: JSAMPARRAY sample_data, JBLOCKROW coef_blocks, nuclear@26: JDIMENSION start_row, JDIMENSION start_col, nuclear@26: JDIMENSION num_blocks)); nuclear@26: }; nuclear@26: nuclear@26: /* Entropy encoding */ nuclear@26: struct jpeg_entropy_encoder { nuclear@26: JMETHOD(void, start_pass, (j_compress_ptr cinfo, boolean gather_statistics)); nuclear@26: JMETHOD(boolean, encode_mcu, (j_compress_ptr cinfo, JBLOCKROW *MCU_data)); nuclear@26: JMETHOD(void, finish_pass, (j_compress_ptr cinfo)); nuclear@26: }; nuclear@26: nuclear@26: /* Marker writing */ nuclear@26: struct jpeg_marker_writer { nuclear@26: JMETHOD(void, write_file_header, (j_compress_ptr cinfo)); nuclear@26: JMETHOD(void, write_frame_header, (j_compress_ptr cinfo)); nuclear@26: JMETHOD(void, write_scan_header, (j_compress_ptr cinfo)); nuclear@26: JMETHOD(void, write_file_trailer, (j_compress_ptr cinfo)); nuclear@26: JMETHOD(void, write_tables_only, (j_compress_ptr cinfo)); nuclear@26: /* These routines are exported to allow insertion of extra markers */ nuclear@26: /* Probably only COM and APPn markers should be written this way */ nuclear@26: JMETHOD(void, write_marker_header, (j_compress_ptr cinfo, int marker, nuclear@26: unsigned int datalen)); nuclear@26: JMETHOD(void, write_marker_byte, (j_compress_ptr cinfo, int val)); nuclear@26: }; nuclear@26: nuclear@26: nuclear@26: /* Declarations for decompression modules */ nuclear@26: nuclear@26: /* Master control module */ nuclear@26: struct jpeg_decomp_master { nuclear@26: JMETHOD(void, prepare_for_output_pass, (j_decompress_ptr cinfo)); nuclear@26: JMETHOD(void, finish_output_pass, (j_decompress_ptr cinfo)); nuclear@26: nuclear@26: /* State variables made visible to other modules */ nuclear@26: boolean is_dummy_pass; /* True during 1st pass for 2-pass quant */ nuclear@26: }; nuclear@26: nuclear@26: /* Input control module */ nuclear@26: struct jpeg_input_controller { nuclear@26: JMETHOD(int, consume_input, (j_decompress_ptr cinfo)); nuclear@26: JMETHOD(void, reset_input_controller, (j_decompress_ptr cinfo)); nuclear@26: JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo)); nuclear@26: JMETHOD(void, finish_input_pass, (j_decompress_ptr cinfo)); nuclear@26: nuclear@26: /* State variables made visible to other modules */ nuclear@26: boolean has_multiple_scans; /* True if file has multiple scans */ nuclear@26: boolean eoi_reached; /* True when EOI has been consumed */ nuclear@26: }; nuclear@26: nuclear@26: /* Main buffer control (downsampled-data buffer) */ nuclear@26: struct jpeg_d_main_controller { nuclear@26: JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)); nuclear@26: JMETHOD(void, process_data, (j_decompress_ptr cinfo, nuclear@26: JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, nuclear@26: JDIMENSION out_rows_avail)); nuclear@26: }; nuclear@26: nuclear@26: /* Coefficient buffer control */ nuclear@26: struct jpeg_d_coef_controller { nuclear@26: JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo)); nuclear@26: JMETHOD(int, consume_data, (j_decompress_ptr cinfo)); nuclear@26: JMETHOD(void, start_output_pass, (j_decompress_ptr cinfo)); nuclear@26: JMETHOD(int, decompress_data, (j_decompress_ptr cinfo, nuclear@26: JSAMPIMAGE output_buf)); nuclear@26: /* Pointer to array of coefficient virtual arrays, or NULL if none */ nuclear@26: jvirt_barray_ptr *coef_arrays; nuclear@26: }; nuclear@26: nuclear@26: /* Decompression postprocessing (color quantization buffer control) */ nuclear@26: struct jpeg_d_post_controller { nuclear@26: JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)); nuclear@26: JMETHOD(void, post_process_data, (j_decompress_ptr cinfo, nuclear@26: JSAMPIMAGE input_buf, nuclear@26: JDIMENSION *in_row_group_ctr, nuclear@26: JDIMENSION in_row_groups_avail, nuclear@26: JSAMPARRAY output_buf, nuclear@26: JDIMENSION *out_row_ctr, nuclear@26: JDIMENSION out_rows_avail)); nuclear@26: }; nuclear@26: nuclear@26: /* Marker reading & parsing */ nuclear@26: struct jpeg_marker_reader { nuclear@26: JMETHOD(void, reset_marker_reader, (j_decompress_ptr cinfo)); nuclear@26: /* Read markers until SOS or EOI. nuclear@26: * Returns same codes as are defined for jpeg_consume_input: nuclear@26: * JPEG_SUSPENDED, JPEG_REACHED_SOS, or JPEG_REACHED_EOI. nuclear@26: */ nuclear@26: JMETHOD(int, read_markers, (j_decompress_ptr cinfo)); nuclear@26: /* Read a restart marker --- exported for use by entropy decoder only */ nuclear@26: jpeg_marker_parser_method read_restart_marker; nuclear@26: nuclear@26: /* State of marker reader --- nominally internal, but applications nuclear@26: * supplying COM or APPn handlers might like to know the state. nuclear@26: */ nuclear@26: boolean saw_SOI; /* found SOI? */ nuclear@26: boolean saw_SOF; /* found SOF? */ nuclear@26: int next_restart_num; /* next restart number expected (0-7) */ nuclear@26: unsigned int discarded_bytes; /* # of bytes skipped looking for a marker */ nuclear@26: }; nuclear@26: nuclear@26: /* Entropy decoding */ nuclear@26: struct jpeg_entropy_decoder { nuclear@26: JMETHOD(void, start_pass, (j_decompress_ptr cinfo)); nuclear@26: JMETHOD(boolean, decode_mcu, (j_decompress_ptr cinfo, nuclear@26: JBLOCKROW *MCU_data)); nuclear@26: nuclear@26: /* This is here to share code between baseline and progressive decoders; */ nuclear@26: /* other modules probably should not use it */ nuclear@26: boolean insufficient_data; /* set TRUE after emitting warning */ nuclear@26: }; nuclear@26: nuclear@26: /* Inverse DCT (also performs dequantization) */ nuclear@26: typedef JMETHOD(void, inverse_DCT_method_ptr, nuclear@26: (j_decompress_ptr cinfo, jpeg_component_info * compptr, nuclear@26: JCOEFPTR coef_block, nuclear@26: JSAMPARRAY output_buf, JDIMENSION output_col)); nuclear@26: nuclear@26: struct jpeg_inverse_dct { nuclear@26: JMETHOD(void, start_pass, (j_decompress_ptr cinfo)); nuclear@26: /* It is useful to allow each component to have a separate IDCT method. */ nuclear@26: inverse_DCT_method_ptr inverse_DCT[MAX_COMPONENTS]; nuclear@26: }; nuclear@26: nuclear@26: /* Upsampling (note that upsampler must also call color converter) */ nuclear@26: struct jpeg_upsampler { nuclear@26: JMETHOD(void, start_pass, (j_decompress_ptr cinfo)); nuclear@26: JMETHOD(void, upsample, (j_decompress_ptr cinfo, nuclear@26: JSAMPIMAGE input_buf, nuclear@26: JDIMENSION *in_row_group_ctr, nuclear@26: JDIMENSION in_row_groups_avail, nuclear@26: JSAMPARRAY output_buf, nuclear@26: JDIMENSION *out_row_ctr, nuclear@26: JDIMENSION out_rows_avail)); nuclear@26: nuclear@26: boolean need_context_rows; /* TRUE if need rows above & below */ nuclear@26: }; nuclear@26: nuclear@26: /* Colorspace conversion */ nuclear@26: struct jpeg_color_deconverter { nuclear@26: JMETHOD(void, start_pass, (j_decompress_ptr cinfo)); nuclear@26: JMETHOD(void, color_convert, (j_decompress_ptr cinfo, nuclear@26: JSAMPIMAGE input_buf, JDIMENSION input_row, nuclear@26: JSAMPARRAY output_buf, int num_rows)); nuclear@26: }; nuclear@26: nuclear@26: /* Color quantization or color precision reduction */ nuclear@26: struct jpeg_color_quantizer { nuclear@26: JMETHOD(void, start_pass, (j_decompress_ptr cinfo, boolean is_pre_scan)); nuclear@26: JMETHOD(void, color_quantize, (j_decompress_ptr cinfo, nuclear@26: JSAMPARRAY input_buf, JSAMPARRAY output_buf, nuclear@26: int num_rows)); nuclear@26: JMETHOD(void, finish_pass, (j_decompress_ptr cinfo)); nuclear@26: JMETHOD(void, new_color_map, (j_decompress_ptr cinfo)); nuclear@26: }; nuclear@26: nuclear@26: nuclear@26: /* Miscellaneous useful macros */ nuclear@26: nuclear@26: #undef MAX nuclear@26: #define MAX(a,b) ((a) > (b) ? (a) : (b)) nuclear@26: #undef MIN nuclear@26: #define MIN(a,b) ((a) < (b) ? (a) : (b)) nuclear@26: nuclear@26: nuclear@26: /* We assume that right shift corresponds to signed division by 2 with nuclear@26: * rounding towards minus infinity. This is correct for typical "arithmetic nuclear@26: * shift" instructions that shift in copies of the sign bit. But some nuclear@26: * C compilers implement >> with an unsigned shift. For these machines you nuclear@26: * must define RIGHT_SHIFT_IS_UNSIGNED. nuclear@26: * RIGHT_SHIFT provides a proper signed right shift of an INT32 quantity. nuclear@26: * It is only applied with constant shift counts. SHIFT_TEMPS must be nuclear@26: * included in the variables of any routine using RIGHT_SHIFT. nuclear@26: */ nuclear@26: nuclear@26: #ifdef RIGHT_SHIFT_IS_UNSIGNED nuclear@26: #define SHIFT_TEMPS INT32 shift_temp; nuclear@26: #define RIGHT_SHIFT(x,shft) \ nuclear@26: ((shift_temp = (x)) < 0 ? \ nuclear@26: (shift_temp >> (shft)) | ((~((INT32) 0)) << (32-(shft))) : \ nuclear@26: (shift_temp >> (shft))) nuclear@26: #else nuclear@26: #define SHIFT_TEMPS nuclear@26: #define RIGHT_SHIFT(x,shft) ((x) >> (shft)) nuclear@26: #endif nuclear@26: nuclear@26: nuclear@26: /* Short forms of external names for systems with brain-damaged linkers. */ nuclear@26: nuclear@26: #ifdef NEED_SHORT_EXTERNAL_NAMES nuclear@26: #define jinit_compress_master jICompress nuclear@26: #define jinit_c_master_control jICMaster nuclear@26: #define jinit_c_main_controller jICMainC nuclear@26: #define jinit_c_prep_controller jICPrepC nuclear@26: #define jinit_c_coef_controller jICCoefC nuclear@26: #define jinit_color_converter jICColor nuclear@26: #define jinit_downsampler jIDownsampler nuclear@26: #define jinit_forward_dct jIFDCT nuclear@26: #define jinit_huff_encoder jIHEncoder nuclear@26: #define jinit_phuff_encoder jIPHEncoder nuclear@26: #define jinit_marker_writer jIMWriter nuclear@26: #define jinit_master_decompress jIDMaster nuclear@26: #define jinit_d_main_controller jIDMainC nuclear@26: #define jinit_d_coef_controller jIDCoefC nuclear@26: #define jinit_d_post_controller jIDPostC nuclear@26: #define jinit_input_controller jIInCtlr nuclear@26: #define jinit_marker_reader jIMReader nuclear@26: #define jinit_huff_decoder jIHDecoder nuclear@26: #define jinit_phuff_decoder jIPHDecoder nuclear@26: #define jinit_inverse_dct jIIDCT nuclear@26: #define jinit_upsampler jIUpsampler nuclear@26: #define jinit_color_deconverter jIDColor nuclear@26: #define jinit_1pass_quantizer jI1Quant nuclear@26: #define jinit_2pass_quantizer jI2Quant nuclear@26: #define jinit_merged_upsampler jIMUpsampler nuclear@26: #define jinit_memory_mgr jIMemMgr nuclear@26: #define jdiv_round_up jDivRound nuclear@26: #define jround_up jRound nuclear@26: #define jcopy_sample_rows jCopySamples nuclear@26: #define jcopy_block_row jCopyBlocks nuclear@26: #define jzero_far jZeroFar nuclear@26: #define jpeg_zigzag_order jZIGTable nuclear@26: #define jpeg_natural_order jZAGTable nuclear@26: #endif /* NEED_SHORT_EXTERNAL_NAMES */ nuclear@26: nuclear@26: nuclear@26: /* Compression module initialization routines */ nuclear@26: EXTERN(void) jinit_compress_master JPP((j_compress_ptr cinfo)); nuclear@26: EXTERN(void) jinit_c_master_control JPP((j_compress_ptr cinfo, nuclear@26: boolean transcode_only)); nuclear@26: EXTERN(void) jinit_c_main_controller JPP((j_compress_ptr cinfo, nuclear@26: boolean need_full_buffer)); nuclear@26: EXTERN(void) jinit_c_prep_controller JPP((j_compress_ptr cinfo, nuclear@26: boolean need_full_buffer)); nuclear@26: EXTERN(void) jinit_c_coef_controller JPP((j_compress_ptr cinfo, nuclear@26: boolean need_full_buffer)); nuclear@26: EXTERN(void) jinit_color_converter JPP((j_compress_ptr cinfo)); nuclear@26: EXTERN(void) jinit_downsampler JPP((j_compress_ptr cinfo)); nuclear@26: EXTERN(void) jinit_forward_dct JPP((j_compress_ptr cinfo)); nuclear@26: EXTERN(void) jinit_huff_encoder JPP((j_compress_ptr cinfo)); nuclear@26: EXTERN(void) jinit_phuff_encoder JPP((j_compress_ptr cinfo)); nuclear@26: EXTERN(void) jinit_marker_writer JPP((j_compress_ptr cinfo)); nuclear@26: /* Decompression module initialization routines */ nuclear@26: EXTERN(void) jinit_master_decompress JPP((j_decompress_ptr cinfo)); nuclear@26: EXTERN(void) jinit_d_main_controller JPP((j_decompress_ptr cinfo, nuclear@26: boolean need_full_buffer)); nuclear@26: EXTERN(void) jinit_d_coef_controller JPP((j_decompress_ptr cinfo, nuclear@26: boolean need_full_buffer)); nuclear@26: EXTERN(void) jinit_d_post_controller JPP((j_decompress_ptr cinfo, nuclear@26: boolean need_full_buffer)); nuclear@26: EXTERN(void) jinit_input_controller JPP((j_decompress_ptr cinfo)); nuclear@26: EXTERN(void) jinit_marker_reader JPP((j_decompress_ptr cinfo)); nuclear@26: EXTERN(void) jinit_huff_decoder JPP((j_decompress_ptr cinfo)); nuclear@26: EXTERN(void) jinit_phuff_decoder JPP((j_decompress_ptr cinfo)); nuclear@26: EXTERN(void) jinit_inverse_dct JPP((j_decompress_ptr cinfo)); nuclear@26: EXTERN(void) jinit_upsampler JPP((j_decompress_ptr cinfo)); nuclear@26: EXTERN(void) jinit_color_deconverter JPP((j_decompress_ptr cinfo)); nuclear@26: EXTERN(void) jinit_1pass_quantizer JPP((j_decompress_ptr cinfo)); nuclear@26: EXTERN(void) jinit_2pass_quantizer JPP((j_decompress_ptr cinfo)); nuclear@26: EXTERN(void) jinit_merged_upsampler JPP((j_decompress_ptr cinfo)); nuclear@26: /* Memory manager initialization */ nuclear@26: EXTERN(void) jinit_memory_mgr JPP((j_common_ptr cinfo)); nuclear@26: nuclear@26: /* Utility routines in jutils.c */ nuclear@26: EXTERN(long) jdiv_round_up JPP((long a, long b)); nuclear@26: EXTERN(long) jround_up JPP((long a, long b)); nuclear@26: EXTERN(void) jcopy_sample_rows JPP((JSAMPARRAY input_array, int source_row, nuclear@26: JSAMPARRAY output_array, int dest_row, nuclear@26: int num_rows, JDIMENSION num_cols)); nuclear@26: EXTERN(void) jcopy_block_row JPP((JBLOCKROW input_row, JBLOCKROW output_row, nuclear@26: JDIMENSION num_blocks)); nuclear@26: EXTERN(void) jzero_far JPP((void FAR * target, size_t bytestozero)); nuclear@26: /* Constant tables in jutils.c */ nuclear@26: #if 0 /* This table is not actually needed in v6a */ nuclear@26: extern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */ nuclear@26: #endif nuclear@26: extern const int jpeg_natural_order[]; /* zigzag coef order to natural order */ nuclear@26: nuclear@26: /* Suppress undefined-structure complaints if necessary. */ nuclear@26: nuclear@26: #ifdef INCOMPLETE_TYPES_BROKEN nuclear@26: #ifndef AM_MEMORY_MANAGER /* only jmemmgr.c defines these */ nuclear@26: struct jvirt_sarray_control { long dummy; }; nuclear@26: struct jvirt_barray_control { long dummy; }; nuclear@26: #endif nuclear@26: #endif /* INCOMPLETE_TYPES_BROKEN */