blob: 7bf9ffe952589882f635ecd75e92ef55ade88131 [file] [log] [blame]
Dees_Troy51a0e822012-09-05 15:24:24 -04001/*
2 * jpegint.h
3 *
4 * Copyright (C) 1991-1997, Thomas G. Lane.
5 * Copyright (c) 2010, Code Aurora Forum. All rights reserved.
6 * This file is part of the Independent JPEG Group's software.
7 * For conditions of distribution and use, see the accompanying README file.
8 *
9 * This file provides common declarations for the various JPEG modules.
10 * These declarations are considered internal to the JPEG library; most
11 * applications using the library shouldn't need to include this file.
12 */
13
14
15/* Declarations for both compression & decompression */
16
17typedef enum { /* Operating modes for buffer controllers */
18 JBUF_PASS_THRU, /* Plain stripwise operation */
19 /* Remaining modes require a full-image buffer to have been created */
20 JBUF_SAVE_SOURCE, /* Run source subobject only, save output */
21 JBUF_CRANK_DEST, /* Run dest subobject only, using saved data */
22 JBUF_SAVE_AND_PASS /* Run both subobjects, save output */
23} J_BUF_MODE;
24
25/* Values of global_state field (jdapi.c has some dependencies on ordering!) */
26#define CSTATE_START 100 /* after create_compress */
27#define CSTATE_SCANNING 101 /* start_compress done, write_scanlines OK */
28#define CSTATE_RAW_OK 102 /* start_compress done, write_raw_data OK */
29#define CSTATE_WRCOEFS 103 /* jpeg_write_coefficients done */
30#define DSTATE_START 200 /* after create_decompress */
31#define DSTATE_INHEADER 201 /* reading header markers, no SOS yet */
32#define DSTATE_READY 202 /* found SOS, ready for start_decompress */
33#define DSTATE_PRELOAD 203 /* reading multiscan file in start_decompress*/
34#define DSTATE_PRESCAN 204 /* performing dummy pass for 2-pass quant */
35#define DSTATE_SCANNING 205 /* start_decompress done, read_scanlines OK */
36#define DSTATE_RAW_OK 206 /* start_decompress done, read_raw_data OK */
37#define DSTATE_BUFIMAGE 207 /* expecting jpeg_start_output */
38#define DSTATE_BUFPOST 208 /* looking for SOS/EOI in jpeg_finish_output */
39#define DSTATE_RDCOEFS 209 /* reading file in jpeg_read_coefficients */
40#define DSTATE_STOPPING 210 /* looking for EOI in jpeg_finish_decompress */
41
42
43/* Declarations for compression modules */
44
45/* Master control module */
46struct jpeg_comp_master {
47 JMETHOD(void, prepare_for_pass, (j_compress_ptr cinfo));
48 JMETHOD(void, pass_startup, (j_compress_ptr cinfo));
49 JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
50
51 /* State variables made visible to other modules */
52 boolean call_pass_startup; /* True if pass_startup must be called */
53 boolean is_last_pass; /* True during last pass */
54};
55
56/* Main buffer control (downsampled-data buffer) */
57struct jpeg_c_main_controller {
58 JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
59 JMETHOD(void, process_data, (j_compress_ptr cinfo,
60 JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
61 JDIMENSION in_rows_avail));
62};
63
64/* Compression preprocessing (downsampling input buffer control) */
65struct jpeg_c_prep_controller {
66 JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
67 JMETHOD(void, pre_process_data, (j_compress_ptr cinfo,
68 JSAMPARRAY input_buf,
69 JDIMENSION *in_row_ctr,
70 JDIMENSION in_rows_avail,
71 JSAMPIMAGE output_buf,
72 JDIMENSION *out_row_group_ctr,
73 JDIMENSION out_row_groups_avail));
74};
75
76/* Coefficient buffer control */
77struct jpeg_c_coef_controller {
78 JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
79 JMETHOD(boolean, compress_data, (j_compress_ptr cinfo,
80 JSAMPIMAGE input_buf));
81};
82
83/* Colorspace conversion */
84struct jpeg_color_converter {
85 JMETHOD(void, start_pass, (j_compress_ptr cinfo));
86 JMETHOD(void, color_convert, (j_compress_ptr cinfo,
87 JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
88 JDIMENSION output_row, int num_rows));
89};
90
91/* Downsampling */
92struct jpeg_downsampler {
93 JMETHOD(void, start_pass, (j_compress_ptr cinfo));
94 JMETHOD(void, downsample, (j_compress_ptr cinfo,
95 JSAMPIMAGE input_buf, JDIMENSION in_row_index,
96 JSAMPIMAGE output_buf,
97 JDIMENSION out_row_group_index));
98
99 boolean need_context_rows; /* TRUE if need rows above & below */
100};
101
102/* Forward DCT (also controls coefficient quantization) */
103struct jpeg_forward_dct {
104 JMETHOD(void, start_pass, (j_compress_ptr cinfo));
105 /* perhaps this should be an array??? */
106 JMETHOD(void, forward_DCT, (j_compress_ptr cinfo,
107 jpeg_component_info * compptr,
108 JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
109 JDIMENSION start_row, JDIMENSION start_col,
110 JDIMENSION num_blocks));
111};
112
113/* Entropy encoding */
114struct jpeg_entropy_encoder {
115 JMETHOD(void, start_pass, (j_compress_ptr cinfo, boolean gather_statistics));
116 JMETHOD(boolean, encode_mcu, (j_compress_ptr cinfo, JBLOCKROW *MCU_data));
117 JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
118};
119
120/* Marker writing */
121struct jpeg_marker_writer {
122 JMETHOD(void, write_file_header, (j_compress_ptr cinfo));
123 JMETHOD(void, write_frame_header, (j_compress_ptr cinfo));
124 JMETHOD(void, write_scan_header, (j_compress_ptr cinfo));
125 JMETHOD(void, write_file_trailer, (j_compress_ptr cinfo));
126 JMETHOD(void, write_tables_only, (j_compress_ptr cinfo));
127 /* These routines are exported to allow insertion of extra markers */
128 /* Probably only COM and APPn markers should be written this way */
129 JMETHOD(void, write_marker_header, (j_compress_ptr cinfo, int marker,
130 unsigned int datalen));
131 JMETHOD(void, write_marker_byte, (j_compress_ptr cinfo, int val));
132};
133
134
135/* Declarations for decompression modules */
136
137/* Master control module */
138struct jpeg_decomp_master {
139 JMETHOD(void, prepare_for_output_pass, (j_decompress_ptr cinfo));
140 JMETHOD(void, finish_output_pass, (j_decompress_ptr cinfo));
141
142 /* State variables made visible to other modules */
143 boolean is_dummy_pass; /* True during 1st pass for 2-pass quant */
144};
145
146/* Input control module */
147struct jpeg_input_controller {
148 JMETHOD(int, consume_input, (j_decompress_ptr cinfo));
149 JMETHOD(int, consume_input_build_huffman_index, (j_decompress_ptr cinfo,
150 huffman_index *index, int scan_count));
151 JMETHOD(int, consume_markers, (j_decompress_ptr cinfo,
152 huffman_index *index, int scan_count));
153 JMETHOD(void, reset_input_controller, (j_decompress_ptr cinfo));
154 JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
155 JMETHOD(void, finish_input_pass, (j_decompress_ptr cinfo));
156
157 /* State variables made visible to other modules */
158 boolean has_multiple_scans; /* True if file has multiple scans */
159 boolean eoi_reached; /* True when EOI has been consumed */
160};
161
162/* Main buffer control (downsampled-data buffer) */
163struct jpeg_d_main_controller {
164 JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
165 JMETHOD(void, process_data, (j_decompress_ptr cinfo,
166 JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
167 JDIMENSION out_rows_avail));
168};
169
170/* Coefficient buffer control */
171struct jpeg_d_coef_controller {
172 JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
173 JMETHOD(int, consume_data, (j_decompress_ptr cinfo));
174 JMETHOD(int, consume_data_build_huffman_index, (j_decompress_ptr cinfo,
175 huffman_index* index, int scan_count));
176 JMETHOD(void, start_output_pass, (j_decompress_ptr cinfo));
177 JMETHOD(int, decompress_data, (j_decompress_ptr cinfo,
178 JSAMPIMAGE output_buf));
179 /* Pointer to array of coefficient virtual arrays, or NULL if none */
180 jvirt_barray_ptr *coef_arrays;
181
182 /* column number of the first and last tile, respectively */
183 int column_left_boundary;
184 int column_right_boundary;
185
186 /* column number of the first and last MCU, respectively */
187 int MCU_column_left_boundary;
188 int MCU_column_right_boundary;
189
190 /* the number of MCU columns to skip from the indexed MCU, iM,
191 * to the requested MCU boundary, rM, where iM is the MCU that we sample
192 * into our index and is the nearest one to the left of rM.
193 */
194 int MCU_columns_to_skip;
195};
196
197/* Decompression postprocessing (color quantization buffer control) */
198struct jpeg_d_post_controller {
199 JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
200 JMETHOD(void, post_process_data, (j_decompress_ptr cinfo,
201 JSAMPIMAGE input_buf,
202 JDIMENSION *in_row_group_ctr,
203 JDIMENSION in_row_groups_avail,
204 JSAMPARRAY output_buf,
205 JDIMENSION *out_row_ctr,
206 JDIMENSION out_rows_avail));
207};
208
209/* Marker reading & parsing */
210struct jpeg_marker_reader {
211 JMETHOD(void, reset_marker_reader, (j_decompress_ptr cinfo));
212 /* Read markers until SOS or EOI.
213 * Returns same codes as are defined for jpeg_consume_input:
214 * JPEG_SUSPENDED, JPEG_REACHED_SOS, or JPEG_REACHED_EOI.
215 */
216 JMETHOD(int, read_markers, (j_decompress_ptr cinfo));
217 JMETHOD(void, get_sos_marker_position, (j_decompress_ptr cinfo,
218 huffman_index *index));
219 /* Read a restart marker --- exported for use by entropy decoder only */
220 jpeg_marker_parser_method read_restart_marker;
221
222 /* State of marker reader --- nominally internal, but applications
223 * supplying COM or APPn handlers might like to know the state.
224 */
225 boolean saw_SOI; /* found SOI? */
226 boolean saw_SOF; /* found SOF? */
227 int next_restart_num; /* next restart number expected (0-7) */
228 int current_sos_marker_position;
229 unsigned int discarded_bytes; /* # of bytes skipped looking for a marker */
230};
231
232/* Entropy decoding */
233struct jpeg_entropy_decoder {
234 JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
235 JMETHOD(boolean, decode_mcu, (j_decompress_ptr cinfo,
236 JBLOCKROW *MCU_data));
237 JMETHOD(boolean, decode_mcu_discard_coef, (j_decompress_ptr cinfo));
238 JMETHOD(void, configure_huffman_decoder, (j_decompress_ptr cinfo,
239 huffman_offset_data offset));
240 JMETHOD(void, get_huffman_decoder_configuration, (j_decompress_ptr cinfo,
241 huffman_offset_data *offset));
242
243 /* This is here to share code between baseline and progressive decoders; */
244 /* other modules probably should not use it */
245 boolean insufficient_data; /* set TRUE after emitting warning */
246
247 huffman_index *index;
248};
249
250/* Inverse DCT (also performs dequantization) */
251typedef JMETHOD(void, inverse_DCT_method_ptr,
252 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
253 JCOEFPTR coef_block,
254 JSAMPARRAY output_buf, JDIMENSION output_col));
255
256struct jpeg_inverse_dct {
257 JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
258 /* It is useful to allow each component to have a separate IDCT method. */
259 inverse_DCT_method_ptr inverse_DCT[MAX_COMPONENTS];
260};
261
262/* Upsampling (note that upsampler must also call color converter) */
263struct jpeg_upsampler {
264 JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
265 JMETHOD(void, upsample, (j_decompress_ptr cinfo,
266 JSAMPIMAGE input_buf,
267 JDIMENSION *in_row_group_ctr,
268 JDIMENSION in_row_groups_avail,
269 JSAMPARRAY output_buf,
270 JDIMENSION *out_row_ctr,
271 JDIMENSION out_rows_avail));
272
273 boolean need_context_rows; /* TRUE if need rows above & below */
274};
275
276/* Colorspace conversion */
277struct jpeg_color_deconverter {
278 JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
279 JMETHOD(void, color_convert, (j_decompress_ptr cinfo,
280 JSAMPIMAGE input_buf, JDIMENSION input_row,
281 JSAMPARRAY output_buf, int num_rows));
282};
283
284/* Color quantization or color precision reduction */
285struct jpeg_color_quantizer {
286 JMETHOD(void, start_pass, (j_decompress_ptr cinfo, boolean is_pre_scan));
287 JMETHOD(void, color_quantize, (j_decompress_ptr cinfo,
288 JSAMPARRAY input_buf, JSAMPARRAY output_buf,
289 int num_rows));
290 JMETHOD(void, finish_pass, (j_decompress_ptr cinfo));
291 JMETHOD(void, new_color_map, (j_decompress_ptr cinfo));
292};
293
294#ifdef ANDROID_JPEG_USE_VENUM
295
296/* IDCT routines */
297EXTERN (void) idct_1x1_venum (INT16 * coeffPtr, INT16 * samplePtr, INT32 stride);
298EXTERN (void) idct_2x2_venum (INT16 * coeffPtr, INT16 * samplePtr, INT32 stride);
299EXTERN (void) idct_4x4_venum (INT16 * coeffPtr, INT16 * samplePtr, INT32 stride);
300EXTERN (void) idct_8x8_venum (INT16 * coeffPtr, INT16 * samplePtr, INT32 stride);
301
302#ifndef ANDROID_JPEG_DISABLE_VENUM_YCC_RGB_565
303/* Color conversion routines */
304EXTERN (void) yvup2rgb565_venum (UINT8 *pLumaLine,
305 UINT8 *pCrLine,
306 UINT8 *pCbLine,
307 UINT8 *pRGB565Line,
308 JDIMENSION nLineWidth);
309EXTERN (void) yyvup2rgb565_venum (UINT8 * pLumaLine,
310 UINT8 *pCrLine,
311 UINT8 *pCbLine,
312 UINT8 * pRGB565Line,
313 JDIMENSION nLineWidth);
314#endif
315EXTERN (void) yvup2bgr888_venum (UINT8 * pLumaLine,
316 UINT8 *pCrLine,
317 UINT8 *pCbLine,
318 UINT8 * pBGR888Line,
319 JDIMENSION nLineWidth);
320EXTERN (void) yyvup2bgr888_venum (UINT8 * pLumaLine,
321 UINT8 *pCrLine,
322 UINT8 *pCbLine,
323 UINT8 * pBGR888Line,
324 JDIMENSION nLineWidth);
325EXTERN (void) yvup2abgr8888_venum (UINT8 * pLumaLine,
326 UINT8 *pCrLine,
327 UINT8 *pCbLine,
328 UINT8 * pABGR888Line,
329 JDIMENSION nLineWidth);
330EXTERN (void) yyvup2abgr8888_venum (UINT8 * pLumaLine,
331 UINT8 *pCrLine,
332 UINT8 *pCbLine,
333 UINT8 * pABGR888Line,
334 JDIMENSION nLineWidth);
335#endif
336
337/* Miscellaneous useful macros */
338
339#undef MAX
340#define MAX(a,b) ((a) > (b) ? (a) : (b))
341#undef MIN
342#define MIN(a,b) ((a) < (b) ? (a) : (b))
343
344
345/* We assume that right shift corresponds to signed division by 2 with
346 * rounding towards minus infinity. This is correct for typical "arithmetic
347 * shift" instructions that shift in copies of the sign bit. But some
348 * C compilers implement >> with an unsigned shift. For these machines you
349 * must define RIGHT_SHIFT_IS_UNSIGNED.
350 * RIGHT_SHIFT provides a proper signed right shift of an INT32 quantity.
351 * It is only applied with constant shift counts. SHIFT_TEMPS must be
352 * included in the variables of any routine using RIGHT_SHIFT.
353 */
354
355#ifdef RIGHT_SHIFT_IS_UNSIGNED
356#define SHIFT_TEMPS INT32 shift_temp;
357#define RIGHT_SHIFT(x,shft) \
358 ((shift_temp = (x)) < 0 ? \
359 (shift_temp >> (shft)) | ((~((INT32) 0)) << (32-(shft))) : \
360 (shift_temp >> (shft)))
361#else
362#define SHIFT_TEMPS
363#define RIGHT_SHIFT(x,shft) ((x) >> (shft))
364#endif
365
366
367/* Short forms of external names for systems with brain-damaged linkers. */
368
369#ifdef NEED_SHORT_EXTERNAL_NAMES
370#define jinit_compress_master jICompress
371#define jinit_c_master_control jICMaster
372#define jinit_c_main_controller jICMainC
373#define jinit_c_prep_controller jICPrepC
374#define jinit_c_coef_controller jICCoefC
375#define jinit_color_converter jICColor
376#define jinit_downsampler jIDownsampler
377#define jinit_forward_dct jIFDCT
378#define jinit_huff_encoder jIHEncoder
379#define jinit_phuff_encoder jIPHEncoder
380#define jinit_marker_writer jIMWriter
381#define jinit_master_decompress jIDMaster
382#define jinit_d_main_controller jIDMainC
383#define jinit_d_coef_controller jIDCoefC
384#define jinit_d_post_controller jIDPostC
385#define jinit_input_controller jIInCtlr
386#define jinit_marker_reader jIMReader
387#define jinit_huff_decoder jIHDecoder
388#define jinit_phuff_decoder jIPHDecoder
389#define jinit_inverse_dct jIIDCT
390#define jinit_upsampler jIUpsampler
391#define jinit_color_deconverter jIDColor
392#define jinit_1pass_quantizer jI1Quant
393#define jinit_2pass_quantizer jI2Quant
394#define jinit_merged_upsampler jIMUpsampler
395#define jinit_memory_mgr jIMemMgr
396#define jdiv_round_up jDivRound
397#define jround_up jRound
398#define jcopy_sample_rows jCopySamples
399#define jcopy_block_row jCopyBlocks
400#define jzero_far jZeroFar
401#define jpeg_zigzag_order jZIGTable
402#define jpeg_natural_order jZAGTable
403#endif /* NEED_SHORT_EXTERNAL_NAMES */
404
405
406/* Compression module initialization routines */
407EXTERN(void) jinit_compress_master JPP((j_compress_ptr cinfo));
408EXTERN(void) jinit_c_master_control JPP((j_compress_ptr cinfo,
409 boolean transcode_only));
410EXTERN(void) jinit_c_main_controller JPP((j_compress_ptr cinfo,
411 boolean need_full_buffer));
412EXTERN(void) jinit_c_prep_controller JPP((j_compress_ptr cinfo,
413 boolean need_full_buffer));
414EXTERN(void) jinit_c_coef_controller JPP((j_compress_ptr cinfo,
415 boolean need_full_buffer));
416EXTERN(void) jinit_color_converter JPP((j_compress_ptr cinfo));
417EXTERN(void) jinit_downsampler JPP((j_compress_ptr cinfo));
418EXTERN(void) jinit_forward_dct JPP((j_compress_ptr cinfo));
419EXTERN(void) jinit_huff_encoder JPP((j_compress_ptr cinfo));
420EXTERN(void) jinit_phuff_encoder JPP((j_compress_ptr cinfo));
421EXTERN(void) jinit_marker_writer JPP((j_compress_ptr cinfo));
422/* Decompression module initialization routines */
423EXTERN(void) jinit_master_decompress JPP((j_decompress_ptr cinfo));
424EXTERN(void) jinit_d_main_controller JPP((j_decompress_ptr cinfo,
425 boolean need_full_buffer));
426EXTERN(void) jinit_d_coef_controller JPP((j_decompress_ptr cinfo,
427 boolean need_full_buffer));
428EXTERN(void) jinit_d_post_controller JPP((j_decompress_ptr cinfo,
429 boolean need_full_buffer));
430EXTERN(void) jinit_input_controller JPP((j_decompress_ptr cinfo));
431EXTERN(void) jinit_marker_reader JPP((j_decompress_ptr cinfo));
432EXTERN(void) jinit_huff_decoder JPP((j_decompress_ptr cinfo));
433EXTERN(void) jinit_huff_decoder_no_data JPP((j_decompress_ptr cinfo));
434EXTERN(void) jinit_phuff_decoder JPP((j_decompress_ptr cinfo));
435EXTERN(void) jinit_inverse_dct JPP((j_decompress_ptr cinfo));
436EXTERN(void) jinit_upsampler JPP((j_decompress_ptr cinfo));
437EXTERN(void) jinit_color_deconverter JPP((j_decompress_ptr cinfo));
438EXTERN(void) jinit_1pass_quantizer JPP((j_decompress_ptr cinfo));
439EXTERN(void) jinit_2pass_quantizer JPP((j_decompress_ptr cinfo));
440EXTERN(void) jinit_merged_upsampler JPP((j_decompress_ptr cinfo));
441EXTERN(void) jpeg_decompress_per_scan_setup (j_decompress_ptr cinfo);
442/* Memory manager initialization */
443EXTERN(void) jinit_memory_mgr JPP((j_common_ptr cinfo));
444
445/* Utility routines in jutils.c */
446EXTERN(long) jdiv_round_up JPP((long a, long b));
447EXTERN(long) jround_up JPP((long a, long b));
448EXTERN(long) jmin JPP((long a, long b));
449EXTERN(void) jcopy_sample_rows JPP((JSAMPARRAY input_array, int source_row,
450 JSAMPARRAY output_array, int dest_row,
451 int num_rows, JDIMENSION num_cols));
452EXTERN(void) jcopy_block_row JPP((JBLOCKROW input_row, JBLOCKROW output_row,
453 JDIMENSION num_blocks));
454EXTERN(void) jzero_far JPP((void FAR * target, size_t bytestozero));
455
456EXTERN(void) jset_input_stream_position JPP((j_decompress_ptr cinfo,
457 int offset));
458EXTERN(void) jset_input_stream_position_bit JPP((j_decompress_ptr cinfo,
459 int byte_offset, int bit_left, INT32 buf));
460
461EXTERN(int) jget_input_stream_position JPP((j_decompress_ptr cinfo));
462/* Constant tables in jutils.c */
463#if 0 /* This table is not actually needed in v6a */
464extern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */
465#endif
466extern const int jpeg_natural_order[]; /* zigzag coef order to natural order */
467
468/* Suppress undefined-structure complaints if necessary. */
469
470#ifdef INCOMPLETE_TYPES_BROKEN
471#ifndef AM_MEMORY_MANAGER /* only jmemmgr.c defines these */
472struct jvirt_sarray_control { long dummy; };
473struct jvirt_barray_control { long dummy; };
474#endif
475#endif /* INCOMPLETE_TYPES_BROKEN */