1*dfc6aa5cSAndroid Build Coastguard Worker /* 2*dfc6aa5cSAndroid Build Coastguard Worker * jpegint.h 3*dfc6aa5cSAndroid Build Coastguard Worker * 4*dfc6aa5cSAndroid Build Coastguard Worker * This file was part of the Independent JPEG Group's software: 5*dfc6aa5cSAndroid Build Coastguard Worker * Copyright (C) 1991-1997, Thomas G. Lane. 6*dfc6aa5cSAndroid Build Coastguard Worker * Modified 1997-2009 by Guido Vollbeding. 7*dfc6aa5cSAndroid Build Coastguard Worker * Lossless JPEG Modifications: 8*dfc6aa5cSAndroid Build Coastguard Worker * Copyright (C) 1999, Ken Murchison. 9*dfc6aa5cSAndroid Build Coastguard Worker * libjpeg-turbo Modifications: 10*dfc6aa5cSAndroid Build Coastguard Worker * Copyright (C) 2015-2017, 2019, 2021-2022, 2024, D. R. Commander. 11*dfc6aa5cSAndroid Build Coastguard Worker * Copyright (C) 2015, Google, Inc. 12*dfc6aa5cSAndroid Build Coastguard Worker * Copyright (C) 2021, Alex Richardson. 13*dfc6aa5cSAndroid Build Coastguard Worker * For conditions of distribution and use, see the accompanying README.ijg 14*dfc6aa5cSAndroid Build Coastguard Worker * file. 15*dfc6aa5cSAndroid Build Coastguard Worker * 16*dfc6aa5cSAndroid Build Coastguard Worker * This file provides common declarations for the various JPEG modules. 17*dfc6aa5cSAndroid Build Coastguard Worker * These declarations are considered internal to the JPEG library; most 18*dfc6aa5cSAndroid Build Coastguard Worker * applications using the library shouldn't need to include this file. 19*dfc6aa5cSAndroid Build Coastguard Worker */ 20*dfc6aa5cSAndroid Build Coastguard Worker 21*dfc6aa5cSAndroid Build Coastguard Worker 22*dfc6aa5cSAndroid Build Coastguard Worker /* Declarations for both compression & decompression */ 23*dfc6aa5cSAndroid Build Coastguard Worker 24*dfc6aa5cSAndroid Build Coastguard Worker typedef enum { /* Operating modes for buffer controllers */ 25*dfc6aa5cSAndroid Build Coastguard Worker JBUF_PASS_THRU, /* Plain stripwise operation */ 26*dfc6aa5cSAndroid Build Coastguard Worker /* Remaining modes require a full-image buffer to have been created */ 27*dfc6aa5cSAndroid Build Coastguard Worker JBUF_SAVE_SOURCE, /* Run source subobject only, save output */ 28*dfc6aa5cSAndroid Build Coastguard Worker JBUF_CRANK_DEST, /* Run dest subobject only, using saved data */ 29*dfc6aa5cSAndroid Build Coastguard Worker JBUF_SAVE_AND_PASS /* Run both subobjects, save output */ 30*dfc6aa5cSAndroid Build Coastguard Worker } J_BUF_MODE; 31*dfc6aa5cSAndroid Build Coastguard Worker 32*dfc6aa5cSAndroid Build Coastguard Worker /* Values of global_state field (jdapi.c has some dependencies on ordering!) */ 33*dfc6aa5cSAndroid Build Coastguard Worker #define CSTATE_START 100 /* after create_compress */ 34*dfc6aa5cSAndroid Build Coastguard Worker #define CSTATE_SCANNING 101 /* start_compress done, write_scanlines OK */ 35*dfc6aa5cSAndroid Build Coastguard Worker #define CSTATE_RAW_OK 102 /* start_compress done, write_raw_data OK */ 36*dfc6aa5cSAndroid Build Coastguard Worker #define CSTATE_WRCOEFS 103 /* jpeg_write_coefficients done */ 37*dfc6aa5cSAndroid Build Coastguard Worker #define DSTATE_START 200 /* after create_decompress */ 38*dfc6aa5cSAndroid Build Coastguard Worker #define DSTATE_INHEADER 201 /* reading header markers, no SOS yet */ 39*dfc6aa5cSAndroid Build Coastguard Worker #define DSTATE_READY 202 /* found SOS, ready for start_decompress */ 40*dfc6aa5cSAndroid Build Coastguard Worker #define DSTATE_PRELOAD 203 /* reading multiscan file in start_decompress*/ 41*dfc6aa5cSAndroid Build Coastguard Worker #define DSTATE_PRESCAN 204 /* performing dummy pass for 2-pass quant */ 42*dfc6aa5cSAndroid Build Coastguard Worker #define DSTATE_SCANNING 205 /* start_decompress done, read_scanlines OK */ 43*dfc6aa5cSAndroid Build Coastguard Worker #define DSTATE_RAW_OK 206 /* start_decompress done, read_raw_data OK */ 44*dfc6aa5cSAndroid Build Coastguard Worker #define DSTATE_BUFIMAGE 207 /* expecting jpeg_start_output */ 45*dfc6aa5cSAndroid Build Coastguard Worker #define DSTATE_BUFPOST 208 /* looking for SOS/EOI in jpeg_finish_output */ 46*dfc6aa5cSAndroid Build Coastguard Worker #define DSTATE_RDCOEFS 209 /* reading file in jpeg_read_coefficients */ 47*dfc6aa5cSAndroid Build Coastguard Worker #define DSTATE_STOPPING 210 /* looking for EOI in jpeg_finish_decompress */ 48*dfc6aa5cSAndroid Build Coastguard Worker 49*dfc6aa5cSAndroid Build Coastguard Worker 50*dfc6aa5cSAndroid Build Coastguard Worker /* JLONG must hold at least signed 32-bit values. */ 51*dfc6aa5cSAndroid Build Coastguard Worker typedef long JLONG; 52*dfc6aa5cSAndroid Build Coastguard Worker 53*dfc6aa5cSAndroid Build Coastguard Worker /* JUINTPTR must hold pointer values. */ 54*dfc6aa5cSAndroid Build Coastguard Worker #ifdef __UINTPTR_TYPE__ 55*dfc6aa5cSAndroid Build Coastguard Worker /* 56*dfc6aa5cSAndroid Build Coastguard Worker * __UINTPTR_TYPE__ is GNU-specific and available in GCC 4.6+ and Clang 3.0+. 57*dfc6aa5cSAndroid Build Coastguard Worker * Fortunately, that is sufficient to support the few architectures for which 58*dfc6aa5cSAndroid Build Coastguard Worker * sizeof(void *) != sizeof(size_t). The only other options would require C99 59*dfc6aa5cSAndroid Build Coastguard Worker * or Clang-specific builtins. 60*dfc6aa5cSAndroid Build Coastguard Worker */ 61*dfc6aa5cSAndroid Build Coastguard Worker typedef __UINTPTR_TYPE__ JUINTPTR; 62*dfc6aa5cSAndroid Build Coastguard Worker #else 63*dfc6aa5cSAndroid Build Coastguard Worker typedef size_t JUINTPTR; 64*dfc6aa5cSAndroid Build Coastguard Worker #endif 65*dfc6aa5cSAndroid Build Coastguard Worker 66*dfc6aa5cSAndroid Build Coastguard Worker /* 67*dfc6aa5cSAndroid Build Coastguard Worker * Left shift macro that handles a negative operand without causing any 68*dfc6aa5cSAndroid Build Coastguard Worker * sanitizer warnings 69*dfc6aa5cSAndroid Build Coastguard Worker */ 70*dfc6aa5cSAndroid Build Coastguard Worker 71*dfc6aa5cSAndroid Build Coastguard Worker #define LEFT_SHIFT(a, b) ((JLONG)((unsigned long)(a) << (b))) 72*dfc6aa5cSAndroid Build Coastguard Worker 73*dfc6aa5cSAndroid Build Coastguard Worker 74*dfc6aa5cSAndroid Build Coastguard Worker /* Declarations for compression modules */ 75*dfc6aa5cSAndroid Build Coastguard Worker 76*dfc6aa5cSAndroid Build Coastguard Worker /* Master control module */ 77*dfc6aa5cSAndroid Build Coastguard Worker struct jpeg_comp_master { 78*dfc6aa5cSAndroid Build Coastguard Worker void (*prepare_for_pass) (j_compress_ptr cinfo); 79*dfc6aa5cSAndroid Build Coastguard Worker void (*pass_startup) (j_compress_ptr cinfo); 80*dfc6aa5cSAndroid Build Coastguard Worker void (*finish_pass) (j_compress_ptr cinfo); 81*dfc6aa5cSAndroid Build Coastguard Worker 82*dfc6aa5cSAndroid Build Coastguard Worker /* State variables made visible to other modules */ 83*dfc6aa5cSAndroid Build Coastguard Worker boolean call_pass_startup; /* True if pass_startup must be called */ 84*dfc6aa5cSAndroid Build Coastguard Worker boolean is_last_pass; /* True during last pass */ 85*dfc6aa5cSAndroid Build Coastguard Worker }; 86*dfc6aa5cSAndroid Build Coastguard Worker 87*dfc6aa5cSAndroid Build Coastguard Worker /* Main buffer control (downsampled-data buffer) */ 88*dfc6aa5cSAndroid Build Coastguard Worker struct jpeg_c_main_controller { 89*dfc6aa5cSAndroid Build Coastguard Worker void (*start_pass) (j_compress_ptr cinfo, J_BUF_MODE pass_mode); 90*dfc6aa5cSAndroid Build Coastguard Worker void (*process_data) (j_compress_ptr cinfo, JSAMPARRAY input_buf, 91*dfc6aa5cSAndroid Build Coastguard Worker JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail); 92*dfc6aa5cSAndroid Build Coastguard Worker }; 93*dfc6aa5cSAndroid Build Coastguard Worker 94*dfc6aa5cSAndroid Build Coastguard Worker /* Compression preprocessing (downsampling input buffer control) */ 95*dfc6aa5cSAndroid Build Coastguard Worker struct jpeg_c_prep_controller { 96*dfc6aa5cSAndroid Build Coastguard Worker void (*start_pass) (j_compress_ptr cinfo, J_BUF_MODE pass_mode); 97*dfc6aa5cSAndroid Build Coastguard Worker void (*pre_process_data) (j_compress_ptr cinfo, JSAMPARRAY input_buf, 98*dfc6aa5cSAndroid Build Coastguard Worker JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail, 99*dfc6aa5cSAndroid Build Coastguard Worker JSAMPIMAGE output_buf, 100*dfc6aa5cSAndroid Build Coastguard Worker JDIMENSION *out_row_group_ctr, 101*dfc6aa5cSAndroid Build Coastguard Worker JDIMENSION out_row_groups_avail); 102*dfc6aa5cSAndroid Build Coastguard Worker }; 103*dfc6aa5cSAndroid Build Coastguard Worker 104*dfc6aa5cSAndroid Build Coastguard Worker /* Coefficient buffer control */ 105*dfc6aa5cSAndroid Build Coastguard Worker struct jpeg_c_coef_controller { 106*dfc6aa5cSAndroid Build Coastguard Worker void (*start_pass) (j_compress_ptr cinfo, J_BUF_MODE pass_mode); 107*dfc6aa5cSAndroid Build Coastguard Worker boolean (*compress_data) (j_compress_ptr cinfo, JSAMPIMAGE input_buf); 108*dfc6aa5cSAndroid Build Coastguard Worker }; 109*dfc6aa5cSAndroid Build Coastguard Worker 110*dfc6aa5cSAndroid Build Coastguard Worker /* Colorspace conversion */ 111*dfc6aa5cSAndroid Build Coastguard Worker struct jpeg_color_converter { 112*dfc6aa5cSAndroid Build Coastguard Worker void (*start_pass) (j_compress_ptr cinfo); 113*dfc6aa5cSAndroid Build Coastguard Worker void (*color_convert) (j_compress_ptr cinfo, JSAMPARRAY input_buf, 114*dfc6aa5cSAndroid Build Coastguard Worker JSAMPIMAGE output_buf, JDIMENSION output_row, 115*dfc6aa5cSAndroid Build Coastguard Worker int num_rows); 116*dfc6aa5cSAndroid Build Coastguard Worker }; 117*dfc6aa5cSAndroid Build Coastguard Worker 118*dfc6aa5cSAndroid Build Coastguard Worker /* Downsampling */ 119*dfc6aa5cSAndroid Build Coastguard Worker struct jpeg_downsampler { 120*dfc6aa5cSAndroid Build Coastguard Worker void (*start_pass) (j_compress_ptr cinfo); 121*dfc6aa5cSAndroid Build Coastguard Worker void (*downsample) (j_compress_ptr cinfo, JSAMPIMAGE input_buf, 122*dfc6aa5cSAndroid Build Coastguard Worker JDIMENSION in_row_index, JSAMPIMAGE output_buf, 123*dfc6aa5cSAndroid Build Coastguard Worker JDIMENSION out_row_group_index); 124*dfc6aa5cSAndroid Build Coastguard Worker 125*dfc6aa5cSAndroid Build Coastguard Worker boolean need_context_rows; /* TRUE if need rows above & below */ 126*dfc6aa5cSAndroid Build Coastguard Worker }; 127*dfc6aa5cSAndroid Build Coastguard Worker 128*dfc6aa5cSAndroid Build Coastguard Worker /* Forward DCT (also controls coefficient quantization) */ 129*dfc6aa5cSAndroid Build Coastguard Worker struct jpeg_forward_dct { 130*dfc6aa5cSAndroid Build Coastguard Worker void (*start_pass) (j_compress_ptr cinfo); 131*dfc6aa5cSAndroid Build Coastguard Worker /* perhaps this should be an array??? */ 132*dfc6aa5cSAndroid Build Coastguard Worker void (*forward_DCT) (j_compress_ptr cinfo, jpeg_component_info *compptr, 133*dfc6aa5cSAndroid Build Coastguard Worker JSAMPARRAY sample_data, JBLOCKROW coef_blocks, 134*dfc6aa5cSAndroid Build Coastguard Worker JDIMENSION start_row, JDIMENSION start_col, 135*dfc6aa5cSAndroid Build Coastguard Worker JDIMENSION num_blocks); 136*dfc6aa5cSAndroid Build Coastguard Worker }; 137*dfc6aa5cSAndroid Build Coastguard Worker 138*dfc6aa5cSAndroid Build Coastguard Worker /* Entropy encoding */ 139*dfc6aa5cSAndroid Build Coastguard Worker struct jpeg_entropy_encoder { 140*dfc6aa5cSAndroid Build Coastguard Worker void (*start_pass) (j_compress_ptr cinfo, boolean gather_statistics); 141*dfc6aa5cSAndroid Build Coastguard Worker boolean (*encode_mcu) (j_compress_ptr cinfo, JBLOCKROW *MCU_data); 142*dfc6aa5cSAndroid Build Coastguard Worker void (*finish_pass) (j_compress_ptr cinfo); 143*dfc6aa5cSAndroid Build Coastguard Worker }; 144*dfc6aa5cSAndroid Build Coastguard Worker 145*dfc6aa5cSAndroid Build Coastguard Worker /* Marker writing */ 146*dfc6aa5cSAndroid Build Coastguard Worker struct jpeg_marker_writer { 147*dfc6aa5cSAndroid Build Coastguard Worker void (*write_file_header) (j_compress_ptr cinfo); 148*dfc6aa5cSAndroid Build Coastguard Worker void (*write_frame_header) (j_compress_ptr cinfo); 149*dfc6aa5cSAndroid Build Coastguard Worker void (*write_scan_header) (j_compress_ptr cinfo); 150*dfc6aa5cSAndroid Build Coastguard Worker void (*write_file_trailer) (j_compress_ptr cinfo); 151*dfc6aa5cSAndroid Build Coastguard Worker void (*write_tables_only) (j_compress_ptr cinfo); 152*dfc6aa5cSAndroid Build Coastguard Worker /* These routines are exported to allow insertion of extra markers */ 153*dfc6aa5cSAndroid Build Coastguard Worker /* Probably only COM and APPn markers should be written this way */ 154*dfc6aa5cSAndroid Build Coastguard Worker void (*write_marker_header) (j_compress_ptr cinfo, int marker, 155*dfc6aa5cSAndroid Build Coastguard Worker unsigned int datalen); 156*dfc6aa5cSAndroid Build Coastguard Worker void (*write_marker_byte) (j_compress_ptr cinfo, int val); 157*dfc6aa5cSAndroid Build Coastguard Worker }; 158*dfc6aa5cSAndroid Build Coastguard Worker 159*dfc6aa5cSAndroid Build Coastguard Worker 160*dfc6aa5cSAndroid Build Coastguard Worker /* Declarations for decompression modules */ 161*dfc6aa5cSAndroid Build Coastguard Worker 162*dfc6aa5cSAndroid Build Coastguard Worker /* Master control module */ 163*dfc6aa5cSAndroid Build Coastguard Worker struct jpeg_decomp_master { 164*dfc6aa5cSAndroid Build Coastguard Worker void (*prepare_for_output_pass) (j_decompress_ptr cinfo); 165*dfc6aa5cSAndroid Build Coastguard Worker void (*finish_output_pass) (j_decompress_ptr cinfo); 166*dfc6aa5cSAndroid Build Coastguard Worker 167*dfc6aa5cSAndroid Build Coastguard Worker /* State variables made visible to other modules */ 168*dfc6aa5cSAndroid Build Coastguard Worker boolean is_dummy_pass; /* True during 1st pass for 2-pass quant */ 169*dfc6aa5cSAndroid Build Coastguard Worker 170*dfc6aa5cSAndroid Build Coastguard Worker /* Partial decompression variables */ 171*dfc6aa5cSAndroid Build Coastguard Worker JDIMENSION first_iMCU_col; 172*dfc6aa5cSAndroid Build Coastguard Worker JDIMENSION last_iMCU_col; 173*dfc6aa5cSAndroid Build Coastguard Worker JDIMENSION first_MCU_col[MAX_COMPONENTS]; 174*dfc6aa5cSAndroid Build Coastguard Worker JDIMENSION last_MCU_col[MAX_COMPONENTS]; 175*dfc6aa5cSAndroid Build Coastguard Worker boolean jinit_upsampler_no_alloc; 176*dfc6aa5cSAndroid Build Coastguard Worker 177*dfc6aa5cSAndroid Build Coastguard Worker /* Last iMCU row that was successfully decoded */ 178*dfc6aa5cSAndroid Build Coastguard Worker JDIMENSION last_good_iMCU_row; 179*dfc6aa5cSAndroid Build Coastguard Worker 180*dfc6aa5cSAndroid Build Coastguard Worker /* Tail of list of saved markers */ 181*dfc6aa5cSAndroid Build Coastguard Worker jpeg_saved_marker_ptr marker_list_end; 182*dfc6aa5cSAndroid Build Coastguard Worker }; 183*dfc6aa5cSAndroid Build Coastguard Worker 184*dfc6aa5cSAndroid Build Coastguard Worker /* Input control module */ 185*dfc6aa5cSAndroid Build Coastguard Worker struct jpeg_input_controller { 186*dfc6aa5cSAndroid Build Coastguard Worker int (*consume_input) (j_decompress_ptr cinfo); 187*dfc6aa5cSAndroid Build Coastguard Worker void (*reset_input_controller) (j_decompress_ptr cinfo); 188*dfc6aa5cSAndroid Build Coastguard Worker void (*start_input_pass) (j_decompress_ptr cinfo); 189*dfc6aa5cSAndroid Build Coastguard Worker void (*finish_input_pass) (j_decompress_ptr cinfo); 190*dfc6aa5cSAndroid Build Coastguard Worker 191*dfc6aa5cSAndroid Build Coastguard Worker /* State variables made visible to other modules */ 192*dfc6aa5cSAndroid Build Coastguard Worker boolean has_multiple_scans; /* True if file has multiple scans */ 193*dfc6aa5cSAndroid Build Coastguard Worker boolean eoi_reached; /* True when EOI has been consumed */ 194*dfc6aa5cSAndroid Build Coastguard Worker }; 195*dfc6aa5cSAndroid Build Coastguard Worker 196*dfc6aa5cSAndroid Build Coastguard Worker /* Main buffer control (downsampled-data buffer) */ 197*dfc6aa5cSAndroid Build Coastguard Worker struct jpeg_d_main_controller { 198*dfc6aa5cSAndroid Build Coastguard Worker void (*start_pass) (j_decompress_ptr cinfo, J_BUF_MODE pass_mode); 199*dfc6aa5cSAndroid Build Coastguard Worker void (*process_data) (j_decompress_ptr cinfo, JSAMPARRAY output_buf, 200*dfc6aa5cSAndroid Build Coastguard Worker JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail); 201*dfc6aa5cSAndroid Build Coastguard Worker }; 202*dfc6aa5cSAndroid Build Coastguard Worker 203*dfc6aa5cSAndroid Build Coastguard Worker /* Coefficient buffer control */ 204*dfc6aa5cSAndroid Build Coastguard Worker struct jpeg_d_coef_controller { 205*dfc6aa5cSAndroid Build Coastguard Worker void (*start_input_pass) (j_decompress_ptr cinfo); 206*dfc6aa5cSAndroid Build Coastguard Worker int (*consume_data) (j_decompress_ptr cinfo); 207*dfc6aa5cSAndroid Build Coastguard Worker void (*start_output_pass) (j_decompress_ptr cinfo); 208*dfc6aa5cSAndroid Build Coastguard Worker int (*decompress_data) (j_decompress_ptr cinfo, JSAMPIMAGE output_buf); 209*dfc6aa5cSAndroid Build Coastguard Worker /* Pointer to array of coefficient virtual arrays, or NULL if none */ 210*dfc6aa5cSAndroid Build Coastguard Worker jvirt_barray_ptr *coef_arrays; 211*dfc6aa5cSAndroid Build Coastguard Worker }; 212*dfc6aa5cSAndroid Build Coastguard Worker 213*dfc6aa5cSAndroid Build Coastguard Worker /* Decompression postprocessing (color quantization buffer control) */ 214*dfc6aa5cSAndroid Build Coastguard Worker struct jpeg_d_post_controller { 215*dfc6aa5cSAndroid Build Coastguard Worker void (*start_pass) (j_decompress_ptr cinfo, J_BUF_MODE pass_mode); 216*dfc6aa5cSAndroid Build Coastguard Worker void (*post_process_data) (j_decompress_ptr cinfo, JSAMPIMAGE input_buf, 217*dfc6aa5cSAndroid Build Coastguard Worker JDIMENSION *in_row_group_ctr, 218*dfc6aa5cSAndroid Build Coastguard Worker JDIMENSION in_row_groups_avail, 219*dfc6aa5cSAndroid Build Coastguard Worker JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, 220*dfc6aa5cSAndroid Build Coastguard Worker JDIMENSION out_rows_avail); 221*dfc6aa5cSAndroid Build Coastguard Worker }; 222*dfc6aa5cSAndroid Build Coastguard Worker 223*dfc6aa5cSAndroid Build Coastguard Worker /* Marker reading & parsing */ 224*dfc6aa5cSAndroid Build Coastguard Worker struct jpeg_marker_reader { 225*dfc6aa5cSAndroid Build Coastguard Worker void (*reset_marker_reader) (j_decompress_ptr cinfo); 226*dfc6aa5cSAndroid Build Coastguard Worker /* Read markers until SOS or EOI. 227*dfc6aa5cSAndroid Build Coastguard Worker * Returns same codes as are defined for jpeg_consume_input: 228*dfc6aa5cSAndroid Build Coastguard Worker * JPEG_SUSPENDED, JPEG_REACHED_SOS, or JPEG_REACHED_EOI. 229*dfc6aa5cSAndroid Build Coastguard Worker */ 230*dfc6aa5cSAndroid Build Coastguard Worker int (*read_markers) (j_decompress_ptr cinfo); 231*dfc6aa5cSAndroid Build Coastguard Worker /* Read a restart marker --- exported for use by entropy decoder only */ 232*dfc6aa5cSAndroid Build Coastguard Worker jpeg_marker_parser_method read_restart_marker; 233*dfc6aa5cSAndroid Build Coastguard Worker 234*dfc6aa5cSAndroid Build Coastguard Worker /* State of marker reader --- nominally internal, but applications 235*dfc6aa5cSAndroid Build Coastguard Worker * supplying COM or APPn handlers might like to know the state. 236*dfc6aa5cSAndroid Build Coastguard Worker */ 237*dfc6aa5cSAndroid Build Coastguard Worker boolean saw_SOI; /* found SOI? */ 238*dfc6aa5cSAndroid Build Coastguard Worker boolean saw_SOF; /* found SOF? */ 239*dfc6aa5cSAndroid Build Coastguard Worker int next_restart_num; /* next restart number expected (0-7) */ 240*dfc6aa5cSAndroid Build Coastguard Worker unsigned int discarded_bytes; /* # of bytes skipped looking for a marker */ 241*dfc6aa5cSAndroid Build Coastguard Worker }; 242*dfc6aa5cSAndroid Build Coastguard Worker 243*dfc6aa5cSAndroid Build Coastguard Worker /* Entropy decoding */ 244*dfc6aa5cSAndroid Build Coastguard Worker struct jpeg_entropy_decoder { 245*dfc6aa5cSAndroid Build Coastguard Worker void (*start_pass) (j_decompress_ptr cinfo); 246*dfc6aa5cSAndroid Build Coastguard Worker boolean (*decode_mcu) (j_decompress_ptr cinfo, JBLOCKROW *MCU_data); 247*dfc6aa5cSAndroid Build Coastguard Worker 248*dfc6aa5cSAndroid Build Coastguard Worker /* This is here to share code between baseline and progressive decoders; */ 249*dfc6aa5cSAndroid Build Coastguard Worker /* other modules probably should not use it */ 250*dfc6aa5cSAndroid Build Coastguard Worker boolean insufficient_data; /* set TRUE after emitting warning */ 251*dfc6aa5cSAndroid Build Coastguard Worker }; 252*dfc6aa5cSAndroid Build Coastguard Worker 253*dfc6aa5cSAndroid Build Coastguard Worker /* Inverse DCT (also performs dequantization) */ 254*dfc6aa5cSAndroid Build Coastguard Worker typedef void (*inverse_DCT_method_ptr) (j_decompress_ptr cinfo, 255*dfc6aa5cSAndroid Build Coastguard Worker jpeg_component_info *compptr, 256*dfc6aa5cSAndroid Build Coastguard Worker JCOEFPTR coef_block, 257*dfc6aa5cSAndroid Build Coastguard Worker JSAMPARRAY output_buf, 258*dfc6aa5cSAndroid Build Coastguard Worker JDIMENSION output_col); 259*dfc6aa5cSAndroid Build Coastguard Worker 260*dfc6aa5cSAndroid Build Coastguard Worker struct jpeg_inverse_dct { 261*dfc6aa5cSAndroid Build Coastguard Worker void (*start_pass) (j_decompress_ptr cinfo); 262*dfc6aa5cSAndroid Build Coastguard Worker /* It is useful to allow each component to have a separate IDCT method. */ 263*dfc6aa5cSAndroid Build Coastguard Worker inverse_DCT_method_ptr inverse_DCT[MAX_COMPONENTS]; 264*dfc6aa5cSAndroid Build Coastguard Worker }; 265*dfc6aa5cSAndroid Build Coastguard Worker 266*dfc6aa5cSAndroid Build Coastguard Worker /* Upsampling (note that upsampler must also call color converter) */ 267*dfc6aa5cSAndroid Build Coastguard Worker struct jpeg_upsampler { 268*dfc6aa5cSAndroid Build Coastguard Worker void (*start_pass) (j_decompress_ptr cinfo); 269*dfc6aa5cSAndroid Build Coastguard Worker void (*upsample) (j_decompress_ptr cinfo, JSAMPIMAGE input_buf, 270*dfc6aa5cSAndroid Build Coastguard Worker JDIMENSION *in_row_group_ctr, 271*dfc6aa5cSAndroid Build Coastguard Worker JDIMENSION in_row_groups_avail, JSAMPARRAY output_buf, 272*dfc6aa5cSAndroid Build Coastguard Worker JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail); 273*dfc6aa5cSAndroid Build Coastguard Worker 274*dfc6aa5cSAndroid Build Coastguard Worker boolean need_context_rows; /* TRUE if need rows above & below */ 275*dfc6aa5cSAndroid Build Coastguard Worker }; 276*dfc6aa5cSAndroid Build Coastguard Worker 277*dfc6aa5cSAndroid Build Coastguard Worker /* Colorspace conversion */ 278*dfc6aa5cSAndroid Build Coastguard Worker struct jpeg_color_deconverter { 279*dfc6aa5cSAndroid Build Coastguard Worker void (*start_pass) (j_decompress_ptr cinfo); 280*dfc6aa5cSAndroid Build Coastguard Worker void (*color_convert) (j_decompress_ptr cinfo, JSAMPIMAGE input_buf, 281*dfc6aa5cSAndroid Build Coastguard Worker JDIMENSION input_row, JSAMPARRAY output_buf, 282*dfc6aa5cSAndroid Build Coastguard Worker int num_rows); 283*dfc6aa5cSAndroid Build Coastguard Worker }; 284*dfc6aa5cSAndroid Build Coastguard Worker 285*dfc6aa5cSAndroid Build Coastguard Worker /* Color quantization or color precision reduction */ 286*dfc6aa5cSAndroid Build Coastguard Worker struct jpeg_color_quantizer { 287*dfc6aa5cSAndroid Build Coastguard Worker void (*start_pass) (j_decompress_ptr cinfo, boolean is_pre_scan); 288*dfc6aa5cSAndroid Build Coastguard Worker void (*color_quantize) (j_decompress_ptr cinfo, JSAMPARRAY input_buf, 289*dfc6aa5cSAndroid Build Coastguard Worker JSAMPARRAY output_buf, int num_rows); 290*dfc6aa5cSAndroid Build Coastguard Worker void (*finish_pass) (j_decompress_ptr cinfo); 291*dfc6aa5cSAndroid Build Coastguard Worker void (*new_color_map) (j_decompress_ptr cinfo); 292*dfc6aa5cSAndroid Build Coastguard Worker }; 293*dfc6aa5cSAndroid Build Coastguard Worker 294*dfc6aa5cSAndroid Build Coastguard Worker 295*dfc6aa5cSAndroid Build Coastguard Worker /* Miscellaneous useful macros */ 296*dfc6aa5cSAndroid Build Coastguard Worker 297*dfc6aa5cSAndroid Build Coastguard Worker #undef MAX 298*dfc6aa5cSAndroid Build Coastguard Worker #define MAX(a, b) ((a) > (b) ? (a) : (b)) 299*dfc6aa5cSAndroid Build Coastguard Worker #undef MIN 300*dfc6aa5cSAndroid Build Coastguard Worker #define MIN(a, b) ((a) < (b) ? (a) : (b)) 301*dfc6aa5cSAndroid Build Coastguard Worker 302*dfc6aa5cSAndroid Build Coastguard Worker 303*dfc6aa5cSAndroid Build Coastguard Worker /* We assume that right shift corresponds to signed division by 2 with 304*dfc6aa5cSAndroid Build Coastguard Worker * rounding towards minus infinity. This is correct for typical "arithmetic 305*dfc6aa5cSAndroid Build Coastguard Worker * shift" instructions that shift in copies of the sign bit. But some 306*dfc6aa5cSAndroid Build Coastguard Worker * C compilers implement >> with an unsigned shift. For these machines you 307*dfc6aa5cSAndroid Build Coastguard Worker * must define RIGHT_SHIFT_IS_UNSIGNED. 308*dfc6aa5cSAndroid Build Coastguard Worker * RIGHT_SHIFT provides a proper signed right shift of a JLONG quantity. 309*dfc6aa5cSAndroid Build Coastguard Worker * It is only applied with constant shift counts. SHIFT_TEMPS must be 310*dfc6aa5cSAndroid Build Coastguard Worker * included in the variables of any routine using RIGHT_SHIFT. 311*dfc6aa5cSAndroid Build Coastguard Worker */ 312*dfc6aa5cSAndroid Build Coastguard Worker 313*dfc6aa5cSAndroid Build Coastguard Worker #ifdef RIGHT_SHIFT_IS_UNSIGNED 314*dfc6aa5cSAndroid Build Coastguard Worker #define SHIFT_TEMPS JLONG shift_temp; 315*dfc6aa5cSAndroid Build Coastguard Worker #define RIGHT_SHIFT(x, shft) \ 316*dfc6aa5cSAndroid Build Coastguard Worker ((shift_temp = (x)) < 0 ? \ 317*dfc6aa5cSAndroid Build Coastguard Worker (shift_temp >> (shft)) | ((~((JLONG)0)) << (32 - (shft))) : \ 318*dfc6aa5cSAndroid Build Coastguard Worker (shift_temp >> (shft))) 319*dfc6aa5cSAndroid Build Coastguard Worker #else 320*dfc6aa5cSAndroid Build Coastguard Worker #define SHIFT_TEMPS 321*dfc6aa5cSAndroid Build Coastguard Worker #define RIGHT_SHIFT(x, shft) ((x) >> (shft)) 322*dfc6aa5cSAndroid Build Coastguard Worker #endif 323*dfc6aa5cSAndroid Build Coastguard Worker 324*dfc6aa5cSAndroid Build Coastguard Worker 325*dfc6aa5cSAndroid Build Coastguard Worker /* Compression module initialization routines */ 326*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jinit_compress_master(j_compress_ptr cinfo); 327*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jinit_c_master_control(j_compress_ptr cinfo, 328*dfc6aa5cSAndroid Build Coastguard Worker boolean transcode_only); 329*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jinit_c_main_controller(j_compress_ptr cinfo, 330*dfc6aa5cSAndroid Build Coastguard Worker boolean need_full_buffer); 331*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jinit_c_prep_controller(j_compress_ptr cinfo, 332*dfc6aa5cSAndroid Build Coastguard Worker boolean need_full_buffer); 333*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jinit_c_coef_controller(j_compress_ptr cinfo, 334*dfc6aa5cSAndroid Build Coastguard Worker boolean need_full_buffer); 335*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jinit_color_converter(j_compress_ptr cinfo); 336*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jinit_downsampler(j_compress_ptr cinfo); 337*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jinit_forward_dct(j_compress_ptr cinfo); 338*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jinit_huff_encoder(j_compress_ptr cinfo); 339*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jinit_phuff_encoder(j_compress_ptr cinfo); 340*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jinit_arith_encoder(j_compress_ptr cinfo); 341*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jinit_marker_writer(j_compress_ptr cinfo); 342*dfc6aa5cSAndroid Build Coastguard Worker /* Decompression module initialization routines */ 343*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jinit_master_decompress(j_decompress_ptr cinfo); 344*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jinit_d_main_controller(j_decompress_ptr cinfo, 345*dfc6aa5cSAndroid Build Coastguard Worker boolean need_full_buffer); 346*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jinit_d_coef_controller(j_decompress_ptr cinfo, 347*dfc6aa5cSAndroid Build Coastguard Worker boolean need_full_buffer); 348*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jinit_d_post_controller(j_decompress_ptr cinfo, 349*dfc6aa5cSAndroid Build Coastguard Worker boolean need_full_buffer); 350*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jinit_input_controller(j_decompress_ptr cinfo); 351*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jinit_marker_reader(j_decompress_ptr cinfo); 352*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jinit_huff_decoder(j_decompress_ptr cinfo); 353*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jinit_phuff_decoder(j_decompress_ptr cinfo); 354*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jinit_arith_decoder(j_decompress_ptr cinfo); 355*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jinit_inverse_dct(j_decompress_ptr cinfo); 356*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jinit_upsampler(j_decompress_ptr cinfo); 357*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jinit_color_deconverter(j_decompress_ptr cinfo); 358*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jinit_1pass_quantizer(j_decompress_ptr cinfo); 359*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jinit_2pass_quantizer(j_decompress_ptr cinfo); 360*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jinit_merged_upsampler(j_decompress_ptr cinfo); 361*dfc6aa5cSAndroid Build Coastguard Worker /* Memory manager initialization */ 362*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jinit_memory_mgr(j_common_ptr cinfo); 363*dfc6aa5cSAndroid Build Coastguard Worker 364*dfc6aa5cSAndroid Build Coastguard Worker /* Utility routines in jutils.c */ 365*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(long) jdiv_round_up(long a, long b); 366*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(long) jround_up(long a, long b); 367*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jcopy_sample_rows(JSAMPARRAY input_array, int source_row, 368*dfc6aa5cSAndroid Build Coastguard Worker JSAMPARRAY output_array, int dest_row, 369*dfc6aa5cSAndroid Build Coastguard Worker int num_rows, JDIMENSION num_cols); 370*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jcopy_block_row(JBLOCKROW input_row, JBLOCKROW output_row, 371*dfc6aa5cSAndroid Build Coastguard Worker JDIMENSION num_blocks); 372*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jzero_far(void *target, size_t bytestozero); 373*dfc6aa5cSAndroid Build Coastguard Worker /* Constant tables in jutils.c */ 374*dfc6aa5cSAndroid Build Coastguard Worker #if 0 /* This table is not actually needed in v6a */ 375*dfc6aa5cSAndroid Build Coastguard Worker extern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */ 376*dfc6aa5cSAndroid Build Coastguard Worker #endif 377*dfc6aa5cSAndroid Build Coastguard Worker extern const int jpeg_natural_order[]; /* zigzag coef order to natural order */ 378*dfc6aa5cSAndroid Build Coastguard Worker 379*dfc6aa5cSAndroid Build Coastguard Worker /* Arithmetic coding probability estimation tables in jaricom.c */ 380*dfc6aa5cSAndroid Build Coastguard Worker extern const JLONG jpeg_aritab[]; 381