Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/libs/jpeg/jpegint.h
4394 views
1
/*
2
* jpegint.h
3
*
4
* Copyright (C) 1991-1997, Thomas G. Lane.
5
* Modified 1997-2020 by Guido Vollbeding.
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
17
typedef 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 */
46
struct 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) */
57
struct 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) */
65
struct 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 */
77
struct 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 */
84
struct 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 */
92
struct 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) */
103
typedef JMETHOD(void, forward_DCT_ptr,
104
(j_compress_ptr cinfo, jpeg_component_info * compptr,
105
JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
106
JDIMENSION start_col, JDIMENSION num_blocks));
107
108
struct jpeg_forward_dct {
109
JMETHOD(void, start_pass, (j_compress_ptr cinfo));
110
/* It is useful to allow each component to have a separate FDCT method. */
111
forward_DCT_ptr forward_DCT[MAX_COMPONENTS];
112
};
113
114
/* Entropy encoding */
115
struct jpeg_entropy_encoder {
116
JMETHOD(void, start_pass, (j_compress_ptr cinfo, boolean gather_statistics));
117
JMETHOD(boolean, encode_mcu, (j_compress_ptr cinfo, JBLOCKARRAY MCU_data));
118
JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
119
};
120
121
/* Marker writing */
122
struct jpeg_marker_writer {
123
JMETHOD(void, write_file_header, (j_compress_ptr cinfo));
124
JMETHOD(void, write_frame_header, (j_compress_ptr cinfo));
125
JMETHOD(void, write_scan_header, (j_compress_ptr cinfo));
126
JMETHOD(void, write_file_trailer, (j_compress_ptr cinfo));
127
JMETHOD(void, write_tables_only, (j_compress_ptr cinfo));
128
/* These routines are exported to allow insertion of extra markers */
129
/* Probably only COM and APPn markers should be written this way */
130
JMETHOD(void, write_marker_header, (j_compress_ptr cinfo, int marker,
131
unsigned int datalen));
132
JMETHOD(void, write_marker_byte, (j_compress_ptr cinfo, int val));
133
};
134
135
136
/* Declarations for decompression modules */
137
138
/* Master control module */
139
struct jpeg_decomp_master {
140
JMETHOD(void, prepare_for_output_pass, (j_decompress_ptr cinfo));
141
JMETHOD(void, finish_output_pass, (j_decompress_ptr cinfo));
142
143
/* State variables made visible to other modules */
144
boolean is_dummy_pass; /* True during 1st pass for 2-pass quant */
145
};
146
147
/* Input control module */
148
struct jpeg_input_controller {
149
JMETHOD(int, consume_input, (j_decompress_ptr cinfo));
150
JMETHOD(void, reset_input_controller, (j_decompress_ptr cinfo));
151
JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
152
JMETHOD(void, finish_input_pass, (j_decompress_ptr cinfo));
153
154
/* State variables made visible to other modules */
155
boolean has_multiple_scans; /* True if file has multiple scans */
156
boolean eoi_reached; /* True when EOI has been consumed */
157
};
158
159
/* Main buffer control (downsampled-data buffer) */
160
struct jpeg_d_main_controller {
161
JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
162
JMETHOD(void, process_data, (j_decompress_ptr cinfo,
163
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
164
JDIMENSION out_rows_avail));
165
};
166
167
/* Coefficient buffer control */
168
struct jpeg_d_coef_controller {
169
JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
170
JMETHOD(int, consume_data, (j_decompress_ptr cinfo));
171
JMETHOD(void, start_output_pass, (j_decompress_ptr cinfo));
172
JMETHOD(int, decompress_data, (j_decompress_ptr cinfo,
173
JSAMPIMAGE output_buf));
174
/* Pointer to array of coefficient virtual arrays, or NULL if none */
175
jvirt_barray_ptr *coef_arrays;
176
};
177
178
/* Decompression postprocessing (color quantization buffer control) */
179
struct jpeg_d_post_controller {
180
JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
181
JMETHOD(void, post_process_data, (j_decompress_ptr cinfo,
182
JSAMPIMAGE input_buf,
183
JDIMENSION *in_row_group_ctr,
184
JDIMENSION in_row_groups_avail,
185
JSAMPARRAY output_buf,
186
JDIMENSION *out_row_ctr,
187
JDIMENSION out_rows_avail));
188
};
189
190
/* Marker reading & parsing */
191
struct jpeg_marker_reader {
192
JMETHOD(void, reset_marker_reader, (j_decompress_ptr cinfo));
193
/* Read markers until SOS or EOI.
194
* Returns same codes as are defined for jpeg_consume_input:
195
* JPEG_SUSPENDED, JPEG_REACHED_SOS, or JPEG_REACHED_EOI.
196
*/
197
JMETHOD(int, read_markers, (j_decompress_ptr cinfo));
198
/* Read a restart marker --- exported for use by entropy decoder only */
199
jpeg_marker_parser_method read_restart_marker;
200
201
/* State of marker reader --- nominally internal, but applications
202
* supplying COM or APPn handlers might like to know the state.
203
*/
204
boolean saw_SOI; /* found SOI? */
205
boolean saw_SOF; /* found SOF? */
206
int next_restart_num; /* next restart number expected (0-7) */
207
unsigned int discarded_bytes; /* # of bytes skipped looking for a marker */
208
};
209
210
/* Entropy decoding */
211
struct jpeg_entropy_decoder {
212
JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
213
JMETHOD(boolean, decode_mcu, (j_decompress_ptr cinfo, JBLOCKARRAY MCU_data));
214
JMETHOD(void, finish_pass, (j_decompress_ptr cinfo));
215
};
216
217
/* Inverse DCT (also performs dequantization) */
218
typedef JMETHOD(void, inverse_DCT_method_ptr,
219
(j_decompress_ptr cinfo, jpeg_component_info * compptr,
220
JCOEFPTR coef_block,
221
JSAMPARRAY output_buf, JDIMENSION output_col));
222
223
struct jpeg_inverse_dct {
224
JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
225
/* It is useful to allow each component to have a separate IDCT method. */
226
inverse_DCT_method_ptr inverse_DCT[MAX_COMPONENTS];
227
};
228
229
/* Upsampling (note that upsampler must also call color converter) */
230
struct jpeg_upsampler {
231
JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
232
JMETHOD(void, upsample, (j_decompress_ptr cinfo,
233
JSAMPIMAGE input_buf,
234
JDIMENSION *in_row_group_ctr,
235
JDIMENSION in_row_groups_avail,
236
JSAMPARRAY output_buf,
237
JDIMENSION *out_row_ctr,
238
JDIMENSION out_rows_avail));
239
240
boolean need_context_rows; /* TRUE if need rows above & below */
241
};
242
243
/* Colorspace conversion */
244
struct jpeg_color_deconverter {
245
JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
246
JMETHOD(void, color_convert, (j_decompress_ptr cinfo,
247
JSAMPIMAGE input_buf, JDIMENSION input_row,
248
JSAMPARRAY output_buf, int num_rows));
249
};
250
251
/* Color quantization or color precision reduction */
252
struct jpeg_color_quantizer {
253
JMETHOD(void, start_pass, (j_decompress_ptr cinfo, boolean is_pre_scan));
254
JMETHOD(void, color_quantize, (j_decompress_ptr cinfo,
255
JSAMPARRAY input_buf, JSAMPARRAY output_buf,
256
int num_rows));
257
JMETHOD(void, finish_pass, (j_decompress_ptr cinfo));
258
JMETHOD(void, new_color_map, (j_decompress_ptr cinfo));
259
};
260
261
262
/* Definition of range extension bits for decompression processes.
263
* See the comments with prepare_range_limit_table (in jdmaster.c)
264
* for more info.
265
* The recommended default value for normal applications is 2.
266
* Applications with special requirements may use a different value.
267
* For example, Ghostscript wants to use 3 for proper handling of
268
* wacky images with oversize coefficient values.
269
*/
270
271
#define RANGE_BITS 2
272
#define RANGE_CENTER (CENTERJSAMPLE << RANGE_BITS)
273
274
275
/* Miscellaneous useful macros */
276
277
#undef MAX
278
#define MAX(a,b) ((a) > (b) ? (a) : (b))
279
#undef MIN
280
#define MIN(a,b) ((a) < (b) ? (a) : (b))
281
282
283
/* We assume that right shift corresponds to signed division by 2 with
284
* rounding towards minus infinity. This is correct for typical "arithmetic
285
* shift" instructions that shift in copies of the sign bit. But some
286
* C compilers implement >> with an unsigned shift. For these machines you
287
* must define RIGHT_SHIFT_IS_UNSIGNED.
288
* RIGHT_SHIFT provides a proper signed right shift of an INT32 quantity.
289
* It is only applied with constant shift counts. SHIFT_TEMPS must be
290
* included in the variables of any routine using RIGHT_SHIFT.
291
*/
292
293
#ifdef RIGHT_SHIFT_IS_UNSIGNED
294
#define SHIFT_TEMPS INT32 shift_temp;
295
#define RIGHT_SHIFT(x,shft) \
296
((shift_temp = (x)) < 0 ? \
297
(shift_temp >> (shft)) | ((~((INT32) 0)) << (32-(shft))) : \
298
(shift_temp >> (shft)))
299
#else
300
#define SHIFT_TEMPS
301
#define RIGHT_SHIFT(x,shft) ((x) >> (shft))
302
#endif
303
304
/* Descale and correctly round an INT32 value that's scaled by N bits.
305
* We assume RIGHT_SHIFT rounds towards minus infinity, so adding
306
* the fudge factor is correct for either sign of X.
307
*/
308
309
#define DESCALE(x,n) RIGHT_SHIFT((x) + ((INT32) 1 << ((n)-1)), n)
310
311
312
/* Short forms of external names for systems with brain-damaged linkers. */
313
314
#ifdef NEED_SHORT_EXTERNAL_NAMES
315
#define jinit_compress_master jICompress
316
#define jinit_c_master_control jICMaster
317
#define jinit_c_main_controller jICMainC
318
#define jinit_c_prep_controller jICPrepC
319
#define jinit_c_coef_controller jICCoefC
320
#define jinit_color_converter jICColor
321
#define jinit_downsampler jIDownsampler
322
#define jinit_forward_dct jIFDCT
323
#define jinit_huff_encoder jIHEncoder
324
#define jinit_arith_encoder jIAEncoder
325
#define jinit_marker_writer jIMWriter
326
#define jinit_master_decompress jIDMaster
327
#define jinit_d_main_controller jIDMainC
328
#define jinit_d_coef_controller jIDCoefC
329
#define jinit_d_post_controller jIDPostC
330
#define jinit_input_controller jIInCtlr
331
#define jinit_marker_reader jIMReader
332
#define jinit_huff_decoder jIHDecoder
333
#define jinit_arith_decoder jIADecoder
334
#define jinit_inverse_dct jIIDCT
335
#define jinit_upsampler jIUpsampler
336
#define jinit_color_deconverter jIDColor
337
#define jinit_1pass_quantizer jI1Quant
338
#define jinit_2pass_quantizer jI2Quant
339
#define jinit_merged_upsampler jIMUpsampler
340
#define jinit_memory_mgr jIMemMgr
341
#define jdiv_round_up jDivRound
342
#define jround_up jRound
343
#define jzero_far jZeroFar
344
#define jcopy_sample_rows jCopySamples
345
#define jcopy_block_row jCopyBlocks
346
#define jpeg_zigzag_order jZIGTable
347
#define jpeg_natural_order jZAGTable
348
#define jpeg_natural_order7 jZAG7Table
349
#define jpeg_natural_order6 jZAG6Table
350
#define jpeg_natural_order5 jZAG5Table
351
#define jpeg_natural_order4 jZAG4Table
352
#define jpeg_natural_order3 jZAG3Table
353
#define jpeg_natural_order2 jZAG2Table
354
#define jpeg_aritab jAriTab
355
#endif /* NEED_SHORT_EXTERNAL_NAMES */
356
357
358
/* On normal machines we can apply MEMCOPY() and MEMZERO() to sample arrays
359
* and coefficient-block arrays. This won't work on 80x86 because the arrays
360
* are FAR and we're assuming a small-pointer memory model. However, some
361
* DOS compilers provide far-pointer versions of memcpy() and memset() even
362
* in the small-model libraries. These will be used if USE_FMEM is defined.
363
* Otherwise, the routines in jutils.c do it the hard way.
364
*/
365
366
#ifndef NEED_FAR_POINTERS /* normal case, same as regular macro */
367
#define FMEMZERO(target,size) MEMZERO(target,size)
368
#else /* 80x86 case */
369
#ifdef USE_FMEM
370
#define FMEMZERO(target,size) _fmemset((void FAR *)(target), 0, (size_t)(size))
371
#else
372
EXTERN(void) jzero_far JPP((void FAR * target, size_t bytestozero));
373
#define FMEMZERO(target,size) jzero_far(target, size)
374
#endif
375
#endif
376
377
378
/* Compression module initialization routines */
379
EXTERN(void) jinit_compress_master JPP((j_compress_ptr cinfo));
380
EXTERN(void) jinit_c_master_control JPP((j_compress_ptr cinfo,
381
boolean transcode_only));
382
EXTERN(void) jinit_c_main_controller JPP((j_compress_ptr cinfo,
383
boolean need_full_buffer));
384
EXTERN(void) jinit_c_prep_controller JPP((j_compress_ptr cinfo,
385
boolean need_full_buffer));
386
EXTERN(void) jinit_c_coef_controller JPP((j_compress_ptr cinfo,
387
boolean need_full_buffer));
388
EXTERN(void) jinit_color_converter JPP((j_compress_ptr cinfo));
389
EXTERN(void) jinit_downsampler JPP((j_compress_ptr cinfo));
390
EXTERN(void) jinit_forward_dct JPP((j_compress_ptr cinfo));
391
EXTERN(void) jinit_huff_encoder JPP((j_compress_ptr cinfo));
392
EXTERN(void) jinit_arith_encoder JPP((j_compress_ptr cinfo));
393
EXTERN(void) jinit_marker_writer JPP((j_compress_ptr cinfo));
394
/* Decompression module initialization routines */
395
EXTERN(void) jinit_master_decompress JPP((j_decompress_ptr cinfo));
396
EXTERN(void) jinit_d_main_controller JPP((j_decompress_ptr cinfo,
397
boolean need_full_buffer));
398
EXTERN(void) jinit_d_coef_controller JPP((j_decompress_ptr cinfo,
399
boolean need_full_buffer));
400
EXTERN(void) jinit_d_post_controller JPP((j_decompress_ptr cinfo,
401
boolean need_full_buffer));
402
EXTERN(void) jinit_input_controller JPP((j_decompress_ptr cinfo));
403
EXTERN(void) jinit_marker_reader JPP((j_decompress_ptr cinfo));
404
EXTERN(void) jinit_huff_decoder JPP((j_decompress_ptr cinfo));
405
EXTERN(void) jinit_arith_decoder JPP((j_decompress_ptr cinfo));
406
EXTERN(void) jinit_inverse_dct JPP((j_decompress_ptr cinfo));
407
EXTERN(void) jinit_upsampler JPP((j_decompress_ptr cinfo));
408
EXTERN(void) jinit_color_deconverter JPP((j_decompress_ptr cinfo));
409
EXTERN(void) jinit_1pass_quantizer JPP((j_decompress_ptr cinfo));
410
EXTERN(void) jinit_2pass_quantizer JPP((j_decompress_ptr cinfo));
411
EXTERN(void) jinit_merged_upsampler JPP((j_decompress_ptr cinfo));
412
/* Memory manager initialization */
413
EXTERN(void) jinit_memory_mgr JPP((j_common_ptr cinfo));
414
415
/* Utility routines in jutils.c */
416
EXTERN(long) jdiv_round_up JPP((long a, long b));
417
EXTERN(long) jround_up JPP((long a, long b));
418
EXTERN(void) jcopy_sample_rows JPP((JSAMPARRAY input_array,
419
JSAMPARRAY output_array,
420
int num_rows, JDIMENSION num_cols));
421
EXTERN(void) jcopy_block_row JPP((JBLOCKROW input_row, JBLOCKROW output_row,
422
JDIMENSION num_blocks));
423
/* Constant tables in jutils.c */
424
#if 0 /* This table is not actually needed in v6a */
425
extern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */
426
#endif
427
extern const int jpeg_natural_order[]; /* zigzag coef order to natural order */
428
extern const int jpeg_natural_order7[]; /* zz to natural order for 7x7 block */
429
extern const int jpeg_natural_order6[]; /* zz to natural order for 6x6 block */
430
extern const int jpeg_natural_order5[]; /* zz to natural order for 5x5 block */
431
extern const int jpeg_natural_order4[]; /* zz to natural order for 4x4 block */
432
extern const int jpeg_natural_order3[]; /* zz to natural order for 3x3 block */
433
extern const int jpeg_natural_order2[]; /* zz to natural order for 2x2 block */
434
435
/* Arithmetic coding probability estimation tables in jaricom.c */
436
extern const INT32 jpeg_aritab[];
437
438
/* Suppress undefined-structure complaints if necessary. */
439
440
#ifdef INCOMPLETE_TYPES_BROKEN
441
#ifndef AM_MEMORY_MANAGER /* only jmemmgr.c defines these */
442
struct jvirt_sarray_control { long dummy; };
443
struct jvirt_barray_control { long dummy; };
444
#endif
445
#endif /* INCOMPLETE_TYPES_BROKEN */
446
447