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