Remove 'oldcode'
[oweals/cde.git] / cde / lib / DtHelp / jpeg / jpegint.h
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: jpegint.h /main/2 1996/05/09 03:53:25 drk $ */
24 /*
25  * jpegint.h
26  *
27  * Copyright (C) 1991-1996, Thomas G. Lane.
28  * This file is part of the Independent JPEG Group's software.
29  * For conditions of distribution and use, see the accompanying README file.
30  *
31  * This file provides common declarations for the various JPEG modules.
32  * These declarations are considered internal to the JPEG library; most
33  * applications using the library shouldn't need to include this file.
34  */
35
36
37 /* Declarations for both compression & decompression */
38
39 typedef enum {                  /* Operating modes for buffer controllers */
40         JBUF_PASS_THRU,         /* Plain stripwise operation */
41         /* Remaining modes require a full-image buffer to have been created */
42         JBUF_SAVE_SOURCE,       /* Run source subobject only, save output */
43         JBUF_CRANK_DEST,        /* Run dest subobject only, using saved data */
44         JBUF_SAVE_AND_PASS      /* Run both subobjects, save output */
45 } J_BUF_MODE;
46
47 /* Values of global_state field (jdapi.c has some dependencies on ordering!) */
48 #define CSTATE_START    100     /* after create_compress */
49 #define CSTATE_SCANNING 101     /* start_compress done, write_scanlines OK */
50 #define CSTATE_RAW_OK   102     /* start_compress done, write_raw_data OK */
51 #define CSTATE_WRCOEFS  103     /* jpeg_write_coefficients done */
52 #define DSTATE_START    200     /* after create_decompress */
53 #define DSTATE_INHEADER 201     /* reading header markers, no SOS yet */
54 #define DSTATE_READY    202     /* found SOS, ready for start_decompress */
55 #define DSTATE_PRELOAD  203     /* reading multiscan file in start_decompress*/
56 #define DSTATE_PRESCAN  204     /* performing dummy pass for 2-pass quant */
57 #define DSTATE_SCANNING 205     /* start_decompress done, read_scanlines OK */
58 #define DSTATE_RAW_OK   206     /* start_decompress done, read_raw_data OK */
59 #define DSTATE_BUFIMAGE 207     /* expecting jpeg_start_output */
60 #define DSTATE_BUFPOST  208     /* looking for SOS/EOI in jpeg_finish_output */
61 #define DSTATE_RDCOEFS  209     /* reading file in jpeg_read_coefficients */
62 #define DSTATE_STOPPING 210     /* looking for EOI in jpeg_finish_decompress */
63
64
65 /* Declarations for compression modules */
66
67 /* Master control module */
68 struct jpeg_comp_master {
69   JMETHOD(void, prepare_for_pass, (j_compress_ptr cinfo));
70   JMETHOD(void, pass_startup, (j_compress_ptr cinfo));
71   JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
72
73   /* State variables made visible to other modules */
74   boolean call_pass_startup;    /* True if pass_startup must be called */
75   boolean is_last_pass;         /* True during last pass */
76 };
77
78 /* Main buffer control (downsampled-data buffer) */
79 struct jpeg_c_main_controller {
80   JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
81   JMETHOD(void, process_data, (j_compress_ptr cinfo,
82                                JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
83                                JDIMENSION in_rows_avail));
84 };
85
86 /* Compression preprocessing (downsampling input buffer control) */
87 struct jpeg_c_prep_controller {
88   JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
89   JMETHOD(void, pre_process_data, (j_compress_ptr cinfo,
90                                    JSAMPARRAY input_buf,
91                                    JDIMENSION *in_row_ctr,
92                                    JDIMENSION in_rows_avail,
93                                    JSAMPIMAGE output_buf,
94                                    JDIMENSION *out_row_group_ctr,
95                                    JDIMENSION out_row_groups_avail));
96 };
97
98 /* Coefficient buffer control */
99 struct jpeg_c_coef_controller {
100   JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
101   JMETHOD(boolean, compress_data, (j_compress_ptr cinfo,
102                                    JSAMPIMAGE input_buf));
103 };
104
105 /* Colorspace conversion */
106 struct jpeg_color_converter {
107   JMETHOD(void, start_pass, (j_compress_ptr cinfo));
108   JMETHOD(void, color_convert, (j_compress_ptr cinfo,
109                                 JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
110                                 JDIMENSION output_row, int num_rows));
111 };
112
113 /* Downsampling */
114 struct jpeg_downsampler {
115   JMETHOD(void, start_pass, (j_compress_ptr cinfo));
116   JMETHOD(void, downsample, (j_compress_ptr cinfo,
117                              JSAMPIMAGE input_buf, JDIMENSION in_row_index,
118                              JSAMPIMAGE output_buf,
119                              JDIMENSION out_row_group_index));
120
121   boolean need_context_rows;    /* TRUE if need rows above & below */
122 };
123
124 /* Forward DCT (also controls coefficient quantization) */
125 struct jpeg_forward_dct {
126   JMETHOD(void, start_pass, (j_compress_ptr cinfo));
127   /* perhaps this should be an array??? */
128   JMETHOD(void, forward_DCT, (j_compress_ptr cinfo,
129                               jpeg_component_info * compptr,
130                               JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
131                               JDIMENSION start_row, JDIMENSION start_col,
132                               JDIMENSION num_blocks));
133 };
134
135 /* Entropy encoding */
136 struct jpeg_entropy_encoder {
137   JMETHOD(void, start_pass, (j_compress_ptr cinfo, boolean gather_statistics));
138   JMETHOD(boolean, encode_mcu, (j_compress_ptr cinfo, JBLOCKROW *MCU_data));
139   JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
140 };
141
142 /* Marker writing */
143 struct jpeg_marker_writer {
144   /* write_any_marker is exported for use by applications */
145   /* Probably only COM and APPn markers should be written */
146   JMETHOD(void, write_any_marker, (j_compress_ptr cinfo, int marker,
147                                    const JOCTET *dataptr, unsigned int datalen));
148   JMETHOD(void, write_file_header, (j_compress_ptr cinfo));
149   JMETHOD(void, write_frame_header, (j_compress_ptr cinfo));
150   JMETHOD(void, write_scan_header, (j_compress_ptr cinfo));
151   JMETHOD(void, write_file_trailer, (j_compress_ptr cinfo));
152   JMETHOD(void, write_tables_only, (j_compress_ptr cinfo));
153 };
154
155
156 /* Declarations for decompression modules */
157
158 /* Master control module */
159 struct jpeg_decomp_master {
160   JMETHOD(void, prepare_for_output_pass, (j_decompress_ptr cinfo));
161   JMETHOD(void, finish_output_pass, (j_decompress_ptr cinfo));
162
163   /* State variables made visible to other modules */
164   boolean is_dummy_pass;        /* True during 1st pass for 2-pass quant */
165 };
166
167 /* Input control module */
168 struct jpeg_input_controller {
169   JMETHOD(int, consume_input, (j_decompress_ptr cinfo));
170   JMETHOD(void, reset_input_controller, (j_decompress_ptr cinfo));
171   JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
172   JMETHOD(void, finish_input_pass, (j_decompress_ptr cinfo));
173
174   /* State variables made visible to other modules */
175   boolean has_multiple_scans;   /* True if file has multiple scans */
176   boolean eoi_reached;          /* True when EOI has been consumed */
177 };
178
179 /* Main buffer control (downsampled-data buffer) */
180 struct jpeg_d_main_controller {
181   JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
182   JMETHOD(void, process_data, (j_decompress_ptr cinfo,
183                                JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
184                                JDIMENSION out_rows_avail));
185 };
186
187 /* Coefficient buffer control */
188 struct jpeg_d_coef_controller {
189   JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
190   JMETHOD(int, consume_data, (j_decompress_ptr cinfo));
191   JMETHOD(void, start_output_pass, (j_decompress_ptr cinfo));
192   JMETHOD(int, decompress_data, (j_decompress_ptr cinfo,
193                                  JSAMPIMAGE output_buf));
194   /* Pointer to array of coefficient virtual arrays, or NULL if none */
195   jvirt_barray_ptr *coef_arrays;
196 };
197
198 /* Decompression postprocessing (color quantization buffer control) */
199 struct jpeg_d_post_controller {
200   JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
201   JMETHOD(void, post_process_data, (j_decompress_ptr cinfo,
202                                     JSAMPIMAGE input_buf,
203                                     JDIMENSION *in_row_group_ctr,
204                                     JDIMENSION in_row_groups_avail,
205                                     JSAMPARRAY output_buf,
206                                     JDIMENSION *out_row_ctr,
207                                     JDIMENSION out_rows_avail));
208 };
209
210 /* Marker reading & parsing */
211 struct jpeg_marker_reader {
212   JMETHOD(void, reset_marker_reader, (j_decompress_ptr cinfo));
213   /* Read markers until SOS or EOI.
214    * Returns same codes as are defined for jpeg_consume_input:
215    * JPEG_SUSPENDED, JPEG_REACHED_SOS, or JPEG_REACHED_EOI.
216    */
217   JMETHOD(int, read_markers, (j_decompress_ptr cinfo));
218   /* Read a restart marker --- exported for use by entropy decoder only */
219   jpeg_marker_parser_method read_restart_marker;
220   /* Application-overridable marker processing methods */
221   jpeg_marker_parser_method process_COM;
222   jpeg_marker_parser_method process_APPn[16];
223
224   /* State of marker reader --- nominally internal, but applications
225    * supplying COM or APPn handlers might like to know the state.
226    */
227   boolean saw_SOI;              /* found SOI? */
228   boolean saw_SOF;              /* found SOF? */
229   int next_restart_num;         /* next restart number expected (0-7) */
230   unsigned int discarded_bytes; /* # of bytes skipped looking for a marker */
231 };
232
233 /* Entropy decoding */
234 struct jpeg_entropy_decoder {
235   JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
236   JMETHOD(boolean, decode_mcu, (j_decompress_ptr cinfo,
237                                 JBLOCKROW *MCU_data));
238 };
239
240 /* Inverse DCT (also performs dequantization) */
241 typedef JMETHOD(void, inverse_DCT_method_ptr,
242                 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
243                  JCOEFPTR coef_block,
244                  JSAMPARRAY output_buf, JDIMENSION output_col));
245
246 struct jpeg_inverse_dct {
247   JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
248   /* It is useful to allow each component to have a separate IDCT method. */
249   inverse_DCT_method_ptr inverse_DCT[MAX_COMPONENTS];
250 };
251
252 /* Upsampling (note that upsampler must also call color converter) */
253 struct jpeg_upsampler {
254   JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
255   JMETHOD(void, upsample, (j_decompress_ptr cinfo,
256                            JSAMPIMAGE input_buf,
257                            JDIMENSION *in_row_group_ctr,
258                            JDIMENSION in_row_groups_avail,
259                            JSAMPARRAY output_buf,
260                            JDIMENSION *out_row_ctr,
261                            JDIMENSION out_rows_avail));
262
263   boolean need_context_rows;    /* TRUE if need rows above & below */
264 };
265
266 /* Colorspace conversion */
267 struct jpeg_color_deconverter {
268   JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
269   JMETHOD(void, color_convert, (j_decompress_ptr cinfo,
270                                 JSAMPIMAGE input_buf, JDIMENSION input_row,
271                                 JSAMPARRAY output_buf, int num_rows));
272 };
273
274 /* Color quantization or color precision reduction */
275 struct jpeg_color_quantizer {
276   JMETHOD(void, start_pass, (j_decompress_ptr cinfo, boolean is_pre_scan));
277   JMETHOD(void, color_quantize, (j_decompress_ptr cinfo,
278                                  JSAMPARRAY input_buf, JSAMPARRAY output_buf,
279                                  int num_rows));
280   JMETHOD(void, finish_pass, (j_decompress_ptr cinfo));
281   JMETHOD(void, new_color_map, (j_decompress_ptr cinfo));
282 };
283
284
285 /* Miscellaneous useful macros */
286
287 #undef MAX
288 #define MAX(a,b)        ((a) > (b) ? (a) : (b))
289 #undef MIN
290 #define MIN(a,b)        ((a) < (b) ? (a) : (b))
291
292
293 /* We assume that right shift corresponds to signed division by 2 with
294  * rounding towards minus infinity.  This is correct for typical "arithmetic
295  * shift" instructions that shift in copies of the sign bit.  But some
296  * C compilers implement >> with an unsigned shift.  For these machines you
297  * must define RIGHT_SHIFT_IS_UNSIGNED.
298  * RIGHT_SHIFT provides a proper signed right shift of an INT32 quantity.
299  * It is only applied with constant shift counts.  SHIFT_TEMPS must be
300  * included in the variables of any routine using RIGHT_SHIFT.
301  */
302
303 #ifdef RIGHT_SHIFT_IS_UNSIGNED
304 #define SHIFT_TEMPS     INT32 shift_temp;
305 #define RIGHT_SHIFT(x,shft)  \
306         ((shift_temp = (x)) < 0 ? \
307          (shift_temp >> (shft)) | ((~((INT32) 0)) << (32-(shft))) : \
308          (shift_temp >> (shft)))
309 #else
310 #define SHIFT_TEMPS
311 #define RIGHT_SHIFT(x,shft)     ((x) >> (shft))
312 #endif
313
314
315 /* Short forms of external names for systems with brain-damaged linkers. */
316
317 #ifdef NEED_SHORT_EXTERNAL_NAMES
318 #define jinit_compress_master   jICompress
319 #define jinit_c_master_control  jICMaster
320 #define jinit_c_main_controller jICMainC
321 #define jinit_c_prep_controller jICPrepC
322 #define jinit_c_coef_controller jICCoefC
323 #define jinit_color_converter   jICColor
324 #define jinit_downsampler       jIDownsampler
325 #define jinit_forward_dct       jIFDCT
326 #define jinit_huff_encoder      jIHEncoder
327 #define jinit_phuff_encoder     jIPHEncoder
328 #define jinit_marker_writer     jIMWriter
329 #define jinit_master_decompress jIDMaster
330 #define jinit_d_main_controller jIDMainC
331 #define jinit_d_coef_controller jIDCoefC
332 #define jinit_d_post_controller jIDPostC
333 #define jinit_input_controller  jIInCtlr
334 #define jinit_marker_reader     jIMReader
335 #define jinit_huff_decoder      jIHDecoder
336 #define jinit_phuff_decoder     jIPHDecoder
337 #define jinit_inverse_dct       jIIDCT
338 #define jinit_upsampler         jIUpsampler
339 #define jinit_color_deconverter jIDColor
340 #define jinit_1pass_quantizer   jI1Quant
341 #define jinit_2pass_quantizer   jI2Quant
342 #define jinit_merged_upsampler  jIMUpsampler
343 #define jinit_memory_mgr        jIMemMgr
344 #define jdiv_round_up           jDivRound
345 #define jround_up               jRound
346 #define jcopy_sample_rows       jCopySamples
347 #define jcopy_block_row         jCopyBlocks
348 #define jzero_far               jZeroFar
349 #define jpeg_zigzag_order       jZIGTable
350 #define jpeg_natural_order      jZAGTable
351 #endif /* NEED_SHORT_EXTERNAL_NAMES */
352
353
354 /* Compression module initialization routines */
355 EXTERN(void) jinit_compress_master JPP((j_compress_ptr cinfo));
356 EXTERN(void) jinit_c_master_control JPP((j_compress_ptr cinfo,
357                                          boolean transcode_only));
358 EXTERN(void) jinit_c_main_controller JPP((j_compress_ptr cinfo,
359                                           boolean need_full_buffer));
360 EXTERN(void) jinit_c_prep_controller JPP((j_compress_ptr cinfo,
361                                           boolean need_full_buffer));
362 EXTERN(void) jinit_c_coef_controller JPP((j_compress_ptr cinfo,
363                                           boolean need_full_buffer));
364 EXTERN(void) jinit_color_converter JPP((j_compress_ptr cinfo));
365 EXTERN(void) jinit_downsampler JPP((j_compress_ptr cinfo));
366 EXTERN(void) jinit_forward_dct JPP((j_compress_ptr cinfo));
367 EXTERN(void) jinit_huff_encoder JPP((j_compress_ptr cinfo));
368 EXTERN(void) jinit_phuff_encoder JPP((j_compress_ptr cinfo));
369 EXTERN(void) jinit_marker_writer JPP((j_compress_ptr cinfo));
370 /* Decompression module initialization routines */
371 EXTERN(void) jinit_master_decompress JPP((j_decompress_ptr cinfo));
372 EXTERN(void) jinit_d_main_controller JPP((j_decompress_ptr cinfo,
373                                           boolean need_full_buffer));
374 EXTERN(void) jinit_d_coef_controller JPP((j_decompress_ptr cinfo,
375                                           boolean need_full_buffer));
376 EXTERN(void) jinit_d_post_controller JPP((j_decompress_ptr cinfo,
377                                           boolean need_full_buffer));
378 EXTERN(void) jinit_input_controller JPP((j_decompress_ptr cinfo));
379 EXTERN(void) jinit_marker_reader JPP((j_decompress_ptr cinfo));
380 EXTERN(void) jinit_huff_decoder JPP((j_decompress_ptr cinfo));
381 EXTERN(void) jinit_phuff_decoder JPP((j_decompress_ptr cinfo));
382 EXTERN(void) jinit_inverse_dct JPP((j_decompress_ptr cinfo));
383 EXTERN(void) jinit_upsampler JPP((j_decompress_ptr cinfo));
384 EXTERN(void) jinit_color_deconverter JPP((j_decompress_ptr cinfo));
385 EXTERN(void) jinit_1pass_quantizer JPP((j_decompress_ptr cinfo));
386 EXTERN(void) jinit_2pass_quantizer JPP((j_decompress_ptr cinfo));
387 EXTERN(void) jinit_merged_upsampler JPP((j_decompress_ptr cinfo));
388 /* Memory manager initialization */
389 EXTERN(void) jinit_memory_mgr JPP((j_common_ptr cinfo));
390
391 /* Utility routines in jutils.c */
392 EXTERN(long) jdiv_round_up JPP((long a, long b));
393 EXTERN(long) jround_up JPP((long a, long b));
394 EXTERN(void) jcopy_sample_rows JPP((JSAMPARRAY input_array, int source_row,
395                                     JSAMPARRAY output_array, int dest_row,
396                                     int num_rows, JDIMENSION num_cols));
397 EXTERN(void) jcopy_block_row JPP((JBLOCKROW input_row, JBLOCKROW output_row,
398                                   JDIMENSION num_blocks));
399 EXTERN(void) jzero_far JPP((void FAR * target, size_t bytestozero));
400 /* Constant tables in jutils.c */
401 extern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */
402 extern const int jpeg_natural_order[]; /* zigzag coef order to natural order */
403
404 /* Suppress undefined-structure complaints if necessary. */
405
406 #ifdef INCOMPLETE_TYPES_BROKEN
407 #ifndef AM_MEMORY_MANAGER       /* only jmemmgr.c defines these */
408 struct jvirt_sarray_control { long dummy; };
409 struct jvirt_barray_control { long dummy; };
410 #endif
411 #endif /* INCOMPLETE_TYPES_BROKEN */