Developer World
Spresense SDK Library v3.3.0-375c679
jpegint.h
1/*
2 * jpegint.h
3 *
4 * Copyright (C) 1991-1997, Thomas G. Lane.
5 * Modified 1997-2020 by Guido Vollbeding.
6 * Copyright 2021 Sony Semiconductor Solutions Corporation
7 * This file is part of the Independent JPEG Group's software.
8 * For conditions of distribution and use, see the accompanying README file.
9 *
10 * This file provides common declarations for the various JPEG modules.
11 * These declarations are considered internal to the JPEG library; most
12 * applications using the library shouldn't need to include this file.
13 */
14
15
16/* Modified for Spresense by Sony Semiconductor Solutions. */
17#define SPRESENSE_PORT
18
19/* Declarations for both compression & decompression */
20
21typedef enum { /* Operating modes for buffer controllers */
22 JBUF_PASS_THRU, /* Plain stripwise operation */
23 /* Remaining modes require a full-image buffer to have been created */
24 JBUF_SAVE_SOURCE, /* Run source subobject only, save output */
25 JBUF_CRANK_DEST, /* Run dest subobject only, using saved data */
26 JBUF_SAVE_AND_PASS /* Run both subobjects, save output */
27} J_BUF_MODE;
28
29/* Values of global_state field (jdapi.c has some dependencies on ordering!) */
30#define CSTATE_START 100 /* after create_compress */
31#define CSTATE_SCANNING 101 /* start_compress done, write_scanlines OK */
32#define CSTATE_RAW_OK 102 /* start_compress done, write_raw_data OK */
33#define CSTATE_WRCOEFS 103 /* jpeg_write_coefficients done */
34#define DSTATE_START 200 /* after create_decompress */
35#define DSTATE_INHEADER 201 /* reading header markers, no SOS yet */
36#define DSTATE_READY 202 /* found SOS, ready for start_decompress */
37#define DSTATE_PRELOAD 203 /* reading multiscan file in start_decompress*/
38#define DSTATE_PRESCAN 204 /* performing dummy pass for 2-pass quant */
39#define DSTATE_SCANNING 205 /* start_decompress done, read_scanlines OK */
40#define DSTATE_RAW_OK 206 /* start_decompress done, read_raw_data OK */
41#define DSTATE_BUFIMAGE 207 /* expecting jpeg_start_output */
42#define DSTATE_BUFPOST 208 /* looking for SOS/EOI in jpeg_finish_output */
43#define DSTATE_RDCOEFS 209 /* reading file in jpeg_read_coefficients */
44#define DSTATE_STOPPING 210 /* looking for EOI in jpeg_finish_decompress */
45#ifdef SPRESENSE_PORT
46/* Modified for Spresense by Sony Semiconductor Solutions.
47 * Add state which source has been already set.
48 */
49#define DSTATE_SETSRC 211 /* after stdio_src or mem_src */
50#endif
51
52/* Declarations for compression modules */
53
54/* Master control module */
56 JMETHOD(void, prepare_for_pass, (j_compress_ptr cinfo));
57 JMETHOD(void, pass_startup, (j_compress_ptr cinfo));
58 JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
59
60 /* State variables made visible to other modules */
61 boolean call_pass_startup; /* True if pass_startup must be called */
62 boolean is_last_pass; /* True during last pass */
63};
64
65/* Main buffer control (downsampled-data buffer) */
67 JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
68 JMETHOD(void, process_data, (j_compress_ptr cinfo,
69 JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
70 JDIMENSION in_rows_avail));
71};
72
73/* Compression preprocessing (downsampling input buffer control) */
75 JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
76 JMETHOD(void, pre_process_data, (j_compress_ptr cinfo,
77 JSAMPARRAY input_buf,
78 JDIMENSION *in_row_ctr,
79 JDIMENSION in_rows_avail,
80 JSAMPIMAGE output_buf,
81 JDIMENSION *out_row_group_ctr,
82 JDIMENSION out_row_groups_avail));
83};
84
85/* Coefficient buffer control */
87 JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
88 JMETHOD(boolean, compress_data, (j_compress_ptr cinfo,
89 JSAMPIMAGE input_buf));
90};
91
92/* Colorspace conversion */
94 JMETHOD(void, start_pass, (j_compress_ptr cinfo));
95 JMETHOD(void, color_convert, (j_compress_ptr cinfo,
96 JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
97 JDIMENSION output_row, int num_rows));
98};
99
100/* Downsampling */
102 JMETHOD(void, start_pass, (j_compress_ptr cinfo));
103 JMETHOD(void, downsample, (j_compress_ptr cinfo,
104 JSAMPIMAGE input_buf, JDIMENSION in_row_index,
105 JSAMPIMAGE output_buf,
106 JDIMENSION out_row_group_index));
107
108 boolean need_context_rows; /* TRUE if need rows above & below */
109};
110
111/* Forward DCT (also controls coefficient quantization) */
112typedef JMETHOD(void, forward_DCT_ptr,
113 (j_compress_ptr cinfo, jpeg_component_info * compptr,
114 JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
115 JDIMENSION start_col, JDIMENSION num_blocks));
116
118 JMETHOD(void, start_pass, (j_compress_ptr cinfo));
119 /* It is useful to allow each component to have a separate FDCT method. */
120 forward_DCT_ptr forward_DCT[MAX_COMPONENTS];
121};
122
123/* Entropy encoding */
125 JMETHOD(void, start_pass, (j_compress_ptr cinfo, boolean gather_statistics));
126 JMETHOD(boolean, encode_mcu, (j_compress_ptr cinfo, JBLOCKARRAY MCU_data));
127 JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
128};
129
130/* Marker writing */
132 JMETHOD(void, write_file_header, (j_compress_ptr cinfo));
133 JMETHOD(void, write_frame_header, (j_compress_ptr cinfo));
134 JMETHOD(void, write_scan_header, (j_compress_ptr cinfo));
135 JMETHOD(void, write_file_trailer, (j_compress_ptr cinfo));
136 JMETHOD(void, write_tables_only, (j_compress_ptr cinfo));
137 /* These routines are exported to allow insertion of extra markers */
138 /* Probably only COM and APPn markers should be written this way */
139 JMETHOD(void, write_marker_header, (j_compress_ptr cinfo, int marker,
140 unsigned int datalen));
141 JMETHOD(void, write_marker_byte, (j_compress_ptr cinfo, int val));
142};
143
144
145/* Declarations for decompression modules */
146
147/* Master control module */
149 JMETHOD(void, prepare_for_output_pass, (j_decompress_ptr cinfo));
150 JMETHOD(void, finish_output_pass, (j_decompress_ptr cinfo));
151
152 /* State variables made visible to other modules */
153 boolean is_dummy_pass; /* True during 1st pass for 2-pass quant */
154};
155
156/* Input control module */
158 JMETHOD(int, consume_input, (j_decompress_ptr cinfo));
159 JMETHOD(void, reset_input_controller, (j_decompress_ptr cinfo));
160 JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
161 JMETHOD(void, finish_input_pass, (j_decompress_ptr cinfo));
162
163 /* State variables made visible to other modules */
164 boolean has_multiple_scans; /* True if file has multiple scans */
165 boolean eoi_reached; /* True when EOI has been consumed */
166};
167
168/* Main buffer control (downsampled-data buffer) */
170 JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
171 JMETHOD(void, process_data, (j_decompress_ptr cinfo,
172 JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
173 JDIMENSION out_rows_avail));
174};
175
176/* Coefficient buffer control */
178 JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
179 JMETHOD(int, consume_data, (j_decompress_ptr cinfo));
180 JMETHOD(void, start_output_pass, (j_decompress_ptr cinfo));
181 JMETHOD(int, decompress_data, (j_decompress_ptr cinfo,
182 JSAMPIMAGE output_buf));
183 /* Pointer to array of coefficient virtual arrays, or NULL if none */
184 jvirt_barray_ptr *coef_arrays;
185};
186
187/* Decompression postprocessing (color quantization buffer control) */
189 JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
190 JMETHOD(void, post_process_data, (j_decompress_ptr cinfo,
191 JSAMPIMAGE input_buf,
192 JDIMENSION *in_row_group_ctr,
193 JDIMENSION in_row_groups_avail,
194 JSAMPARRAY output_buf,
195 JDIMENSION *out_row_ctr,
196 JDIMENSION out_rows_avail));
197};
198
199/* Marker reading & parsing */
201 JMETHOD(void, reset_marker_reader, (j_decompress_ptr cinfo));
202 /* Read markers until SOS or EOI.
203 * Returns same codes as are defined for jpeg_consume_input:
204 * JPEG_SUSPENDED, JPEG_REACHED_SOS, or JPEG_REACHED_EOI.
205 */
206 JMETHOD(int, read_markers, (j_decompress_ptr cinfo));
207 /* Read a restart marker --- exported for use by entropy decoder only */
208 jpeg_marker_parser_method read_restart_marker;
209
210 /* State of marker reader --- nominally internal, but applications
211 * supplying COM or APPn handlers might like to know the state.
212 */
213 boolean saw_SOI; /* found SOI? */
214 boolean saw_SOF; /* found SOF? */
215 int next_restart_num; /* next restart number expected (0-7) */
216 unsigned int discarded_bytes; /* # of bytes skipped looking for a marker */
217};
218
219/* Entropy decoding */
221 JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
222 JMETHOD(boolean, decode_mcu, (j_decompress_ptr cinfo, JBLOCKARRAY MCU_data));
223 JMETHOD(void, finish_pass, (j_decompress_ptr cinfo));
224};
225
226/* Inverse DCT (also performs dequantization) */
227typedef JMETHOD(void, inverse_DCT_method_ptr,
228 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
229 JCOEFPTR coef_block,
230 JSAMPARRAY output_buf, JDIMENSION output_col));
231
233 JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
234 /* It is useful to allow each component to have a separate IDCT method. */
235 inverse_DCT_method_ptr inverse_DCT[MAX_COMPONENTS];
236};
237
238/* Upsampling (note that upsampler must also call color converter) */
240 JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
241 JMETHOD(void, upsample, (j_decompress_ptr cinfo,
242 JSAMPIMAGE input_buf,
243 JDIMENSION *in_row_group_ctr,
244 JDIMENSION in_row_groups_avail,
245 JSAMPARRAY output_buf,
246 JDIMENSION *out_row_ctr,
247 JDIMENSION out_rows_avail));
248
249 boolean need_context_rows; /* TRUE if need rows above & below */
250};
251
252/* Colorspace conversion */
254 JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
255 JMETHOD(void, color_convert, (j_decompress_ptr cinfo,
256 JSAMPIMAGE input_buf, JDIMENSION input_row,
257 JSAMPARRAY output_buf, int num_rows));
258};
259
260/* Color quantization or color precision reduction */
262 JMETHOD(void, start_pass, (j_decompress_ptr cinfo, boolean is_pre_scan));
263 JMETHOD(void, color_quantize, (j_decompress_ptr cinfo,
264 JSAMPARRAY input_buf, JSAMPARRAY output_buf,
265 int num_rows));
266 JMETHOD(void, finish_pass, (j_decompress_ptr cinfo));
267 JMETHOD(void, new_color_map, (j_decompress_ptr cinfo));
268};
269
270
271/* Definition of range extension bits for decompression processes.
272 * See the comments with prepare_range_limit_table (in jdmaster.c)
273 * for more info.
274 * The recommended default value for normal applications is 2.
275 * Applications with special requirements may use a different value.
276 * For example, Ghostscript wants to use 3 for proper handling of
277 * wacky images with oversize coefficient values.
278 */
279
280#define RANGE_BITS 2
281#define RANGE_CENTER (CENTERJSAMPLE << RANGE_BITS)
282
283
284/* Miscellaneous useful macros */
285
286#undef MAX
287#define MAX(a,b) ((a) > (b) ? (a) : (b))
288#undef MIN
289#define MIN(a,b) ((a) < (b) ? (a) : (b))
290
291
292/* We assume that right shift corresponds to signed division by 2 with
293 * rounding towards minus infinity. This is correct for typical "arithmetic
294 * shift" instructions that shift in copies of the sign bit. But some
295 * C compilers implement >> with an unsigned shift. For these machines you
296 * must define RIGHT_SHIFT_IS_UNSIGNED.
297 * RIGHT_SHIFT provides a proper signed right shift of an INT32 quantity.
298 * It is only applied with constant shift counts. SHIFT_TEMPS must be
299 * included in the variables of any routine using RIGHT_SHIFT.
300 */
301
302#ifdef RIGHT_SHIFT_IS_UNSIGNED
303#define SHIFT_TEMPS INT32 shift_temp;
304#define RIGHT_SHIFT(x,shft) \
305 ((shift_temp = (x)) < 0 ? \
306 (shift_temp >> (shft)) | ((~((INT32) 0)) << (32-(shft))) : \
307 (shift_temp >> (shft)))
308#else
309#define SHIFT_TEMPS
310#define RIGHT_SHIFT(x,shft) ((x) >> (shft))
311#endif
312
313/* Descale and correctly round an INT32 value that's scaled by N bits.
314 * We assume RIGHT_SHIFT rounds towards minus infinity, so adding
315 * the fudge factor is correct for either sign of X.
316 */
317
318#define DESCALE(x,n) RIGHT_SHIFT((x) + ((INT32) 1 << ((n)-1)), n)
319
320
321/* Short forms of external names for systems with brain-damaged linkers. */
322
323#ifdef NEED_SHORT_EXTERNAL_NAMES
324#define jinit_compress_master jICompress
325#define jinit_c_master_control jICMaster
326#define jinit_c_main_controller jICMainC
327#define jinit_c_prep_controller jICPrepC
328#define jinit_c_coef_controller jICCoefC
329#define jinit_color_converter jICColor
330#define jinit_downsampler jIDownsampler
331#define jinit_forward_dct jIFDCT
332#define jinit_huff_encoder jIHEncoder
333#define jinit_arith_encoder jIAEncoder
334#define jinit_marker_writer jIMWriter
335#define jinit_master_decompress jIDMaster
336#define jinit_d_main_controller jIDMainC
337#define jinit_d_coef_controller jIDCoefC
338#define jinit_d_post_controller jIDPostC
339#define jinit_input_controller jIInCtlr
340#define jinit_marker_reader jIMReader
341#define jinit_huff_decoder jIHDecoder
342#define jinit_arith_decoder jIADecoder
343#define jinit_inverse_dct jIIDCT
344#define jinit_upsampler jIUpsampler
345#define jinit_color_deconverter jIDColor
346#define jinit_1pass_quantizer jI1Quant
347#define jinit_2pass_quantizer jI2Quant
348#define jinit_merged_upsampler jIMUpsampler
349#define jinit_memory_mgr jIMemMgr
350#define jdiv_round_up jDivRound
351#define jround_up jRound
352#define jzero_far jZeroFar
353#define jcopy_sample_rows jCopySamples
354#define jcopy_block_row jCopyBlocks
355#define jpeg_zigzag_order jZIGTable
356#define jpeg_natural_order jZAGTable
357#define jpeg_natural_order7 jZAG7Table
358#define jpeg_natural_order6 jZAG6Table
359#define jpeg_natural_order5 jZAG5Table
360#define jpeg_natural_order4 jZAG4Table
361#define jpeg_natural_order3 jZAG3Table
362#define jpeg_natural_order2 jZAG2Table
363#define jpeg_aritab jAriTab
364#endif /* NEED_SHORT_EXTERNAL_NAMES */
365
366
367/* On normal machines we can apply MEMCOPY() and MEMZERO() to sample arrays
368 * and coefficient-block arrays. This won't work on 80x86 because the arrays
369 * are FAR and we're assuming a small-pointer memory model. However, some
370 * DOS compilers provide far-pointer versions of memcpy() and memset() even
371 * in the small-model libraries. These will be used if USE_FMEM is defined.
372 * Otherwise, the routines in jutils.c do it the hard way.
373 */
374
375#ifndef NEED_FAR_POINTERS /* normal case, same as regular macro */
376#define FMEMZERO(target,size) MEMZERO(target,size)
377#else /* 80x86 case */
378#ifdef USE_FMEM
379#define FMEMZERO(target,size) _fmemset((void FAR *)(target), 0, (size_t)(size))
380#else
381EXTERN(void) jzero_far JPP((void FAR * target, size_t bytestozero));
382#define FMEMZERO(target,size) jzero_far(target, size)
383#endif
384#endif
385
386
387/* Compression module initialization routines */
388EXTERN(void) jinit_compress_master JPP((j_compress_ptr cinfo));
389EXTERN(void) jinit_c_master_control JPP((j_compress_ptr cinfo,
390 boolean transcode_only));
391EXTERN(void) jinit_c_main_controller JPP((j_compress_ptr cinfo,
392 boolean need_full_buffer));
393EXTERN(void) jinit_c_prep_controller JPP((j_compress_ptr cinfo,
394 boolean need_full_buffer));
395EXTERN(void) jinit_c_coef_controller JPP((j_compress_ptr cinfo,
396 boolean need_full_buffer));
397EXTERN(void) jinit_color_converter JPP((j_compress_ptr cinfo));
398EXTERN(void) jinit_downsampler JPP((j_compress_ptr cinfo));
399EXTERN(void) jinit_forward_dct JPP((j_compress_ptr cinfo));
400EXTERN(void) jinit_huff_encoder JPP((j_compress_ptr cinfo));
401EXTERN(void) jinit_arith_encoder JPP((j_compress_ptr cinfo));
402EXTERN(void) jinit_marker_writer JPP((j_compress_ptr cinfo));
403/* Decompression module initialization routines */
404EXTERN(void) jinit_master_decompress JPP((j_decompress_ptr cinfo));
405EXTERN(void) jinit_d_main_controller JPP((j_decompress_ptr cinfo,
406 boolean need_full_buffer));
407EXTERN(void) jinit_d_coef_controller JPP((j_decompress_ptr cinfo,
408 boolean need_full_buffer));
409EXTERN(void) jinit_d_post_controller JPP((j_decompress_ptr cinfo,
410 boolean need_full_buffer));
411EXTERN(void) jinit_input_controller JPP((j_decompress_ptr cinfo));
412EXTERN(void) jinit_marker_reader JPP((j_decompress_ptr cinfo));
413EXTERN(void) jinit_huff_decoder JPP((j_decompress_ptr cinfo));
414EXTERN(void) jinit_arith_decoder JPP((j_decompress_ptr cinfo));
415EXTERN(void) jinit_inverse_dct JPP((j_decompress_ptr cinfo));
416EXTERN(void) jinit_upsampler JPP((j_decompress_ptr cinfo));
417EXTERN(void) jinit_color_deconverter JPP((j_decompress_ptr cinfo));
418EXTERN(void) jinit_1pass_quantizer JPP((j_decompress_ptr cinfo));
419EXTERN(void) jinit_2pass_quantizer JPP((j_decompress_ptr cinfo));
420EXTERN(void) jinit_merged_upsampler JPP((j_decompress_ptr cinfo));
421#ifdef SPRESENSE_PORT
422/* Modified for Spresense by Sony Semiconductor Solutions.
423 * MCU decode preparation routines
424 */
425EXTERN(void) jmcu_d_coef_controller JPP((j_decompress_ptr cinfo));
426EXTERN(void) jmcu_upsampler JPP((j_decompress_ptr cinfo));
427EXTERN(void) jmcu_color_deconverter JPP((j_decompress_ptr cinfo));
428#endif
429
430/* Memory manager initialization */
431EXTERN(void) jinit_memory_mgr JPP((j_common_ptr cinfo));
432
433/* Utility routines in jutils.c */
434EXTERN(long) jdiv_round_up JPP((long a, long b));
435EXTERN(long) jround_up JPP((long a, long b));
436EXTERN(void) jcopy_sample_rows JPP((JSAMPARRAY input_array,
437 JSAMPARRAY output_array,
438 int num_rows, JDIMENSION num_cols));
439EXTERN(void) jcopy_block_row JPP((JBLOCKROW input_row, JBLOCKROW output_row,
440 JDIMENSION num_blocks));
441/* Constant tables in jutils.c */
442#if 0 /* This table is not actually needed in v6a */
443extern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */
444#endif
445extern const int jpeg_natural_order[]; /* zigzag coef order to natural order */
446extern const int jpeg_natural_order7[]; /* zz to natural order for 7x7 block */
447extern const int jpeg_natural_order6[]; /* zz to natural order for 6x6 block */
448extern const int jpeg_natural_order5[]; /* zz to natural order for 5x5 block */
449extern const int jpeg_natural_order4[]; /* zz to natural order for 4x4 block */
450extern const int jpeg_natural_order3[]; /* zz to natural order for 3x3 block */
451extern const int jpeg_natural_order2[]; /* zz to natural order for 2x2 block */
452
453/* Arithmetic coding probability estimation tables in jaricom.c */
454extern const INT32 jpeg_aritab[];
455
456/* Suppress undefined-structure complaints if necessary. */
457
458#ifdef INCOMPLETE_TYPES_BROKEN
459#ifndef AM_MEMORY_MANAGER /* only jmemmgr.c defines these */
460struct jvirt_sarray_control { long dummy; };
461struct jvirt_barray_control { long dummy; };
462#endif
463#endif /* INCOMPLETE_TYPES_BROKEN */
Definition: jpegint.h:86
Definition: jpegint.h:66
Definition: jpegint.h:74
Definition: jpegint.h:93
Definition: jpegint.h:253
Definition: jpegint.h:261
Definition: jpeglib.h:297
Definition: jpegint.h:55
Definition: jpeglib.h:145
Definition: jpeglib.h:312
Definition: jpegint.h:177
Definition: jpegint.h:169
Definition: jpegint.h:188
Definition: jpegint.h:148
Definition: jpeglib.h:480
Definition: jpegint.h:101
Definition: jpegint.h:220
Definition: jpegint.h:124
Definition: jpegint.h:117
Definition: jpegint.h:157
Definition: jpegint.h:232
Definition: jpegint.h:200
Definition: jpegint.h:131
Definition: jpegint.h:239