136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/*
236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * jpegint.h
336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane *
45033f3e19a31e8ad40c1a79700365aefe5664494DRC * This file was part of the Independent JPEG Group's software:
55ead57a34a398aa798f35bd7a6abad19b2e453e2Thomas G. Lane * Copyright (C) 1991-1997, Thomas G. Lane.
65996a25e2f50d20d6a8f09830724035b49c3927bGuido Vollbeding * Modified 1997-2009 by Guido Vollbeding.
78e9cef2e6f5156c4b055a04a8f979b7291fc6b7aDRC * libjpeg-turbo Modifications:
86eb7d3798b5a79347c62825fc4c16f7ce673bdd0Alex Naidis * Copyright (C) 2015-2016, D. R. Commander.
90ef076fb7b326dc201b4ab3bd30fefd4e35ad1c4DRC * Copyright (C) 2015, Google, Inc.
100ef076fb7b326dc201b4ab3bd30fefd4e35ad1c4DRC * For conditions of distribution and use, see the accompanying README.ijg
110ef076fb7b326dc201b4ab3bd30fefd4e35ad1c4DRC * file.
1236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane *
1336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * This file provides common declarations for the various JPEG modules.
1436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * These declarations are considered internal to the JPEG library; most
1536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * applications using the library shouldn't need to include this file.
1636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane */
1736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
1836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
1936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Declarations for both compression & decompression */
2036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
21333e9187c8a6f69833baaee51ccd802b0e093cc1DRCtypedef enum {            /* Operating modes for buffer controllers */
22333e9187c8a6f69833baaee51ccd802b0e093cc1DRC  JBUF_PASS_THRU,         /* Plain stripwise operation */
23333e9187c8a6f69833baaee51ccd802b0e093cc1DRC  /* Remaining modes require a full-image buffer to have been created */
24333e9187c8a6f69833baaee51ccd802b0e093cc1DRC  JBUF_SAVE_SOURCE,       /* Run source subobject only, save output */
25333e9187c8a6f69833baaee51ccd802b0e093cc1DRC  JBUF_CRANK_DEST,        /* Run dest subobject only, using saved data */
26333e9187c8a6f69833baaee51ccd802b0e093cc1DRC  JBUF_SAVE_AND_PASS      /* Run both subobjects, save output */
2736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane} J_BUF_MODE;
2836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
29bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane/* Values of global_state field (jdapi.c has some dependencies on ordering!) */
30b775351012af176720429ac21d11682a0b75b4b7DRC#define CSTATE_START    100     /* after create_compress */
31b775351012af176720429ac21d11682a0b75b4b7DRC#define CSTATE_SCANNING 101     /* start_compress done, write_scanlines OK */
32b775351012af176720429ac21d11682a0b75b4b7DRC#define CSTATE_RAW_OK   102     /* start_compress done, write_raw_data OK */
33b775351012af176720429ac21d11682a0b75b4b7DRC#define CSTATE_WRCOEFS  103     /* jpeg_write_coefficients done */
34b775351012af176720429ac21d11682a0b75b4b7DRC#define DSTATE_START    200     /* after create_decompress */
35b775351012af176720429ac21d11682a0b75b4b7DRC#define DSTATE_INHEADER 201     /* reading header markers, no SOS yet */
36b775351012af176720429ac21d11682a0b75b4b7DRC#define DSTATE_READY    202     /* found SOS, ready for start_decompress */
37b775351012af176720429ac21d11682a0b75b4b7DRC#define DSTATE_PRELOAD  203     /* reading multiscan file in start_decompress*/
38b775351012af176720429ac21d11682a0b75b4b7DRC#define DSTATE_PRESCAN  204     /* performing dummy pass for 2-pass quant */
39b775351012af176720429ac21d11682a0b75b4b7DRC#define DSTATE_SCANNING 205     /* start_decompress done, read_scanlines OK */
40b775351012af176720429ac21d11682a0b75b4b7DRC#define DSTATE_RAW_OK   206     /* start_decompress done, read_raw_data OK */
41b775351012af176720429ac21d11682a0b75b4b7DRC#define DSTATE_BUFIMAGE 207     /* expecting jpeg_start_output */
42b775351012af176720429ac21d11682a0b75b4b7DRC#define DSTATE_BUFPOST  208     /* looking for SOS/EOI in jpeg_finish_output */
43b775351012af176720429ac21d11682a0b75b4b7DRC#define DSTATE_RDCOEFS  209     /* reading file in jpeg_read_coefficients */
44b775351012af176720429ac21d11682a0b75b4b7DRC#define DSTATE_STOPPING 210     /* looking for EOI in jpeg_finish_decompress */
4536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
4636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
476eb7d3798b5a79347c62825fc4c16f7ce673bdd0Alex Naidis/* JLONG must hold at least signed 32-bit values. */
486eb7d3798b5a79347c62825fc4c16f7ce673bdd0Alex Naidistypedef long JLONG;
496eb7d3798b5a79347c62825fc4c16f7ce673bdd0Alex Naidis
506eb7d3798b5a79347c62825fc4c16f7ce673bdd0Alex Naidis
518e9cef2e6f5156c4b055a04a8f979b7291fc6b7aDRC/*
528e9cef2e6f5156c4b055a04a8f979b7291fc6b7aDRC * Left shift macro that handles a negative operand without causing any
538e9cef2e6f5156c4b055a04a8f979b7291fc6b7aDRC * sanitizer warnings
548e9cef2e6f5156c4b055a04a8f979b7291fc6b7aDRC */
558e9cef2e6f5156c4b055a04a8f979b7291fc6b7aDRC
566eb7d3798b5a79347c62825fc4c16f7ce673bdd0Alex Naidis#define LEFT_SHIFT(a, b) ((JLONG)((unsigned long)(a) << (b)))
578e9cef2e6f5156c4b055a04a8f979b7291fc6b7aDRC
588e9cef2e6f5156c4b055a04a8f979b7291fc6b7aDRC
5936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Declarations for compression modules */
6036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
6136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Master control module */
6236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jpeg_comp_master {
63bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*prepare_for_pass) (j_compress_ptr cinfo);
64bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*pass_startup) (j_compress_ptr cinfo);
65bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*finish_pass) (j_compress_ptr cinfo);
6636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
6736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* State variables made visible to other modules */
68b775351012af176720429ac21d11682a0b75b4b7DRC  boolean call_pass_startup;    /* True if pass_startup must be called */
69b775351012af176720429ac21d11682a0b75b4b7DRC  boolean is_last_pass;         /* True during last pass */
7036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane};
7136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
7236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Main buffer control (downsampled-data buffer) */
7336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jpeg_c_main_controller {
74bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*start_pass) (j_compress_ptr cinfo, J_BUF_MODE pass_mode);
75bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*process_data) (j_compress_ptr cinfo, JSAMPARRAY input_buf,
76bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                        JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail);
7736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane};
7836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
7936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Compression preprocessing (downsampling input buffer control) */
8036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jpeg_c_prep_controller {
81bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*start_pass) (j_compress_ptr cinfo, J_BUF_MODE pass_mode);
82bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*pre_process_data) (j_compress_ptr cinfo, JSAMPARRAY input_buf,
83bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                            JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail,
84bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                            JSAMPIMAGE output_buf,
85bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                            JDIMENSION *out_row_group_ctr,
86bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                            JDIMENSION out_row_groups_avail);
8736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane};
8836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
8936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Coefficient buffer control */
9036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jpeg_c_coef_controller {
91bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*start_pass) (j_compress_ptr cinfo, J_BUF_MODE pass_mode);
92bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  boolean (*compress_data) (j_compress_ptr cinfo, JSAMPIMAGE input_buf);
9336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane};
9436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
9536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Colorspace conversion */
9636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jpeg_color_converter {
97bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*start_pass) (j_compress_ptr cinfo);
98bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*color_convert) (j_compress_ptr cinfo, JSAMPARRAY input_buf,
99bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                         JSAMPIMAGE output_buf, JDIMENSION output_row,
100bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                         int num_rows);
10136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane};
10236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
10336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Downsampling */
10436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jpeg_downsampler {
105bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*start_pass) (j_compress_ptr cinfo);
106bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*downsample) (j_compress_ptr cinfo, JSAMPIMAGE input_buf,
107bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                      JDIMENSION in_row_index, JSAMPIMAGE output_buf,
108bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                      JDIMENSION out_row_group_index);
10936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
110b775351012af176720429ac21d11682a0b75b4b7DRC  boolean need_context_rows;    /* TRUE if need rows above & below */
11136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane};
11236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
11336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Forward DCT (also controls coefficient quantization) */
11436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jpeg_forward_dct {
115bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*start_pass) (j_compress_ptr cinfo);
11636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* perhaps this should be an array??? */
1176eb7d3798b5a79347c62825fc4c16f7ce673bdd0Alex Naidis  void (*forward_DCT) (j_compress_ptr cinfo, jpeg_component_info *compptr,
118bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                       JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
119bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                       JDIMENSION start_row, JDIMENSION start_col,
120bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                       JDIMENSION num_blocks);
12136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane};
12236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
12336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Entropy encoding */
12436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jpeg_entropy_encoder {
125bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*start_pass) (j_compress_ptr cinfo, boolean gather_statistics);
126bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  boolean (*encode_mcu) (j_compress_ptr cinfo, JBLOCKROW *MCU_data);
127bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*finish_pass) (j_compress_ptr cinfo);
12836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane};
12936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
13036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Marker writing */
13136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jpeg_marker_writer {
132bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*write_file_header) (j_compress_ptr cinfo);
133bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*write_frame_header) (j_compress_ptr cinfo);
134bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*write_scan_header) (j_compress_ptr cinfo);
135bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*write_file_trailer) (j_compress_ptr cinfo);
136bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*write_tables_only) (j_compress_ptr cinfo);
1375ead57a34a398aa798f35bd7a6abad19b2e453e2Thomas G. Lane  /* These routines are exported to allow insertion of extra markers */
1385ead57a34a398aa798f35bd7a6abad19b2e453e2Thomas G. Lane  /* Probably only COM and APPn markers should be written this way */
139bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*write_marker_header) (j_compress_ptr cinfo, int marker,
140bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                               unsigned int datalen);
141bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*write_marker_byte) (j_compress_ptr cinfo, int val);
14236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane};
14336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
14436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
14536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Declarations for decompression modules */
14636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
14736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Master control module */
14836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jpeg_decomp_master {
149bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*prepare_for_output_pass) (j_decompress_ptr cinfo);
150bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*finish_output_pass) (j_decompress_ptr cinfo);
15136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
15236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* State variables made visible to other modules */
153b775351012af176720429ac21d11682a0b75b4b7DRC  boolean is_dummy_pass;        /* True during 1st pass for 2-pass quant */
1540ef076fb7b326dc201b4ab3bd30fefd4e35ad1c4DRC
1550ef076fb7b326dc201b4ab3bd30fefd4e35ad1c4DRC  /* Partial decompression variables */
1560ef076fb7b326dc201b4ab3bd30fefd4e35ad1c4DRC  JDIMENSION first_iMCU_col;
1570ef076fb7b326dc201b4ab3bd30fefd4e35ad1c4DRC  JDIMENSION last_iMCU_col;
1586eb7d3798b5a79347c62825fc4c16f7ce673bdd0Alex Naidis  JDIMENSION first_MCU_col[MAX_COMPONENTS];
1596eb7d3798b5a79347c62825fc4c16f7ce673bdd0Alex Naidis  JDIMENSION last_MCU_col[MAX_COMPONENTS];
1600ef076fb7b326dc201b4ab3bd30fefd4e35ad1c4DRC  boolean jinit_upsampler_no_alloc;
161bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane};
162bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane
163bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane/* Input control module */
164bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lanestruct jpeg_input_controller {
165bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  int (*consume_input) (j_decompress_ptr cinfo);
166bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*reset_input_controller) (j_decompress_ptr cinfo);
167bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*start_input_pass) (j_decompress_ptr cinfo);
168bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*finish_input_pass) (j_decompress_ptr cinfo);
169bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane
170bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane  /* State variables made visible to other modules */
171b775351012af176720429ac21d11682a0b75b4b7DRC  boolean has_multiple_scans;   /* True if file has multiple scans */
172b775351012af176720429ac21d11682a0b75b4b7DRC  boolean eoi_reached;          /* True when EOI has been consumed */
17336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane};
17436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
17536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Main buffer control (downsampled-data buffer) */
17636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jpeg_d_main_controller {
177bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*start_pass) (j_decompress_ptr cinfo, J_BUF_MODE pass_mode);
178bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*process_data) (j_decompress_ptr cinfo, JSAMPARRAY output_buf,
179bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                        JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail);
18036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane};
18136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
18236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Coefficient buffer control */
18336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jpeg_d_coef_controller {
184bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*start_input_pass) (j_decompress_ptr cinfo);
185bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  int (*consume_data) (j_decompress_ptr cinfo);
186bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*start_output_pass) (j_decompress_ptr cinfo);
187bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  int (*decompress_data) (j_decompress_ptr cinfo, JSAMPIMAGE output_buf);
188bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane  /* Pointer to array of coefficient virtual arrays, or NULL if none */
189bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane  jvirt_barray_ptr *coef_arrays;
19036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane};
19136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
19236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Decompression postprocessing (color quantization buffer control) */
19336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jpeg_d_post_controller {
194bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*start_pass) (j_decompress_ptr cinfo, J_BUF_MODE pass_mode);
195bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*post_process_data) (j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
196bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                             JDIMENSION *in_row_group_ctr,
197bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                             JDIMENSION in_row_groups_avail,
198bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                             JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
199bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                             JDIMENSION out_rows_avail);
20036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane};
20136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
20236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Marker reading & parsing */
20336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jpeg_marker_reader {
204bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*reset_marker_reader) (j_decompress_ptr cinfo);
20536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* Read markers until SOS or EOI.
206bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane   * Returns same codes as are defined for jpeg_consume_input:
207bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane   * JPEG_SUSPENDED, JPEG_REACHED_SOS, or JPEG_REACHED_EOI.
20836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   */
209bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  int (*read_markers) (j_decompress_ptr cinfo);
21036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* Read a restart marker --- exported for use by entropy decoder only */
21136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  jpeg_marker_parser_method read_restart_marker;
21236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
21336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* State of marker reader --- nominally internal, but applications
21436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * supplying COM or APPn handlers might like to know the state.
21536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   */
216b775351012af176720429ac21d11682a0b75b4b7DRC  boolean saw_SOI;              /* found SOI? */
217b775351012af176720429ac21d11682a0b75b4b7DRC  boolean saw_SOF;              /* found SOF? */
218b775351012af176720429ac21d11682a0b75b4b7DRC  int next_restart_num;         /* next restart number expected (0-7) */
219b775351012af176720429ac21d11682a0b75b4b7DRC  unsigned int discarded_bytes; /* # of bytes skipped looking for a marker */
22036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane};
22136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
22236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Entropy decoding */
22336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jpeg_entropy_decoder {
224bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*start_pass) (j_decompress_ptr cinfo);
225bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  boolean (*decode_mcu) (j_decompress_ptr cinfo, JBLOCKROW *MCU_data);
2265ead57a34a398aa798f35bd7a6abad19b2e453e2Thomas G. Lane
2275ead57a34a398aa798f35bd7a6abad19b2e453e2Thomas G. Lane  /* This is here to share code between baseline and progressive decoders; */
2285ead57a34a398aa798f35bd7a6abad19b2e453e2Thomas G. Lane  /* other modules probably should not use it */
229b775351012af176720429ac21d11682a0b75b4b7DRC  boolean insufficient_data;    /* set TRUE after emitting warning */
23036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane};
23136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
23236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Inverse DCT (also performs dequantization) */
233bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCtypedef void (*inverse_DCT_method_ptr) (j_decompress_ptr cinfo,
2346eb7d3798b5a79347c62825fc4c16f7ce673bdd0Alex Naidis                                        jpeg_component_info *compptr,
235bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                                        JCOEFPTR coef_block,
236bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                                        JSAMPARRAY output_buf,
237bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                                        JDIMENSION output_col);
23836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
23936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jpeg_inverse_dct {
240bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*start_pass) (j_decompress_ptr cinfo);
24136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* It is useful to allow each component to have a separate IDCT method. */
24236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  inverse_DCT_method_ptr inverse_DCT[MAX_COMPONENTS];
24336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane};
24436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
24536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Upsampling (note that upsampler must also call color converter) */
24636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jpeg_upsampler {
247bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*start_pass) (j_decompress_ptr cinfo);
248bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*upsample) (j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
249bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                    JDIMENSION *in_row_group_ctr,
250bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                    JDIMENSION in_row_groups_avail, JSAMPARRAY output_buf,
251bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                    JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail);
252b775351012af176720429ac21d11682a0b75b4b7DRC
253b775351012af176720429ac21d11682a0b75b4b7DRC  boolean need_context_rows;    /* TRUE if need rows above & below */
25436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane};
25536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
25636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Colorspace conversion */
25736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jpeg_color_deconverter {
258bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*start_pass) (j_decompress_ptr cinfo);
259bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*color_convert) (j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
260bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                         JDIMENSION input_row, JSAMPARRAY output_buf,
261bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                         int num_rows);
26236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane};
26336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
26436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Color quantization or color precision reduction */
26536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jpeg_color_quantizer {
266bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*start_pass) (j_decompress_ptr cinfo, boolean is_pre_scan);
267bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*color_quantize) (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
268bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                          JSAMPARRAY output_buf, int num_rows);
269bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*finish_pass) (j_decompress_ptr cinfo);
270bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*new_color_map) (j_decompress_ptr cinfo);
27136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane};
27236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
27336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
27436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Miscellaneous useful macros */
27536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
27636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#undef MAX
277b775351012af176720429ac21d11682a0b75b4b7DRC#define MAX(a,b)        ((a) > (b) ? (a) : (b))
27836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#undef MIN
279b775351012af176720429ac21d11682a0b75b4b7DRC#define MIN(a,b)        ((a) < (b) ? (a) : (b))
28036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
28136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
28236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* We assume that right shift corresponds to signed division by 2 with
28336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * rounding towards minus infinity.  This is correct for typical "arithmetic
28436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * shift" instructions that shift in copies of the sign bit.  But some
28536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * C compilers implement >> with an unsigned shift.  For these machines you
28636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * must define RIGHT_SHIFT_IS_UNSIGNED.
2876eb7d3798b5a79347c62825fc4c16f7ce673bdd0Alex Naidis * RIGHT_SHIFT provides a proper signed right shift of a JLONG quantity.
28836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * It is only applied with constant shift counts.  SHIFT_TEMPS must be
28936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * included in the variables of any routine using RIGHT_SHIFT.
29036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane */
29136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
29236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#ifdef RIGHT_SHIFT_IS_UNSIGNED
2936eb7d3798b5a79347c62825fc4c16f7ce673bdd0Alex Naidis#define SHIFT_TEMPS     JLONG shift_temp;
29436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#define RIGHT_SHIFT(x,shft)  \
295b775351012af176720429ac21d11682a0b75b4b7DRC        ((shift_temp = (x)) < 0 ? \
2966eb7d3798b5a79347c62825fc4c16f7ce673bdd0Alex Naidis         (shift_temp >> (shft)) | ((~((JLONG) 0)) << (32-(shft))) : \
297b775351012af176720429ac21d11682a0b75b4b7DRC         (shift_temp >> (shft)))
29836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#else
29936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#define SHIFT_TEMPS
300b775351012af176720429ac21d11682a0b75b4b7DRC#define RIGHT_SHIFT(x,shft)     ((x) >> (shft))
30136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#endif
30236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
30336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
30436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Compression module initialization routines */
305bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jinit_compress_master (j_compress_ptr cinfo);
306bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jinit_c_master_control (j_compress_ptr cinfo,
307bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                                     boolean transcode_only);
308bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jinit_c_main_controller (j_compress_ptr cinfo,
309bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                                      boolean need_full_buffer);
310bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jinit_c_prep_controller (j_compress_ptr cinfo,
311bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                                      boolean need_full_buffer);
312bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jinit_c_coef_controller (j_compress_ptr cinfo,
313bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                                      boolean need_full_buffer);
314bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jinit_color_converter (j_compress_ptr cinfo);
315bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jinit_downsampler (j_compress_ptr cinfo);
316bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jinit_forward_dct (j_compress_ptr cinfo);
317bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jinit_huff_encoder (j_compress_ptr cinfo);
318bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jinit_phuff_encoder (j_compress_ptr cinfo);
319bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jinit_arith_encoder (j_compress_ptr cinfo);
320bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jinit_marker_writer (j_compress_ptr cinfo);
32136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Decompression module initialization routines */
322bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jinit_master_decompress (j_decompress_ptr cinfo);
323bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jinit_d_main_controller (j_decompress_ptr cinfo,
324bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                                      boolean need_full_buffer);
325bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jinit_d_coef_controller (j_decompress_ptr cinfo,
326bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                                      boolean need_full_buffer);
327bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jinit_d_post_controller (j_decompress_ptr cinfo,
328bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                                      boolean need_full_buffer);
329bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jinit_input_controller (j_decompress_ptr cinfo);
330bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jinit_marker_reader (j_decompress_ptr cinfo);
331bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jinit_huff_decoder (j_decompress_ptr cinfo);
332bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jinit_phuff_decoder (j_decompress_ptr cinfo);
333bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jinit_arith_decoder (j_decompress_ptr cinfo);
334bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jinit_inverse_dct (j_decompress_ptr cinfo);
335bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jinit_upsampler (j_decompress_ptr cinfo);
336bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jinit_color_deconverter (j_decompress_ptr cinfo);
337bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jinit_1pass_quantizer (j_decompress_ptr cinfo);
338bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jinit_2pass_quantizer (j_decompress_ptr cinfo);
339bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jinit_merged_upsampler (j_decompress_ptr cinfo);
34036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Memory manager initialization */
341bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jinit_memory_mgr (j_common_ptr cinfo);
34236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
34336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Utility routines in jutils.c */
344bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(long) jdiv_round_up (long a, long b);
345bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(long) jround_up (long a, long b);
346bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jcopy_sample_rows (JSAMPARRAY input_array, int source_row,
347bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                                JSAMPARRAY output_array, int dest_row,
348bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                                int num_rows, JDIMENSION num_cols);
349bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row,
350bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                              JDIMENSION num_blocks);
3516eb7d3798b5a79347c62825fc4c16f7ce673bdd0Alex NaidisEXTERN(void) jzero_far (void *target, size_t bytestozero);
352bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane/* Constant tables in jutils.c */
353b775351012af176720429ac21d11682a0b75b4b7DRC#if 0                           /* This table is not actually needed in v6a */
354bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Laneextern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */
3555ead57a34a398aa798f35bd7a6abad19b2e453e2Thomas G. Lane#endif
356bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Laneextern const int jpeg_natural_order[]; /* zigzag coef order to natural order */
35736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
358989630f70cf1af69ebfefca8910d1647bf189712Guido Vollbeding/* Arithmetic coding probability estimation tables in jaricom.c */
3596eb7d3798b5a79347c62825fc4c16f7ce673bdd0Alex Naidisextern const JLONG jpeg_aritab[];
36036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
36136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Suppress undefined-structure complaints if necessary. */
36236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
36336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#ifdef INCOMPLETE_TYPES_BROKEN
364b775351012af176720429ac21d11682a0b75b4b7DRC#ifndef AM_MEMORY_MANAGER       /* only jmemmgr.c defines these */
36536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jvirt_sarray_control { long dummy; };
36636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jvirt_barray_control { long dummy; };
36736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#endif
36836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#endif /* INCOMPLETE_TYPES_BROKEN */
369