xref: /aosp_15_r20/external/libjpeg-turbo/jpeglib.h (revision dfc6aa5c1cfd4bc4e2018dc74aa96e29ee49c6da)
1*dfc6aa5cSAndroid Build Coastguard Worker /*
2*dfc6aa5cSAndroid Build Coastguard Worker  * jpeglib.h
3*dfc6aa5cSAndroid Build Coastguard Worker  *
4*dfc6aa5cSAndroid Build Coastguard Worker  * This file was part of the Independent JPEG Group's software:
5*dfc6aa5cSAndroid Build Coastguard Worker  * Copyright (C) 1991-1998, Thomas G. Lane.
6*dfc6aa5cSAndroid Build Coastguard Worker  * Modified 2002-2009 by Guido Vollbeding.
7*dfc6aa5cSAndroid Build Coastguard Worker  * libjpeg-turbo Modifications:
8*dfc6aa5cSAndroid Build Coastguard Worker  * Copyright (C) 2009-2011, 2013-2014, 2016-2017, 2020, D. R. Commander.
9*dfc6aa5cSAndroid Build Coastguard Worker  * Copyright (C) 2015, Google, Inc.
10*dfc6aa5cSAndroid Build Coastguard Worker  * For conditions of distribution and use, see the accompanying README.ijg
11*dfc6aa5cSAndroid Build Coastguard Worker  * file.
12*dfc6aa5cSAndroid Build Coastguard Worker  *
13*dfc6aa5cSAndroid Build Coastguard Worker  * This file defines the application interface for the JPEG library.
14*dfc6aa5cSAndroid Build Coastguard Worker  * Most applications using the library need only include this file,
15*dfc6aa5cSAndroid Build Coastguard Worker  * and perhaps jerror.h if they want to know the exact error codes.
16*dfc6aa5cSAndroid Build Coastguard Worker  */
17*dfc6aa5cSAndroid Build Coastguard Worker 
18*dfc6aa5cSAndroid Build Coastguard Worker #ifndef JPEGLIB_H
19*dfc6aa5cSAndroid Build Coastguard Worker #define JPEGLIB_H
20*dfc6aa5cSAndroid Build Coastguard Worker 
21*dfc6aa5cSAndroid Build Coastguard Worker /* Begin chromium edits */
22*dfc6aa5cSAndroid Build Coastguard Worker #ifdef MANGLE_JPEG_NAMES
23*dfc6aa5cSAndroid Build Coastguard Worker #include "jpeglibmangler.h"
24*dfc6aa5cSAndroid Build Coastguard Worker #endif
25*dfc6aa5cSAndroid Build Coastguard Worker /* End chromium edits */
26*dfc6aa5cSAndroid Build Coastguard Worker 
27*dfc6aa5cSAndroid Build Coastguard Worker /*
28*dfc6aa5cSAndroid Build Coastguard Worker  * First we include the configuration files that record how this
29*dfc6aa5cSAndroid Build Coastguard Worker  * installation of the JPEG library is set up.  jconfig.h can be
30*dfc6aa5cSAndroid Build Coastguard Worker  * generated automatically for many systems.  jmorecfg.h contains
31*dfc6aa5cSAndroid Build Coastguard Worker  * manual configuration options that most people need not worry about.
32*dfc6aa5cSAndroid Build Coastguard Worker  */
33*dfc6aa5cSAndroid Build Coastguard Worker 
34*dfc6aa5cSAndroid Build Coastguard Worker #ifndef JCONFIG_INCLUDED        /* in case jinclude.h already did */
35*dfc6aa5cSAndroid Build Coastguard Worker #include "jconfig.h"            /* widely used configuration options */
36*dfc6aa5cSAndroid Build Coastguard Worker #endif
37*dfc6aa5cSAndroid Build Coastguard Worker #include "jmorecfg.h"           /* seldom changed options */
38*dfc6aa5cSAndroid Build Coastguard Worker 
39*dfc6aa5cSAndroid Build Coastguard Worker 
40*dfc6aa5cSAndroid Build Coastguard Worker #ifdef __cplusplus
41*dfc6aa5cSAndroid Build Coastguard Worker #ifndef DONT_USE_EXTERN_C
42*dfc6aa5cSAndroid Build Coastguard Worker extern "C" {
43*dfc6aa5cSAndroid Build Coastguard Worker #endif
44*dfc6aa5cSAndroid Build Coastguard Worker #endif
45*dfc6aa5cSAndroid Build Coastguard Worker 
46*dfc6aa5cSAndroid Build Coastguard Worker 
47*dfc6aa5cSAndroid Build Coastguard Worker /* Various constants determining the sizes of things.
48*dfc6aa5cSAndroid Build Coastguard Worker  * All of these are specified by the JPEG standard, so don't change them
49*dfc6aa5cSAndroid Build Coastguard Worker  * if you want to be compatible.
50*dfc6aa5cSAndroid Build Coastguard Worker  */
51*dfc6aa5cSAndroid Build Coastguard Worker 
52*dfc6aa5cSAndroid Build Coastguard Worker #define DCTSIZE             8   /* The basic DCT block is 8x8 samples */
53*dfc6aa5cSAndroid Build Coastguard Worker #define DCTSIZE2            64  /* DCTSIZE squared; # of elements in a block */
54*dfc6aa5cSAndroid Build Coastguard Worker #define NUM_QUANT_TBLS      4   /* Quantization tables are numbered 0..3 */
55*dfc6aa5cSAndroid Build Coastguard Worker #define NUM_HUFF_TBLS       4   /* Huffman tables are numbered 0..3 */
56*dfc6aa5cSAndroid Build Coastguard Worker #define NUM_ARITH_TBLS      16  /* Arith-coding tables are numbered 0..15 */
57*dfc6aa5cSAndroid Build Coastguard Worker #define MAX_COMPS_IN_SCAN   4   /* JPEG limit on # of components in one scan */
58*dfc6aa5cSAndroid Build Coastguard Worker #define MAX_SAMP_FACTOR     4   /* JPEG limit on sampling factors */
59*dfc6aa5cSAndroid Build Coastguard Worker /* Unfortunately, some bozo at Adobe saw no reason to be bound by the standard;
60*dfc6aa5cSAndroid Build Coastguard Worker  * the PostScript DCT filter can emit files with many more than 10 blocks/MCU.
61*dfc6aa5cSAndroid Build Coastguard Worker  * If you happen to run across such a file, you can up D_MAX_BLOCKS_IN_MCU
62*dfc6aa5cSAndroid Build Coastguard Worker  * to handle it.  We even let you do this from the jconfig.h file.  However,
63*dfc6aa5cSAndroid Build Coastguard Worker  * we strongly discourage changing C_MAX_BLOCKS_IN_MCU; just because Adobe
64*dfc6aa5cSAndroid Build Coastguard Worker  * sometimes emits noncompliant files doesn't mean you should too.
65*dfc6aa5cSAndroid Build Coastguard Worker  */
66*dfc6aa5cSAndroid Build Coastguard Worker #define C_MAX_BLOCKS_IN_MCU   10 /* compressor's limit on blocks per MCU */
67*dfc6aa5cSAndroid Build Coastguard Worker #ifndef D_MAX_BLOCKS_IN_MCU
68*dfc6aa5cSAndroid Build Coastguard Worker #define D_MAX_BLOCKS_IN_MCU   10 /* decompressor's limit on blocks per MCU */
69*dfc6aa5cSAndroid Build Coastguard Worker #endif
70*dfc6aa5cSAndroid Build Coastguard Worker 
71*dfc6aa5cSAndroid Build Coastguard Worker 
72*dfc6aa5cSAndroid Build Coastguard Worker /* Data structures for images (arrays of samples and of DCT coefficients).
73*dfc6aa5cSAndroid Build Coastguard Worker  */
74*dfc6aa5cSAndroid Build Coastguard Worker 
75*dfc6aa5cSAndroid Build Coastguard Worker typedef JSAMPLE *JSAMPROW;      /* ptr to one image row of pixel samples. */
76*dfc6aa5cSAndroid Build Coastguard Worker typedef JSAMPROW *JSAMPARRAY;   /* ptr to some rows (a 2-D sample array) */
77*dfc6aa5cSAndroid Build Coastguard Worker typedef JSAMPARRAY *JSAMPIMAGE; /* a 3-D sample array: top index is color */
78*dfc6aa5cSAndroid Build Coastguard Worker 
79*dfc6aa5cSAndroid Build Coastguard Worker typedef JCOEF JBLOCK[DCTSIZE2]; /* one block of coefficients */
80*dfc6aa5cSAndroid Build Coastguard Worker typedef JBLOCK *JBLOCKROW;      /* pointer to one row of coefficient blocks */
81*dfc6aa5cSAndroid Build Coastguard Worker typedef JBLOCKROW *JBLOCKARRAY;         /* a 2-D array of coefficient blocks */
82*dfc6aa5cSAndroid Build Coastguard Worker typedef JBLOCKARRAY *JBLOCKIMAGE;       /* a 3-D array of coefficient blocks */
83*dfc6aa5cSAndroid Build Coastguard Worker 
84*dfc6aa5cSAndroid Build Coastguard Worker typedef JCOEF *JCOEFPTR;        /* useful in a couple of places */
85*dfc6aa5cSAndroid Build Coastguard Worker 
86*dfc6aa5cSAndroid Build Coastguard Worker 
87*dfc6aa5cSAndroid Build Coastguard Worker /* Types for JPEG compression parameters and working tables. */
88*dfc6aa5cSAndroid Build Coastguard Worker 
89*dfc6aa5cSAndroid Build Coastguard Worker 
90*dfc6aa5cSAndroid Build Coastguard Worker /* DCT coefficient quantization tables. */
91*dfc6aa5cSAndroid Build Coastguard Worker 
92*dfc6aa5cSAndroid Build Coastguard Worker typedef struct {
93*dfc6aa5cSAndroid Build Coastguard Worker   /* This array gives the coefficient quantizers in natural array order
94*dfc6aa5cSAndroid Build Coastguard Worker    * (not the zigzag order in which they are stored in a JPEG DQT marker).
95*dfc6aa5cSAndroid Build Coastguard Worker    * CAUTION: IJG versions prior to v6a kept this array in zigzag order.
96*dfc6aa5cSAndroid Build Coastguard Worker    */
97*dfc6aa5cSAndroid Build Coastguard Worker   UINT16 quantval[DCTSIZE2];    /* quantization step for each coefficient */
98*dfc6aa5cSAndroid Build Coastguard Worker   /* This field is used only during compression.  It's initialized FALSE when
99*dfc6aa5cSAndroid Build Coastguard Worker    * the table is created, and set TRUE when it's been output to the file.
100*dfc6aa5cSAndroid Build Coastguard Worker    * You could suppress output of a table by setting this to TRUE.
101*dfc6aa5cSAndroid Build Coastguard Worker    * (See jpeg_suppress_tables for an example.)
102*dfc6aa5cSAndroid Build Coastguard Worker    */
103*dfc6aa5cSAndroid Build Coastguard Worker   boolean sent_table;           /* TRUE when table has been output */
104*dfc6aa5cSAndroid Build Coastguard Worker } JQUANT_TBL;
105*dfc6aa5cSAndroid Build Coastguard Worker 
106*dfc6aa5cSAndroid Build Coastguard Worker 
107*dfc6aa5cSAndroid Build Coastguard Worker /* Huffman coding tables. */
108*dfc6aa5cSAndroid Build Coastguard Worker 
109*dfc6aa5cSAndroid Build Coastguard Worker typedef struct {
110*dfc6aa5cSAndroid Build Coastguard Worker   /* These two fields directly represent the contents of a JPEG DHT marker */
111*dfc6aa5cSAndroid Build Coastguard Worker   UINT8 bits[17];               /* bits[k] = # of symbols with codes of */
112*dfc6aa5cSAndroid Build Coastguard Worker                                 /* length k bits; bits[0] is unused */
113*dfc6aa5cSAndroid Build Coastguard Worker   UINT8 huffval[256];           /* The symbols, in order of incr code length */
114*dfc6aa5cSAndroid Build Coastguard Worker   /* This field is used only during compression.  It's initialized FALSE when
115*dfc6aa5cSAndroid Build Coastguard Worker    * the table is created, and set TRUE when it's been output to the file.
116*dfc6aa5cSAndroid Build Coastguard Worker    * You could suppress output of a table by setting this to TRUE.
117*dfc6aa5cSAndroid Build Coastguard Worker    * (See jpeg_suppress_tables for an example.)
118*dfc6aa5cSAndroid Build Coastguard Worker    */
119*dfc6aa5cSAndroid Build Coastguard Worker   boolean sent_table;           /* TRUE when table has been output */
120*dfc6aa5cSAndroid Build Coastguard Worker } JHUFF_TBL;
121*dfc6aa5cSAndroid Build Coastguard Worker 
122*dfc6aa5cSAndroid Build Coastguard Worker 
123*dfc6aa5cSAndroid Build Coastguard Worker /* Basic info about one component (color channel). */
124*dfc6aa5cSAndroid Build Coastguard Worker 
125*dfc6aa5cSAndroid Build Coastguard Worker typedef struct {
126*dfc6aa5cSAndroid Build Coastguard Worker   /* These values are fixed over the whole image. */
127*dfc6aa5cSAndroid Build Coastguard Worker   /* For compression, they must be supplied by parameter setup; */
128*dfc6aa5cSAndroid Build Coastguard Worker   /* for decompression, they are read from the SOF marker. */
129*dfc6aa5cSAndroid Build Coastguard Worker   int component_id;             /* identifier for this component (0..255) */
130*dfc6aa5cSAndroid Build Coastguard Worker   int component_index;          /* its index in SOF or cinfo->comp_info[] */
131*dfc6aa5cSAndroid Build Coastguard Worker   int h_samp_factor;            /* horizontal sampling factor (1..4) */
132*dfc6aa5cSAndroid Build Coastguard Worker   int v_samp_factor;            /* vertical sampling factor (1..4) */
133*dfc6aa5cSAndroid Build Coastguard Worker   int quant_tbl_no;             /* quantization table selector (0..3) */
134*dfc6aa5cSAndroid Build Coastguard Worker   /* These values may vary between scans. */
135*dfc6aa5cSAndroid Build Coastguard Worker   /* For compression, they must be supplied by parameter setup; */
136*dfc6aa5cSAndroid Build Coastguard Worker   /* for decompression, they are read from the SOS marker. */
137*dfc6aa5cSAndroid Build Coastguard Worker   /* The decompressor output side may not use these variables. */
138*dfc6aa5cSAndroid Build Coastguard Worker   int dc_tbl_no;                /* DC entropy table selector (0..3) */
139*dfc6aa5cSAndroid Build Coastguard Worker   int ac_tbl_no;                /* AC entropy table selector (0..3) */
140*dfc6aa5cSAndroid Build Coastguard Worker 
141*dfc6aa5cSAndroid Build Coastguard Worker   /* Remaining fields should be treated as private by applications. */
142*dfc6aa5cSAndroid Build Coastguard Worker 
143*dfc6aa5cSAndroid Build Coastguard Worker   /* These values are computed during compression or decompression startup: */
144*dfc6aa5cSAndroid Build Coastguard Worker   /* Component's size in DCT blocks.
145*dfc6aa5cSAndroid Build Coastguard Worker    * Any dummy blocks added to complete an MCU are not counted; therefore
146*dfc6aa5cSAndroid Build Coastguard Worker    * these values do not depend on whether a scan is interleaved or not.
147*dfc6aa5cSAndroid Build Coastguard Worker    */
148*dfc6aa5cSAndroid Build Coastguard Worker   JDIMENSION width_in_blocks;
149*dfc6aa5cSAndroid Build Coastguard Worker   JDIMENSION height_in_blocks;
150*dfc6aa5cSAndroid Build Coastguard Worker   /* Size of a DCT block in samples.  Always DCTSIZE for compression.
151*dfc6aa5cSAndroid Build Coastguard Worker    * For decompression this is the size of the output from one DCT block,
152*dfc6aa5cSAndroid Build Coastguard Worker    * reflecting any scaling we choose to apply during the IDCT step.
153*dfc6aa5cSAndroid Build Coastguard Worker    * Values from 1 to 16 are supported.
154*dfc6aa5cSAndroid Build Coastguard Worker    * Note that different components may receive different IDCT scalings.
155*dfc6aa5cSAndroid Build Coastguard Worker    */
156*dfc6aa5cSAndroid Build Coastguard Worker #if JPEG_LIB_VERSION >= 70
157*dfc6aa5cSAndroid Build Coastguard Worker   int DCT_h_scaled_size;
158*dfc6aa5cSAndroid Build Coastguard Worker   int DCT_v_scaled_size;
159*dfc6aa5cSAndroid Build Coastguard Worker #else
160*dfc6aa5cSAndroid Build Coastguard Worker   int DCT_scaled_size;
161*dfc6aa5cSAndroid Build Coastguard Worker #endif
162*dfc6aa5cSAndroid Build Coastguard Worker   /* The downsampled dimensions are the component's actual, unpadded number
163*dfc6aa5cSAndroid Build Coastguard Worker    * of samples at the main buffer (preprocessing/compression interface), thus
164*dfc6aa5cSAndroid Build Coastguard Worker    * downsampled_width = ceil(image_width * Hi/Hmax)
165*dfc6aa5cSAndroid Build Coastguard Worker    * and similarly for height.  For decompression, IDCT scaling is included, so
166*dfc6aa5cSAndroid Build Coastguard Worker    * downsampled_width = ceil(image_width * Hi/Hmax * DCT_[h_]scaled_size/DCTSIZE)
167*dfc6aa5cSAndroid Build Coastguard Worker    */
168*dfc6aa5cSAndroid Build Coastguard Worker   JDIMENSION downsampled_width;  /* actual width in samples */
169*dfc6aa5cSAndroid Build Coastguard Worker   JDIMENSION downsampled_height; /* actual height in samples */
170*dfc6aa5cSAndroid Build Coastguard Worker   /* This flag is used only for decompression.  In cases where some of the
171*dfc6aa5cSAndroid Build Coastguard Worker    * components will be ignored (eg grayscale output from YCbCr image),
172*dfc6aa5cSAndroid Build Coastguard Worker    * we can skip most computations for the unused components.
173*dfc6aa5cSAndroid Build Coastguard Worker    */
174*dfc6aa5cSAndroid Build Coastguard Worker   boolean component_needed;     /* do we need the value of this component? */
175*dfc6aa5cSAndroid Build Coastguard Worker 
176*dfc6aa5cSAndroid Build Coastguard Worker   /* These values are computed before starting a scan of the component. */
177*dfc6aa5cSAndroid Build Coastguard Worker   /* The decompressor output side may not use these variables. */
178*dfc6aa5cSAndroid Build Coastguard Worker   int MCU_width;                /* number of blocks per MCU, horizontally */
179*dfc6aa5cSAndroid Build Coastguard Worker   int MCU_height;               /* number of blocks per MCU, vertically */
180*dfc6aa5cSAndroid Build Coastguard Worker   int MCU_blocks;               /* MCU_width * MCU_height */
181*dfc6aa5cSAndroid Build Coastguard Worker   int MCU_sample_width;         /* MCU width in samples, MCU_width*DCT_[h_]scaled_size */
182*dfc6aa5cSAndroid Build Coastguard Worker   int last_col_width;           /* # of non-dummy blocks across in last MCU */
183*dfc6aa5cSAndroid Build Coastguard Worker   int last_row_height;          /* # of non-dummy blocks down in last MCU */
184*dfc6aa5cSAndroid Build Coastguard Worker 
185*dfc6aa5cSAndroid Build Coastguard Worker   /* Saved quantization table for component; NULL if none yet saved.
186*dfc6aa5cSAndroid Build Coastguard Worker    * See jdinput.c comments about the need for this information.
187*dfc6aa5cSAndroid Build Coastguard Worker    * This field is currently used only for decompression.
188*dfc6aa5cSAndroid Build Coastguard Worker    */
189*dfc6aa5cSAndroid Build Coastguard Worker   JQUANT_TBL *quant_table;
190*dfc6aa5cSAndroid Build Coastguard Worker 
191*dfc6aa5cSAndroid Build Coastguard Worker   /* Private per-component storage for DCT or IDCT subsystem. */
192*dfc6aa5cSAndroid Build Coastguard Worker   void *dct_table;
193*dfc6aa5cSAndroid Build Coastguard Worker } jpeg_component_info;
194*dfc6aa5cSAndroid Build Coastguard Worker 
195*dfc6aa5cSAndroid Build Coastguard Worker 
196*dfc6aa5cSAndroid Build Coastguard Worker /* The script for encoding a multiple-scan file is an array of these: */
197*dfc6aa5cSAndroid Build Coastguard Worker 
198*dfc6aa5cSAndroid Build Coastguard Worker typedef struct {
199*dfc6aa5cSAndroid Build Coastguard Worker   int comps_in_scan;            /* number of components encoded in this scan */
200*dfc6aa5cSAndroid Build Coastguard Worker   int component_index[MAX_COMPS_IN_SCAN]; /* their SOF/comp_info[] indexes */
201*dfc6aa5cSAndroid Build Coastguard Worker   int Ss, Se;                   /* progressive JPEG spectral selection parms */
202*dfc6aa5cSAndroid Build Coastguard Worker   int Ah, Al;                   /* progressive JPEG successive approx. parms */
203*dfc6aa5cSAndroid Build Coastguard Worker } jpeg_scan_info;
204*dfc6aa5cSAndroid Build Coastguard Worker 
205*dfc6aa5cSAndroid Build Coastguard Worker /* The decompressor can save APPn and COM markers in a list of these: */
206*dfc6aa5cSAndroid Build Coastguard Worker 
207*dfc6aa5cSAndroid Build Coastguard Worker typedef struct jpeg_marker_struct *jpeg_saved_marker_ptr;
208*dfc6aa5cSAndroid Build Coastguard Worker 
209*dfc6aa5cSAndroid Build Coastguard Worker struct jpeg_marker_struct {
210*dfc6aa5cSAndroid Build Coastguard Worker   jpeg_saved_marker_ptr next;   /* next in list, or NULL */
211*dfc6aa5cSAndroid Build Coastguard Worker   UINT8 marker;                 /* marker code: JPEG_COM, or JPEG_APP0+n */
212*dfc6aa5cSAndroid Build Coastguard Worker   unsigned int original_length; /* # bytes of data in the file */
213*dfc6aa5cSAndroid Build Coastguard Worker   unsigned int data_length;     /* # bytes of data saved at data[] */
214*dfc6aa5cSAndroid Build Coastguard Worker   JOCTET *data;                 /* the data contained in the marker */
215*dfc6aa5cSAndroid Build Coastguard Worker   /* the marker length word is not counted in data_length or original_length */
216*dfc6aa5cSAndroid Build Coastguard Worker };
217*dfc6aa5cSAndroid Build Coastguard Worker 
218*dfc6aa5cSAndroid Build Coastguard Worker /* Known color spaces. */
219*dfc6aa5cSAndroid Build Coastguard Worker 
220*dfc6aa5cSAndroid Build Coastguard Worker #define JCS_EXTENSIONS  1
221*dfc6aa5cSAndroid Build Coastguard Worker #define JCS_ALPHA_EXTENSIONS  1
222*dfc6aa5cSAndroid Build Coastguard Worker 
223*dfc6aa5cSAndroid Build Coastguard Worker typedef enum {
224*dfc6aa5cSAndroid Build Coastguard Worker   JCS_UNKNOWN,            /* error/unspecified */
225*dfc6aa5cSAndroid Build Coastguard Worker   JCS_GRAYSCALE,          /* monochrome */
226*dfc6aa5cSAndroid Build Coastguard Worker   JCS_RGB,                /* red/green/blue as specified by the RGB_RED,
227*dfc6aa5cSAndroid Build Coastguard Worker                              RGB_GREEN, RGB_BLUE, and RGB_PIXELSIZE macros */
228*dfc6aa5cSAndroid Build Coastguard Worker   JCS_YCbCr,              /* Y/Cb/Cr (also known as YUV) */
229*dfc6aa5cSAndroid Build Coastguard Worker   JCS_CMYK,               /* C/M/Y/K */
230*dfc6aa5cSAndroid Build Coastguard Worker   JCS_YCCK,               /* Y/Cb/Cr/K */
231*dfc6aa5cSAndroid Build Coastguard Worker   JCS_EXT_RGB,            /* red/green/blue */
232*dfc6aa5cSAndroid Build Coastguard Worker   JCS_EXT_RGBX,           /* red/green/blue/x */
233*dfc6aa5cSAndroid Build Coastguard Worker   JCS_EXT_BGR,            /* blue/green/red */
234*dfc6aa5cSAndroid Build Coastguard Worker   JCS_EXT_BGRX,           /* blue/green/red/x */
235*dfc6aa5cSAndroid Build Coastguard Worker   JCS_EXT_XBGR,           /* x/blue/green/red */
236*dfc6aa5cSAndroid Build Coastguard Worker   JCS_EXT_XRGB,           /* x/red/green/blue */
237*dfc6aa5cSAndroid Build Coastguard Worker   /* When out_color_space it set to JCS_EXT_RGBX, JCS_EXT_BGRX, JCS_EXT_XBGR,
238*dfc6aa5cSAndroid Build Coastguard Worker      or JCS_EXT_XRGB during decompression, the X byte is undefined, and in
239*dfc6aa5cSAndroid Build Coastguard Worker      order to ensure the best performance, libjpeg-turbo can set that byte to
240*dfc6aa5cSAndroid Build Coastguard Worker      whatever value it wishes.  Use the following colorspace constants to
241*dfc6aa5cSAndroid Build Coastguard Worker      ensure that the X byte is set to 0xFF, so that it can be interpreted as an
242*dfc6aa5cSAndroid Build Coastguard Worker      opaque alpha channel. */
243*dfc6aa5cSAndroid Build Coastguard Worker   JCS_EXT_RGBA,           /* red/green/blue/alpha */
244*dfc6aa5cSAndroid Build Coastguard Worker   JCS_EXT_BGRA,           /* blue/green/red/alpha */
245*dfc6aa5cSAndroid Build Coastguard Worker   JCS_EXT_ABGR,           /* alpha/blue/green/red */
246*dfc6aa5cSAndroid Build Coastguard Worker   JCS_EXT_ARGB,           /* alpha/red/green/blue */
247*dfc6aa5cSAndroid Build Coastguard Worker   JCS_RGB565              /* 5-bit red/6-bit green/5-bit blue */
248*dfc6aa5cSAndroid Build Coastguard Worker } J_COLOR_SPACE;
249*dfc6aa5cSAndroid Build Coastguard Worker 
250*dfc6aa5cSAndroid Build Coastguard Worker /* DCT/IDCT algorithm options. */
251*dfc6aa5cSAndroid Build Coastguard Worker 
252*dfc6aa5cSAndroid Build Coastguard Worker typedef enum {
253*dfc6aa5cSAndroid Build Coastguard Worker   JDCT_ISLOW,             /* accurate integer method */
254*dfc6aa5cSAndroid Build Coastguard Worker   JDCT_IFAST,             /* less accurate integer method [legacy feature] */
255*dfc6aa5cSAndroid Build Coastguard Worker   JDCT_FLOAT              /* floating-point method [legacy feature] */
256*dfc6aa5cSAndroid Build Coastguard Worker } J_DCT_METHOD;
257*dfc6aa5cSAndroid Build Coastguard Worker 
258*dfc6aa5cSAndroid Build Coastguard Worker #ifndef JDCT_DEFAULT            /* may be overridden in jconfig.h */
259*dfc6aa5cSAndroid Build Coastguard Worker #define JDCT_DEFAULT  JDCT_ISLOW
260*dfc6aa5cSAndroid Build Coastguard Worker #endif
261*dfc6aa5cSAndroid Build Coastguard Worker #ifndef JDCT_FASTEST            /* may be overridden in jconfig.h */
262*dfc6aa5cSAndroid Build Coastguard Worker #define JDCT_FASTEST  JDCT_IFAST
263*dfc6aa5cSAndroid Build Coastguard Worker #endif
264*dfc6aa5cSAndroid Build Coastguard Worker 
265*dfc6aa5cSAndroid Build Coastguard Worker /* Dithering options for decompression. */
266*dfc6aa5cSAndroid Build Coastguard Worker 
267*dfc6aa5cSAndroid Build Coastguard Worker typedef enum {
268*dfc6aa5cSAndroid Build Coastguard Worker   JDITHER_NONE,           /* no dithering */
269*dfc6aa5cSAndroid Build Coastguard Worker   JDITHER_ORDERED,        /* simple ordered dither */
270*dfc6aa5cSAndroid Build Coastguard Worker   JDITHER_FS              /* Floyd-Steinberg error diffusion dither */
271*dfc6aa5cSAndroid Build Coastguard Worker } J_DITHER_MODE;
272*dfc6aa5cSAndroid Build Coastguard Worker 
273*dfc6aa5cSAndroid Build Coastguard Worker 
274*dfc6aa5cSAndroid Build Coastguard Worker /* Common fields between JPEG compression and decompression master structs. */
275*dfc6aa5cSAndroid Build Coastguard Worker 
276*dfc6aa5cSAndroid Build Coastguard Worker #define jpeg_common_fields \
277*dfc6aa5cSAndroid Build Coastguard Worker   struct jpeg_error_mgr *err;   /* Error handler module */ \
278*dfc6aa5cSAndroid Build Coastguard Worker   struct jpeg_memory_mgr *mem;  /* Memory manager module */ \
279*dfc6aa5cSAndroid Build Coastguard Worker   struct jpeg_progress_mgr *progress; /* Progress monitor, or NULL if none */ \
280*dfc6aa5cSAndroid Build Coastguard Worker   void *client_data;            /* Available for use by application */ \
281*dfc6aa5cSAndroid Build Coastguard Worker   boolean is_decompressor;      /* So common code can tell which is which */ \
282*dfc6aa5cSAndroid Build Coastguard Worker   int global_state              /* For checking call sequence validity */
283*dfc6aa5cSAndroid Build Coastguard Worker 
284*dfc6aa5cSAndroid Build Coastguard Worker /* Routines that are to be used by both halves of the library are declared
285*dfc6aa5cSAndroid Build Coastguard Worker  * to receive a pointer to this structure.  There are no actual instances of
286*dfc6aa5cSAndroid Build Coastguard Worker  * jpeg_common_struct, only of jpeg_compress_struct and jpeg_decompress_struct.
287*dfc6aa5cSAndroid Build Coastguard Worker  */
288*dfc6aa5cSAndroid Build Coastguard Worker struct jpeg_common_struct {
289*dfc6aa5cSAndroid Build Coastguard Worker   jpeg_common_fields;           /* Fields common to both master struct types */
290*dfc6aa5cSAndroid Build Coastguard Worker   /* Additional fields follow in an actual jpeg_compress_struct or
291*dfc6aa5cSAndroid Build Coastguard Worker    * jpeg_decompress_struct.  All three structs must agree on these
292*dfc6aa5cSAndroid Build Coastguard Worker    * initial fields!  (This would be a lot cleaner in C++.)
293*dfc6aa5cSAndroid Build Coastguard Worker    */
294*dfc6aa5cSAndroid Build Coastguard Worker };
295*dfc6aa5cSAndroid Build Coastguard Worker 
296*dfc6aa5cSAndroid Build Coastguard Worker typedef struct jpeg_common_struct *j_common_ptr;
297*dfc6aa5cSAndroid Build Coastguard Worker typedef struct jpeg_compress_struct *j_compress_ptr;
298*dfc6aa5cSAndroid Build Coastguard Worker typedef struct jpeg_decompress_struct *j_decompress_ptr;
299*dfc6aa5cSAndroid Build Coastguard Worker 
300*dfc6aa5cSAndroid Build Coastguard Worker 
301*dfc6aa5cSAndroid Build Coastguard Worker /* Master record for a compression instance */
302*dfc6aa5cSAndroid Build Coastguard Worker 
303*dfc6aa5cSAndroid Build Coastguard Worker struct jpeg_compress_struct {
304*dfc6aa5cSAndroid Build Coastguard Worker   jpeg_common_fields;           /* Fields shared with jpeg_decompress_struct */
305*dfc6aa5cSAndroid Build Coastguard Worker 
306*dfc6aa5cSAndroid Build Coastguard Worker   /* Destination for compressed data */
307*dfc6aa5cSAndroid Build Coastguard Worker   struct jpeg_destination_mgr *dest;
308*dfc6aa5cSAndroid Build Coastguard Worker 
309*dfc6aa5cSAndroid Build Coastguard Worker   /* Description of source image --- these fields must be filled in by
310*dfc6aa5cSAndroid Build Coastguard Worker    * outer application before starting compression.  in_color_space must
311*dfc6aa5cSAndroid Build Coastguard Worker    * be correct before you can even call jpeg_set_defaults().
312*dfc6aa5cSAndroid Build Coastguard Worker    */
313*dfc6aa5cSAndroid Build Coastguard Worker 
314*dfc6aa5cSAndroid Build Coastguard Worker   JDIMENSION image_width;       /* input image width */
315*dfc6aa5cSAndroid Build Coastguard Worker   JDIMENSION image_height;      /* input image height */
316*dfc6aa5cSAndroid Build Coastguard Worker   int input_components;         /* # of color components in input image */
317*dfc6aa5cSAndroid Build Coastguard Worker   J_COLOR_SPACE in_color_space; /* colorspace of input image */
318*dfc6aa5cSAndroid Build Coastguard Worker 
319*dfc6aa5cSAndroid Build Coastguard Worker   double input_gamma;           /* image gamma of input image */
320*dfc6aa5cSAndroid Build Coastguard Worker 
321*dfc6aa5cSAndroid Build Coastguard Worker   /* Compression parameters --- these fields must be set before calling
322*dfc6aa5cSAndroid Build Coastguard Worker    * jpeg_start_compress().  We recommend calling jpeg_set_defaults() to
323*dfc6aa5cSAndroid Build Coastguard Worker    * initialize everything to reasonable defaults, then changing anything
324*dfc6aa5cSAndroid Build Coastguard Worker    * the application specifically wants to change.  That way you won't get
325*dfc6aa5cSAndroid Build Coastguard Worker    * burnt when new parameters are added.  Also note that there are several
326*dfc6aa5cSAndroid Build Coastguard Worker    * helper routines to simplify changing parameters.
327*dfc6aa5cSAndroid Build Coastguard Worker    */
328*dfc6aa5cSAndroid Build Coastguard Worker 
329*dfc6aa5cSAndroid Build Coastguard Worker #if JPEG_LIB_VERSION >= 70
330*dfc6aa5cSAndroid Build Coastguard Worker   unsigned int scale_num, scale_denom; /* fraction by which to scale image */
331*dfc6aa5cSAndroid Build Coastguard Worker 
332*dfc6aa5cSAndroid Build Coastguard Worker   JDIMENSION jpeg_width;        /* scaled JPEG image width */
333*dfc6aa5cSAndroid Build Coastguard Worker   JDIMENSION jpeg_height;       /* scaled JPEG image height */
334*dfc6aa5cSAndroid Build Coastguard Worker   /* Dimensions of actual JPEG image that will be written to file,
335*dfc6aa5cSAndroid Build Coastguard Worker    * derived from input dimensions by scaling factors above.
336*dfc6aa5cSAndroid Build Coastguard Worker    * These fields are computed by jpeg_start_compress().
337*dfc6aa5cSAndroid Build Coastguard Worker    * You can also use jpeg_calc_jpeg_dimensions() to determine these values
338*dfc6aa5cSAndroid Build Coastguard Worker    * in advance of calling jpeg_start_compress().
339*dfc6aa5cSAndroid Build Coastguard Worker    */
340*dfc6aa5cSAndroid Build Coastguard Worker #endif
341*dfc6aa5cSAndroid Build Coastguard Worker 
342*dfc6aa5cSAndroid Build Coastguard Worker   int data_precision;           /* bits of precision in image data */
343*dfc6aa5cSAndroid Build Coastguard Worker 
344*dfc6aa5cSAndroid Build Coastguard Worker   int num_components;           /* # of color components in JPEG image */
345*dfc6aa5cSAndroid Build Coastguard Worker   J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
346*dfc6aa5cSAndroid Build Coastguard Worker 
347*dfc6aa5cSAndroid Build Coastguard Worker   jpeg_component_info *comp_info;
348*dfc6aa5cSAndroid Build Coastguard Worker   /* comp_info[i] describes component that appears i'th in SOF */
349*dfc6aa5cSAndroid Build Coastguard Worker 
350*dfc6aa5cSAndroid Build Coastguard Worker   JQUANT_TBL *quant_tbl_ptrs[NUM_QUANT_TBLS];
351*dfc6aa5cSAndroid Build Coastguard Worker #if JPEG_LIB_VERSION >= 70
352*dfc6aa5cSAndroid Build Coastguard Worker   int q_scale_factor[NUM_QUANT_TBLS];
353*dfc6aa5cSAndroid Build Coastguard Worker #endif
354*dfc6aa5cSAndroid Build Coastguard Worker   /* ptrs to coefficient quantization tables, or NULL if not defined,
355*dfc6aa5cSAndroid Build Coastguard Worker    * and corresponding scale factors (percentage, initialized 100).
356*dfc6aa5cSAndroid Build Coastguard Worker    */
357*dfc6aa5cSAndroid Build Coastguard Worker 
358*dfc6aa5cSAndroid Build Coastguard Worker   JHUFF_TBL *dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
359*dfc6aa5cSAndroid Build Coastguard Worker   JHUFF_TBL *ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
360*dfc6aa5cSAndroid Build Coastguard Worker   /* ptrs to Huffman coding tables, or NULL if not defined */
361*dfc6aa5cSAndroid Build Coastguard Worker 
362*dfc6aa5cSAndroid Build Coastguard Worker   UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
363*dfc6aa5cSAndroid Build Coastguard Worker   UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
364*dfc6aa5cSAndroid Build Coastguard Worker   UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
365*dfc6aa5cSAndroid Build Coastguard Worker 
366*dfc6aa5cSAndroid Build Coastguard Worker   int num_scans;                /* # of entries in scan_info array */
367*dfc6aa5cSAndroid Build Coastguard Worker   const jpeg_scan_info *scan_info; /* script for multi-scan file, or NULL */
368*dfc6aa5cSAndroid Build Coastguard Worker   /* The default value of scan_info is NULL, which causes a single-scan
369*dfc6aa5cSAndroid Build Coastguard Worker    * sequential JPEG file to be emitted.  To create a multi-scan file,
370*dfc6aa5cSAndroid Build Coastguard Worker    * set num_scans and scan_info to point to an array of scan definitions.
371*dfc6aa5cSAndroid Build Coastguard Worker    */
372*dfc6aa5cSAndroid Build Coastguard Worker 
373*dfc6aa5cSAndroid Build Coastguard Worker   boolean raw_data_in;          /* TRUE=caller supplies downsampled data */
374*dfc6aa5cSAndroid Build Coastguard Worker   boolean arith_code;           /* TRUE=arithmetic coding, FALSE=Huffman */
375*dfc6aa5cSAndroid Build Coastguard Worker   boolean optimize_coding;      /* TRUE=optimize entropy encoding parms */
376*dfc6aa5cSAndroid Build Coastguard Worker   boolean CCIR601_sampling;     /* TRUE=first samples are cosited */
377*dfc6aa5cSAndroid Build Coastguard Worker #if JPEG_LIB_VERSION >= 70
378*dfc6aa5cSAndroid Build Coastguard Worker   boolean do_fancy_downsampling; /* TRUE=apply fancy downsampling */
379*dfc6aa5cSAndroid Build Coastguard Worker #endif
380*dfc6aa5cSAndroid Build Coastguard Worker   int smoothing_factor;         /* 1..100, or 0 for no input smoothing */
381*dfc6aa5cSAndroid Build Coastguard Worker   J_DCT_METHOD dct_method;      /* DCT algorithm selector */
382*dfc6aa5cSAndroid Build Coastguard Worker 
383*dfc6aa5cSAndroid Build Coastguard Worker   /* The restart interval can be specified in absolute MCUs by setting
384*dfc6aa5cSAndroid Build Coastguard Worker    * restart_interval, or in MCU rows by setting restart_in_rows
385*dfc6aa5cSAndroid Build Coastguard Worker    * (in which case the correct restart_interval will be figured
386*dfc6aa5cSAndroid Build Coastguard Worker    * for each scan).
387*dfc6aa5cSAndroid Build Coastguard Worker    */
388*dfc6aa5cSAndroid Build Coastguard Worker   unsigned int restart_interval; /* MCUs per restart, or 0 for no restart */
389*dfc6aa5cSAndroid Build Coastguard Worker   int restart_in_rows;          /* if > 0, MCU rows per restart interval */
390*dfc6aa5cSAndroid Build Coastguard Worker 
391*dfc6aa5cSAndroid Build Coastguard Worker   /* Parameters controlling emission of special markers. */
392*dfc6aa5cSAndroid Build Coastguard Worker 
393*dfc6aa5cSAndroid Build Coastguard Worker   boolean write_JFIF_header;    /* should a JFIF marker be written? */
394*dfc6aa5cSAndroid Build Coastguard Worker   UINT8 JFIF_major_version;     /* What to write for the JFIF version number */
395*dfc6aa5cSAndroid Build Coastguard Worker   UINT8 JFIF_minor_version;
396*dfc6aa5cSAndroid Build Coastguard Worker   /* These three values are not used by the JPEG code, merely copied */
397*dfc6aa5cSAndroid Build Coastguard Worker   /* into the JFIF APP0 marker.  density_unit can be 0 for unknown, */
398*dfc6aa5cSAndroid Build Coastguard Worker   /* 1 for dots/inch, or 2 for dots/cm.  Note that the pixel aspect */
399*dfc6aa5cSAndroid Build Coastguard Worker   /* ratio is defined by X_density/Y_density even when density_unit=0. */
400*dfc6aa5cSAndroid Build Coastguard Worker   UINT8 density_unit;           /* JFIF code for pixel size units */
401*dfc6aa5cSAndroid Build Coastguard Worker   UINT16 X_density;             /* Horizontal pixel density */
402*dfc6aa5cSAndroid Build Coastguard Worker   UINT16 Y_density;             /* Vertical pixel density */
403*dfc6aa5cSAndroid Build Coastguard Worker   boolean write_Adobe_marker;   /* should an Adobe marker be written? */
404*dfc6aa5cSAndroid Build Coastguard Worker 
405*dfc6aa5cSAndroid Build Coastguard Worker   /* State variable: index of next scanline to be written to
406*dfc6aa5cSAndroid Build Coastguard Worker    * jpeg_write_scanlines().  Application may use this to control its
407*dfc6aa5cSAndroid Build Coastguard Worker    * processing loop, e.g., "while (next_scanline < image_height)".
408*dfc6aa5cSAndroid Build Coastguard Worker    */
409*dfc6aa5cSAndroid Build Coastguard Worker 
410*dfc6aa5cSAndroid Build Coastguard Worker   JDIMENSION next_scanline;     /* 0 .. image_height-1  */
411*dfc6aa5cSAndroid Build Coastguard Worker 
412*dfc6aa5cSAndroid Build Coastguard Worker   /* Remaining fields are known throughout compressor, but generally
413*dfc6aa5cSAndroid Build Coastguard Worker    * should not be touched by a surrounding application.
414*dfc6aa5cSAndroid Build Coastguard Worker    */
415*dfc6aa5cSAndroid Build Coastguard Worker 
416*dfc6aa5cSAndroid Build Coastguard Worker   /*
417*dfc6aa5cSAndroid Build Coastguard Worker    * These fields are computed during compression startup
418*dfc6aa5cSAndroid Build Coastguard Worker    */
419*dfc6aa5cSAndroid Build Coastguard Worker   boolean progressive_mode;     /* TRUE if scan script uses progressive mode */
420*dfc6aa5cSAndroid Build Coastguard Worker   int max_h_samp_factor;        /* largest h_samp_factor */
421*dfc6aa5cSAndroid Build Coastguard Worker   int max_v_samp_factor;        /* largest v_samp_factor */
422*dfc6aa5cSAndroid Build Coastguard Worker 
423*dfc6aa5cSAndroid Build Coastguard Worker #if JPEG_LIB_VERSION >= 70
424*dfc6aa5cSAndroid Build Coastguard Worker   int min_DCT_h_scaled_size;    /* smallest DCT_h_scaled_size of any component */
425*dfc6aa5cSAndroid Build Coastguard Worker   int min_DCT_v_scaled_size;    /* smallest DCT_v_scaled_size of any component */
426*dfc6aa5cSAndroid Build Coastguard Worker #endif
427*dfc6aa5cSAndroid Build Coastguard Worker 
428*dfc6aa5cSAndroid Build Coastguard Worker   JDIMENSION total_iMCU_rows;   /* # of iMCU rows to be input to coef ctlr */
429*dfc6aa5cSAndroid Build Coastguard Worker   /* The coefficient controller receives data in units of MCU rows as defined
430*dfc6aa5cSAndroid Build Coastguard Worker    * for fully interleaved scans (whether the JPEG file is interleaved or not).
431*dfc6aa5cSAndroid Build Coastguard Worker    * There are v_samp_factor * DCTSIZE sample rows of each component in an
432*dfc6aa5cSAndroid Build Coastguard Worker    * "iMCU" (interleaved MCU) row.
433*dfc6aa5cSAndroid Build Coastguard Worker    */
434*dfc6aa5cSAndroid Build Coastguard Worker 
435*dfc6aa5cSAndroid Build Coastguard Worker   /*
436*dfc6aa5cSAndroid Build Coastguard Worker    * These fields are valid during any one scan.
437*dfc6aa5cSAndroid Build Coastguard Worker    * They describe the components and MCUs actually appearing in the scan.
438*dfc6aa5cSAndroid Build Coastguard Worker    */
439*dfc6aa5cSAndroid Build Coastguard Worker   int comps_in_scan;            /* # of JPEG components in this scan */
440*dfc6aa5cSAndroid Build Coastguard Worker   jpeg_component_info *cur_comp_info[MAX_COMPS_IN_SCAN];
441*dfc6aa5cSAndroid Build Coastguard Worker   /* *cur_comp_info[i] describes component that appears i'th in SOS */
442*dfc6aa5cSAndroid Build Coastguard Worker 
443*dfc6aa5cSAndroid Build Coastguard Worker   JDIMENSION MCUs_per_row;      /* # of MCUs across the image */
444*dfc6aa5cSAndroid Build Coastguard Worker   JDIMENSION MCU_rows_in_scan;  /* # of MCU rows in the image */
445*dfc6aa5cSAndroid Build Coastguard Worker 
446*dfc6aa5cSAndroid Build Coastguard Worker   int blocks_in_MCU;            /* # of DCT blocks per MCU */
447*dfc6aa5cSAndroid Build Coastguard Worker   int MCU_membership[C_MAX_BLOCKS_IN_MCU];
448*dfc6aa5cSAndroid Build Coastguard Worker   /* MCU_membership[i] is index in cur_comp_info of component owning */
449*dfc6aa5cSAndroid Build Coastguard Worker   /* i'th block in an MCU */
450*dfc6aa5cSAndroid Build Coastguard Worker 
451*dfc6aa5cSAndroid Build Coastguard Worker   int Ss, Se, Ah, Al;           /* progressive JPEG parameters for scan */
452*dfc6aa5cSAndroid Build Coastguard Worker 
453*dfc6aa5cSAndroid Build Coastguard Worker #if JPEG_LIB_VERSION >= 80
454*dfc6aa5cSAndroid Build Coastguard Worker   int block_size;               /* the basic DCT block size: 1..16 */
455*dfc6aa5cSAndroid Build Coastguard Worker   const int *natural_order;     /* natural-order position array */
456*dfc6aa5cSAndroid Build Coastguard Worker   int lim_Se;                   /* min( Se, DCTSIZE2-1 ) */
457*dfc6aa5cSAndroid Build Coastguard Worker #endif
458*dfc6aa5cSAndroid Build Coastguard Worker 
459*dfc6aa5cSAndroid Build Coastguard Worker   /*
460*dfc6aa5cSAndroid Build Coastguard Worker    * Links to compression subobjects (methods and private variables of modules)
461*dfc6aa5cSAndroid Build Coastguard Worker    */
462*dfc6aa5cSAndroid Build Coastguard Worker   struct jpeg_comp_master *master;
463*dfc6aa5cSAndroid Build Coastguard Worker   struct jpeg_c_main_controller *main;
464*dfc6aa5cSAndroid Build Coastguard Worker   struct jpeg_c_prep_controller *prep;
465*dfc6aa5cSAndroid Build Coastguard Worker   struct jpeg_c_coef_controller *coef;
466*dfc6aa5cSAndroid Build Coastguard Worker   struct jpeg_marker_writer *marker;
467*dfc6aa5cSAndroid Build Coastguard Worker   struct jpeg_color_converter *cconvert;
468*dfc6aa5cSAndroid Build Coastguard Worker   struct jpeg_downsampler *downsample;
469*dfc6aa5cSAndroid Build Coastguard Worker   struct jpeg_forward_dct *fdct;
470*dfc6aa5cSAndroid Build Coastguard Worker   struct jpeg_entropy_encoder *entropy;
471*dfc6aa5cSAndroid Build Coastguard Worker   jpeg_scan_info *script_space; /* workspace for jpeg_simple_progression */
472*dfc6aa5cSAndroid Build Coastguard Worker   int script_space_size;
473*dfc6aa5cSAndroid Build Coastguard Worker };
474*dfc6aa5cSAndroid Build Coastguard Worker 
475*dfc6aa5cSAndroid Build Coastguard Worker 
476*dfc6aa5cSAndroid Build Coastguard Worker /* Master record for a decompression instance */
477*dfc6aa5cSAndroid Build Coastguard Worker 
478*dfc6aa5cSAndroid Build Coastguard Worker struct jpeg_decompress_struct {
479*dfc6aa5cSAndroid Build Coastguard Worker   jpeg_common_fields;           /* Fields shared with jpeg_compress_struct */
480*dfc6aa5cSAndroid Build Coastguard Worker 
481*dfc6aa5cSAndroid Build Coastguard Worker   /* Source of compressed data */
482*dfc6aa5cSAndroid Build Coastguard Worker   struct jpeg_source_mgr *src;
483*dfc6aa5cSAndroid Build Coastguard Worker 
484*dfc6aa5cSAndroid Build Coastguard Worker   /* Basic description of image --- filled in by jpeg_read_header(). */
485*dfc6aa5cSAndroid Build Coastguard Worker   /* Application may inspect these values to decide how to process image. */
486*dfc6aa5cSAndroid Build Coastguard Worker 
487*dfc6aa5cSAndroid Build Coastguard Worker   JDIMENSION image_width;       /* nominal image width (from SOF marker) */
488*dfc6aa5cSAndroid Build Coastguard Worker   JDIMENSION image_height;      /* nominal image height */
489*dfc6aa5cSAndroid Build Coastguard Worker   int num_components;           /* # of color components in JPEG image */
490*dfc6aa5cSAndroid Build Coastguard Worker   J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
491*dfc6aa5cSAndroid Build Coastguard Worker 
492*dfc6aa5cSAndroid Build Coastguard Worker   /* Decompression processing parameters --- these fields must be set before
493*dfc6aa5cSAndroid Build Coastguard Worker    * calling jpeg_start_decompress().  Note that jpeg_read_header() initializes
494*dfc6aa5cSAndroid Build Coastguard Worker    * them to default values.
495*dfc6aa5cSAndroid Build Coastguard Worker    */
496*dfc6aa5cSAndroid Build Coastguard Worker 
497*dfc6aa5cSAndroid Build Coastguard Worker   J_COLOR_SPACE out_color_space; /* colorspace for output */
498*dfc6aa5cSAndroid Build Coastguard Worker 
499*dfc6aa5cSAndroid Build Coastguard Worker   unsigned int scale_num, scale_denom; /* fraction by which to scale image */
500*dfc6aa5cSAndroid Build Coastguard Worker 
501*dfc6aa5cSAndroid Build Coastguard Worker   double output_gamma;          /* image gamma wanted in output */
502*dfc6aa5cSAndroid Build Coastguard Worker 
503*dfc6aa5cSAndroid Build Coastguard Worker   boolean buffered_image;       /* TRUE=multiple output passes */
504*dfc6aa5cSAndroid Build Coastguard Worker   boolean raw_data_out;         /* TRUE=downsampled data wanted */
505*dfc6aa5cSAndroid Build Coastguard Worker 
506*dfc6aa5cSAndroid Build Coastguard Worker   J_DCT_METHOD dct_method;      /* IDCT algorithm selector */
507*dfc6aa5cSAndroid Build Coastguard Worker   boolean do_fancy_upsampling;  /* TRUE=apply fancy upsampling */
508*dfc6aa5cSAndroid Build Coastguard Worker   boolean do_block_smoothing;   /* TRUE=apply interblock smoothing */
509*dfc6aa5cSAndroid Build Coastguard Worker 
510*dfc6aa5cSAndroid Build Coastguard Worker   boolean quantize_colors;      /* TRUE=colormapped output wanted */
511*dfc6aa5cSAndroid Build Coastguard Worker   /* the following are ignored if not quantize_colors: */
512*dfc6aa5cSAndroid Build Coastguard Worker   J_DITHER_MODE dither_mode;    /* type of color dithering to use */
513*dfc6aa5cSAndroid Build Coastguard Worker   boolean two_pass_quantize;    /* TRUE=use two-pass color quantization */
514*dfc6aa5cSAndroid Build Coastguard Worker   int desired_number_of_colors; /* max # colors to use in created colormap */
515*dfc6aa5cSAndroid Build Coastguard Worker   /* these are significant only in buffered-image mode: */
516*dfc6aa5cSAndroid Build Coastguard Worker   boolean enable_1pass_quant;   /* enable future use of 1-pass quantizer */
517*dfc6aa5cSAndroid Build Coastguard Worker   boolean enable_external_quant;/* enable future use of external colormap */
518*dfc6aa5cSAndroid Build Coastguard Worker   boolean enable_2pass_quant;   /* enable future use of 2-pass quantizer */
519*dfc6aa5cSAndroid Build Coastguard Worker 
520*dfc6aa5cSAndroid Build Coastguard Worker   /* Description of actual output image that will be returned to application.
521*dfc6aa5cSAndroid Build Coastguard Worker    * These fields are computed by jpeg_start_decompress().
522*dfc6aa5cSAndroid Build Coastguard Worker    * You can also use jpeg_calc_output_dimensions() to determine these values
523*dfc6aa5cSAndroid Build Coastguard Worker    * in advance of calling jpeg_start_decompress().
524*dfc6aa5cSAndroid Build Coastguard Worker    */
525*dfc6aa5cSAndroid Build Coastguard Worker 
526*dfc6aa5cSAndroid Build Coastguard Worker   JDIMENSION output_width;      /* scaled image width */
527*dfc6aa5cSAndroid Build Coastguard Worker   JDIMENSION output_height;     /* scaled image height */
528*dfc6aa5cSAndroid Build Coastguard Worker   int out_color_components;     /* # of color components in out_color_space */
529*dfc6aa5cSAndroid Build Coastguard Worker   int output_components;        /* # of color components returned */
530*dfc6aa5cSAndroid Build Coastguard Worker   /* output_components is 1 (a colormap index) when quantizing colors;
531*dfc6aa5cSAndroid Build Coastguard Worker    * otherwise it equals out_color_components.
532*dfc6aa5cSAndroid Build Coastguard Worker    */
533*dfc6aa5cSAndroid Build Coastguard Worker   int rec_outbuf_height;        /* min recommended height of scanline buffer */
534*dfc6aa5cSAndroid Build Coastguard Worker   /* If the buffer passed to jpeg_read_scanlines() is less than this many rows
535*dfc6aa5cSAndroid Build Coastguard Worker    * high, space and time will be wasted due to unnecessary data copying.
536*dfc6aa5cSAndroid Build Coastguard Worker    * Usually rec_outbuf_height will be 1 or 2, at most 4.
537*dfc6aa5cSAndroid Build Coastguard Worker    */
538*dfc6aa5cSAndroid Build Coastguard Worker 
539*dfc6aa5cSAndroid Build Coastguard Worker   /* When quantizing colors, the output colormap is described by these fields.
540*dfc6aa5cSAndroid Build Coastguard Worker    * The application can supply a colormap by setting colormap non-NULL before
541*dfc6aa5cSAndroid Build Coastguard Worker    * calling jpeg_start_decompress; otherwise a colormap is created during
542*dfc6aa5cSAndroid Build Coastguard Worker    * jpeg_start_decompress or jpeg_start_output.
543*dfc6aa5cSAndroid Build Coastguard Worker    * The map has out_color_components rows and actual_number_of_colors columns.
544*dfc6aa5cSAndroid Build Coastguard Worker    */
545*dfc6aa5cSAndroid Build Coastguard Worker   int actual_number_of_colors;  /* number of entries in use */
546*dfc6aa5cSAndroid Build Coastguard Worker   JSAMPARRAY colormap;          /* The color map as a 2-D pixel array */
547*dfc6aa5cSAndroid Build Coastguard Worker 
548*dfc6aa5cSAndroid Build Coastguard Worker   /* State variables: these variables indicate the progress of decompression.
549*dfc6aa5cSAndroid Build Coastguard Worker    * The application may examine these but must not modify them.
550*dfc6aa5cSAndroid Build Coastguard Worker    */
551*dfc6aa5cSAndroid Build Coastguard Worker 
552*dfc6aa5cSAndroid Build Coastguard Worker   /* Row index of next scanline to be read from jpeg_read_scanlines().
553*dfc6aa5cSAndroid Build Coastguard Worker    * Application may use this to control its processing loop, e.g.,
554*dfc6aa5cSAndroid Build Coastguard Worker    * "while (output_scanline < output_height)".
555*dfc6aa5cSAndroid Build Coastguard Worker    */
556*dfc6aa5cSAndroid Build Coastguard Worker   JDIMENSION output_scanline;   /* 0 .. output_height-1  */
557*dfc6aa5cSAndroid Build Coastguard Worker 
558*dfc6aa5cSAndroid Build Coastguard Worker   /* Current input scan number and number of iMCU rows completed in scan.
559*dfc6aa5cSAndroid Build Coastguard Worker    * These indicate the progress of the decompressor input side.
560*dfc6aa5cSAndroid Build Coastguard Worker    */
561*dfc6aa5cSAndroid Build Coastguard Worker   int input_scan_number;        /* Number of SOS markers seen so far */
562*dfc6aa5cSAndroid Build Coastguard Worker   JDIMENSION input_iMCU_row;    /* Number of iMCU rows completed */
563*dfc6aa5cSAndroid Build Coastguard Worker 
564*dfc6aa5cSAndroid Build Coastguard Worker   /* The "output scan number" is the notional scan being displayed by the
565*dfc6aa5cSAndroid Build Coastguard Worker    * output side.  The decompressor will not allow output scan/row number
566*dfc6aa5cSAndroid Build Coastguard Worker    * to get ahead of input scan/row, but it can fall arbitrarily far behind.
567*dfc6aa5cSAndroid Build Coastguard Worker    */
568*dfc6aa5cSAndroid Build Coastguard Worker   int output_scan_number;       /* Nominal scan number being displayed */
569*dfc6aa5cSAndroid Build Coastguard Worker   JDIMENSION output_iMCU_row;   /* Number of iMCU rows read */
570*dfc6aa5cSAndroid Build Coastguard Worker 
571*dfc6aa5cSAndroid Build Coastguard Worker   /* Current progression status.  coef_bits[c][i] indicates the precision
572*dfc6aa5cSAndroid Build Coastguard Worker    * with which component c's DCT coefficient i (in zigzag order) is known.
573*dfc6aa5cSAndroid Build Coastguard Worker    * It is -1 when no data has yet been received, otherwise it is the point
574*dfc6aa5cSAndroid Build Coastguard Worker    * transform (shift) value for the most recent scan of the coefficient
575*dfc6aa5cSAndroid Build Coastguard Worker    * (thus, 0 at completion of the progression).
576*dfc6aa5cSAndroid Build Coastguard Worker    * This pointer is NULL when reading a non-progressive file.
577*dfc6aa5cSAndroid Build Coastguard Worker    */
578*dfc6aa5cSAndroid Build Coastguard Worker   int (*coef_bits)[DCTSIZE2];   /* -1 or current Al value for each coef */
579*dfc6aa5cSAndroid Build Coastguard Worker 
580*dfc6aa5cSAndroid Build Coastguard Worker   /* Internal JPEG parameters --- the application usually need not look at
581*dfc6aa5cSAndroid Build Coastguard Worker    * these fields.  Note that the decompressor output side may not use
582*dfc6aa5cSAndroid Build Coastguard Worker    * any parameters that can change between scans.
583*dfc6aa5cSAndroid Build Coastguard Worker    */
584*dfc6aa5cSAndroid Build Coastguard Worker 
585*dfc6aa5cSAndroid Build Coastguard Worker   /* Quantization and Huffman tables are carried forward across input
586*dfc6aa5cSAndroid Build Coastguard Worker    * datastreams when processing abbreviated JPEG datastreams.
587*dfc6aa5cSAndroid Build Coastguard Worker    */
588*dfc6aa5cSAndroid Build Coastguard Worker 
589*dfc6aa5cSAndroid Build Coastguard Worker   JQUANT_TBL *quant_tbl_ptrs[NUM_QUANT_TBLS];
590*dfc6aa5cSAndroid Build Coastguard Worker   /* ptrs to coefficient quantization tables, or NULL if not defined */
591*dfc6aa5cSAndroid Build Coastguard Worker 
592*dfc6aa5cSAndroid Build Coastguard Worker   JHUFF_TBL *dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
593*dfc6aa5cSAndroid Build Coastguard Worker   JHUFF_TBL *ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
594*dfc6aa5cSAndroid Build Coastguard Worker   /* ptrs to Huffman coding tables, or NULL if not defined */
595*dfc6aa5cSAndroid Build Coastguard Worker 
596*dfc6aa5cSAndroid Build Coastguard Worker   /* These parameters are never carried across datastreams, since they
597*dfc6aa5cSAndroid Build Coastguard Worker    * are given in SOF/SOS markers or defined to be reset by SOI.
598*dfc6aa5cSAndroid Build Coastguard Worker    */
599*dfc6aa5cSAndroid Build Coastguard Worker 
600*dfc6aa5cSAndroid Build Coastguard Worker   int data_precision;           /* bits of precision in image data */
601*dfc6aa5cSAndroid Build Coastguard Worker 
602*dfc6aa5cSAndroid Build Coastguard Worker   jpeg_component_info *comp_info;
603*dfc6aa5cSAndroid Build Coastguard Worker   /* comp_info[i] describes component that appears i'th in SOF */
604*dfc6aa5cSAndroid Build Coastguard Worker 
605*dfc6aa5cSAndroid Build Coastguard Worker #if JPEG_LIB_VERSION >= 80
606*dfc6aa5cSAndroid Build Coastguard Worker   boolean is_baseline;          /* TRUE if Baseline SOF0 encountered */
607*dfc6aa5cSAndroid Build Coastguard Worker #endif
608*dfc6aa5cSAndroid Build Coastguard Worker   boolean progressive_mode;     /* TRUE if SOFn specifies progressive mode */
609*dfc6aa5cSAndroid Build Coastguard Worker   boolean arith_code;           /* TRUE=arithmetic coding, FALSE=Huffman */
610*dfc6aa5cSAndroid Build Coastguard Worker 
611*dfc6aa5cSAndroid Build Coastguard Worker   UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
612*dfc6aa5cSAndroid Build Coastguard Worker   UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
613*dfc6aa5cSAndroid Build Coastguard Worker   UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
614*dfc6aa5cSAndroid Build Coastguard Worker 
615*dfc6aa5cSAndroid Build Coastguard Worker   unsigned int restart_interval; /* MCUs per restart interval, or 0 for no restart */
616*dfc6aa5cSAndroid Build Coastguard Worker 
617*dfc6aa5cSAndroid Build Coastguard Worker   /* These fields record data obtained from optional markers recognized by
618*dfc6aa5cSAndroid Build Coastguard Worker    * the JPEG library.
619*dfc6aa5cSAndroid Build Coastguard Worker    */
620*dfc6aa5cSAndroid Build Coastguard Worker   boolean saw_JFIF_marker;      /* TRUE iff a JFIF APP0 marker was found */
621*dfc6aa5cSAndroid Build Coastguard Worker   /* Data copied from JFIF marker; only valid if saw_JFIF_marker is TRUE: */
622*dfc6aa5cSAndroid Build Coastguard Worker   UINT8 JFIF_major_version;     /* JFIF version number */
623*dfc6aa5cSAndroid Build Coastguard Worker   UINT8 JFIF_minor_version;
624*dfc6aa5cSAndroid Build Coastguard Worker   UINT8 density_unit;           /* JFIF code for pixel size units */
625*dfc6aa5cSAndroid Build Coastguard Worker   UINT16 X_density;             /* Horizontal pixel density */
626*dfc6aa5cSAndroid Build Coastguard Worker   UINT16 Y_density;             /* Vertical pixel density */
627*dfc6aa5cSAndroid Build Coastguard Worker   boolean saw_Adobe_marker;     /* TRUE iff an Adobe APP14 marker was found */
628*dfc6aa5cSAndroid Build Coastguard Worker   UINT8 Adobe_transform;        /* Color transform code from Adobe marker */
629*dfc6aa5cSAndroid Build Coastguard Worker 
630*dfc6aa5cSAndroid Build Coastguard Worker   boolean CCIR601_sampling;     /* TRUE=first samples are cosited */
631*dfc6aa5cSAndroid Build Coastguard Worker 
632*dfc6aa5cSAndroid Build Coastguard Worker   /* Aside from the specific data retained from APPn markers known to the
633*dfc6aa5cSAndroid Build Coastguard Worker    * library, the uninterpreted contents of any or all APPn and COM markers
634*dfc6aa5cSAndroid Build Coastguard Worker    * can be saved in a list for examination by the application.
635*dfc6aa5cSAndroid Build Coastguard Worker    */
636*dfc6aa5cSAndroid Build Coastguard Worker   jpeg_saved_marker_ptr marker_list; /* Head of list of saved markers */
637*dfc6aa5cSAndroid Build Coastguard Worker 
638*dfc6aa5cSAndroid Build Coastguard Worker   /* Remaining fields are known throughout decompressor, but generally
639*dfc6aa5cSAndroid Build Coastguard Worker    * should not be touched by a surrounding application.
640*dfc6aa5cSAndroid Build Coastguard Worker    */
641*dfc6aa5cSAndroid Build Coastguard Worker 
642*dfc6aa5cSAndroid Build Coastguard Worker   /*
643*dfc6aa5cSAndroid Build Coastguard Worker    * These fields are computed during decompression startup
644*dfc6aa5cSAndroid Build Coastguard Worker    */
645*dfc6aa5cSAndroid Build Coastguard Worker   int max_h_samp_factor;        /* largest h_samp_factor */
646*dfc6aa5cSAndroid Build Coastguard Worker   int max_v_samp_factor;        /* largest v_samp_factor */
647*dfc6aa5cSAndroid Build Coastguard Worker 
648*dfc6aa5cSAndroid Build Coastguard Worker #if JPEG_LIB_VERSION >= 70
649*dfc6aa5cSAndroid Build Coastguard Worker   int min_DCT_h_scaled_size;    /* smallest DCT_h_scaled_size of any component */
650*dfc6aa5cSAndroid Build Coastguard Worker   int min_DCT_v_scaled_size;    /* smallest DCT_v_scaled_size of any component */
651*dfc6aa5cSAndroid Build Coastguard Worker #else
652*dfc6aa5cSAndroid Build Coastguard Worker   int min_DCT_scaled_size;      /* smallest DCT_scaled_size of any component */
653*dfc6aa5cSAndroid Build Coastguard Worker #endif
654*dfc6aa5cSAndroid Build Coastguard Worker 
655*dfc6aa5cSAndroid Build Coastguard Worker   JDIMENSION total_iMCU_rows;   /* # of iMCU rows in image */
656*dfc6aa5cSAndroid Build Coastguard Worker   /* The coefficient controller's input and output progress is measured in
657*dfc6aa5cSAndroid Build Coastguard Worker    * units of "iMCU" (interleaved MCU) rows.  These are the same as MCU rows
658*dfc6aa5cSAndroid Build Coastguard Worker    * in fully interleaved JPEG scans, but are used whether the scan is
659*dfc6aa5cSAndroid Build Coastguard Worker    * interleaved or not.  We define an iMCU row as v_samp_factor DCT block
660*dfc6aa5cSAndroid Build Coastguard Worker    * rows of each component.  Therefore, the IDCT output contains
661*dfc6aa5cSAndroid Build Coastguard Worker    * v_samp_factor*DCT_[v_]scaled_size sample rows of a component per iMCU row.
662*dfc6aa5cSAndroid Build Coastguard Worker    */
663*dfc6aa5cSAndroid Build Coastguard Worker 
664*dfc6aa5cSAndroid Build Coastguard Worker   JSAMPLE *sample_range_limit;  /* table for fast range-limiting */
665*dfc6aa5cSAndroid Build Coastguard Worker 
666*dfc6aa5cSAndroid Build Coastguard Worker   /*
667*dfc6aa5cSAndroid Build Coastguard Worker    * These fields are valid during any one scan.
668*dfc6aa5cSAndroid Build Coastguard Worker    * They describe the components and MCUs actually appearing in the scan.
669*dfc6aa5cSAndroid Build Coastguard Worker    * Note that the decompressor output side must not use these fields.
670*dfc6aa5cSAndroid Build Coastguard Worker    */
671*dfc6aa5cSAndroid Build Coastguard Worker   int comps_in_scan;            /* # of JPEG components in this scan */
672*dfc6aa5cSAndroid Build Coastguard Worker   jpeg_component_info *cur_comp_info[MAX_COMPS_IN_SCAN];
673*dfc6aa5cSAndroid Build Coastguard Worker   /* *cur_comp_info[i] describes component that appears i'th in SOS */
674*dfc6aa5cSAndroid Build Coastguard Worker 
675*dfc6aa5cSAndroid Build Coastguard Worker   JDIMENSION MCUs_per_row;      /* # of MCUs across the image */
676*dfc6aa5cSAndroid Build Coastguard Worker   JDIMENSION MCU_rows_in_scan;  /* # of MCU rows in the image */
677*dfc6aa5cSAndroid Build Coastguard Worker 
678*dfc6aa5cSAndroid Build Coastguard Worker   int blocks_in_MCU;            /* # of DCT blocks per MCU */
679*dfc6aa5cSAndroid Build Coastguard Worker   int MCU_membership[D_MAX_BLOCKS_IN_MCU];
680*dfc6aa5cSAndroid Build Coastguard Worker   /* MCU_membership[i] is index in cur_comp_info of component owning */
681*dfc6aa5cSAndroid Build Coastguard Worker   /* i'th block in an MCU */
682*dfc6aa5cSAndroid Build Coastguard Worker 
683*dfc6aa5cSAndroid Build Coastguard Worker   int Ss, Se, Ah, Al;           /* progressive JPEG parameters for scan */
684*dfc6aa5cSAndroid Build Coastguard Worker 
685*dfc6aa5cSAndroid Build Coastguard Worker #if JPEG_LIB_VERSION >= 80
686*dfc6aa5cSAndroid Build Coastguard Worker   /* These fields are derived from Se of first SOS marker.
687*dfc6aa5cSAndroid Build Coastguard Worker    */
688*dfc6aa5cSAndroid Build Coastguard Worker   int block_size;               /* the basic DCT block size: 1..16 */
689*dfc6aa5cSAndroid Build Coastguard Worker   const int *natural_order; /* natural-order position array for entropy decode */
690*dfc6aa5cSAndroid Build Coastguard Worker   int lim_Se;                   /* min( Se, DCTSIZE2-1 ) for entropy decode */
691*dfc6aa5cSAndroid Build Coastguard Worker #endif
692*dfc6aa5cSAndroid Build Coastguard Worker 
693*dfc6aa5cSAndroid Build Coastguard Worker   /* This field is shared between entropy decoder and marker parser.
694*dfc6aa5cSAndroid Build Coastguard Worker    * It is either zero or the code of a JPEG marker that has been
695*dfc6aa5cSAndroid Build Coastguard Worker    * read from the data source, but has not yet been processed.
696*dfc6aa5cSAndroid Build Coastguard Worker    */
697*dfc6aa5cSAndroid Build Coastguard Worker   int unread_marker;
698*dfc6aa5cSAndroid Build Coastguard Worker 
699*dfc6aa5cSAndroid Build Coastguard Worker   /*
700*dfc6aa5cSAndroid Build Coastguard Worker    * Links to decompression subobjects (methods, private variables of modules)
701*dfc6aa5cSAndroid Build Coastguard Worker    */
702*dfc6aa5cSAndroid Build Coastguard Worker   struct jpeg_decomp_master *master;
703*dfc6aa5cSAndroid Build Coastguard Worker   struct jpeg_d_main_controller *main;
704*dfc6aa5cSAndroid Build Coastguard Worker   struct jpeg_d_coef_controller *coef;
705*dfc6aa5cSAndroid Build Coastguard Worker   struct jpeg_d_post_controller *post;
706*dfc6aa5cSAndroid Build Coastguard Worker   struct jpeg_input_controller *inputctl;
707*dfc6aa5cSAndroid Build Coastguard Worker   struct jpeg_marker_reader *marker;
708*dfc6aa5cSAndroid Build Coastguard Worker   struct jpeg_entropy_decoder *entropy;
709*dfc6aa5cSAndroid Build Coastguard Worker   struct jpeg_inverse_dct *idct;
710*dfc6aa5cSAndroid Build Coastguard Worker   struct jpeg_upsampler *upsample;
711*dfc6aa5cSAndroid Build Coastguard Worker   struct jpeg_color_deconverter *cconvert;
712*dfc6aa5cSAndroid Build Coastguard Worker   struct jpeg_color_quantizer *cquantize;
713*dfc6aa5cSAndroid Build Coastguard Worker };
714*dfc6aa5cSAndroid Build Coastguard Worker 
715*dfc6aa5cSAndroid Build Coastguard Worker 
716*dfc6aa5cSAndroid Build Coastguard Worker /* "Object" declarations for JPEG modules that may be supplied or called
717*dfc6aa5cSAndroid Build Coastguard Worker  * directly by the surrounding application.
718*dfc6aa5cSAndroid Build Coastguard Worker  * As with all objects in the JPEG library, these structs only define the
719*dfc6aa5cSAndroid Build Coastguard Worker  * publicly visible methods and state variables of a module.  Additional
720*dfc6aa5cSAndroid Build Coastguard Worker  * private fields may exist after the public ones.
721*dfc6aa5cSAndroid Build Coastguard Worker  */
722*dfc6aa5cSAndroid Build Coastguard Worker 
723*dfc6aa5cSAndroid Build Coastguard Worker 
724*dfc6aa5cSAndroid Build Coastguard Worker /* Error handler object */
725*dfc6aa5cSAndroid Build Coastguard Worker 
726*dfc6aa5cSAndroid Build Coastguard Worker struct jpeg_error_mgr {
727*dfc6aa5cSAndroid Build Coastguard Worker   /* Error exit handler: does not return to caller */
728*dfc6aa5cSAndroid Build Coastguard Worker   void (*error_exit) (j_common_ptr cinfo);
729*dfc6aa5cSAndroid Build Coastguard Worker   /* Conditionally emit a trace or warning message */
730*dfc6aa5cSAndroid Build Coastguard Worker   void (*emit_message) (j_common_ptr cinfo, int msg_level);
731*dfc6aa5cSAndroid Build Coastguard Worker   /* Routine that actually outputs a trace or error message */
732*dfc6aa5cSAndroid Build Coastguard Worker   void (*output_message) (j_common_ptr cinfo);
733*dfc6aa5cSAndroid Build Coastguard Worker   /* Format a message string for the most recent JPEG error or message */
734*dfc6aa5cSAndroid Build Coastguard Worker   void (*format_message) (j_common_ptr cinfo, char *buffer);
735*dfc6aa5cSAndroid Build Coastguard Worker #define JMSG_LENGTH_MAX  200    /* recommended size of format_message buffer */
736*dfc6aa5cSAndroid Build Coastguard Worker   /* Reset error state variables at start of a new image */
737*dfc6aa5cSAndroid Build Coastguard Worker   void (*reset_error_mgr) (j_common_ptr cinfo);
738*dfc6aa5cSAndroid Build Coastguard Worker 
739*dfc6aa5cSAndroid Build Coastguard Worker   /* The message ID code and any parameters are saved here.
740*dfc6aa5cSAndroid Build Coastguard Worker    * A message can have one string parameter or up to 8 int parameters.
741*dfc6aa5cSAndroid Build Coastguard Worker    */
742*dfc6aa5cSAndroid Build Coastguard Worker   int msg_code;
743*dfc6aa5cSAndroid Build Coastguard Worker #define JMSG_STR_PARM_MAX  80
744*dfc6aa5cSAndroid Build Coastguard Worker   union {
745*dfc6aa5cSAndroid Build Coastguard Worker     int i[8];
746*dfc6aa5cSAndroid Build Coastguard Worker     char s[JMSG_STR_PARM_MAX];
747*dfc6aa5cSAndroid Build Coastguard Worker   } msg_parm;
748*dfc6aa5cSAndroid Build Coastguard Worker 
749*dfc6aa5cSAndroid Build Coastguard Worker   /* Standard state variables for error facility */
750*dfc6aa5cSAndroid Build Coastguard Worker 
751*dfc6aa5cSAndroid Build Coastguard Worker   int trace_level;              /* max msg_level that will be displayed */
752*dfc6aa5cSAndroid Build Coastguard Worker 
753*dfc6aa5cSAndroid Build Coastguard Worker   /* For recoverable corrupt-data errors, we emit a warning message,
754*dfc6aa5cSAndroid Build Coastguard Worker    * but keep going unless emit_message chooses to abort.  emit_message
755*dfc6aa5cSAndroid Build Coastguard Worker    * should count warnings in num_warnings.  The surrounding application
756*dfc6aa5cSAndroid Build Coastguard Worker    * can check for bad data by seeing if num_warnings is nonzero at the
757*dfc6aa5cSAndroid Build Coastguard Worker    * end of processing.
758*dfc6aa5cSAndroid Build Coastguard Worker    */
759*dfc6aa5cSAndroid Build Coastguard Worker   long num_warnings;            /* number of corrupt-data warnings */
760*dfc6aa5cSAndroid Build Coastguard Worker 
761*dfc6aa5cSAndroid Build Coastguard Worker   /* These fields point to the table(s) of error message strings.
762*dfc6aa5cSAndroid Build Coastguard Worker    * An application can change the table pointer to switch to a different
763*dfc6aa5cSAndroid Build Coastguard Worker    * message list (typically, to change the language in which errors are
764*dfc6aa5cSAndroid Build Coastguard Worker    * reported).  Some applications may wish to add additional error codes
765*dfc6aa5cSAndroid Build Coastguard Worker    * that will be handled by the JPEG library error mechanism; the second
766*dfc6aa5cSAndroid Build Coastguard Worker    * table pointer is used for this purpose.
767*dfc6aa5cSAndroid Build Coastguard Worker    *
768*dfc6aa5cSAndroid Build Coastguard Worker    * First table includes all errors generated by JPEG library itself.
769*dfc6aa5cSAndroid Build Coastguard Worker    * Error code 0 is reserved for a "no such error string" message.
770*dfc6aa5cSAndroid Build Coastguard Worker    */
771*dfc6aa5cSAndroid Build Coastguard Worker   const char * const *jpeg_message_table; /* Library errors */
772*dfc6aa5cSAndroid Build Coastguard Worker   int last_jpeg_message;    /* Table contains strings 0..last_jpeg_message */
773*dfc6aa5cSAndroid Build Coastguard Worker   /* Second table can be added by application (see cjpeg/djpeg for example).
774*dfc6aa5cSAndroid Build Coastguard Worker    * It contains strings numbered first_addon_message..last_addon_message.
775*dfc6aa5cSAndroid Build Coastguard Worker    */
776*dfc6aa5cSAndroid Build Coastguard Worker   const char * const *addon_message_table; /* Non-library errors */
777*dfc6aa5cSAndroid Build Coastguard Worker   int first_addon_message;      /* code for first string in addon table */
778*dfc6aa5cSAndroid Build Coastguard Worker   int last_addon_message;       /* code for last string in addon table */
779*dfc6aa5cSAndroid Build Coastguard Worker };
780*dfc6aa5cSAndroid Build Coastguard Worker 
781*dfc6aa5cSAndroid Build Coastguard Worker 
782*dfc6aa5cSAndroid Build Coastguard Worker /* Progress monitor object */
783*dfc6aa5cSAndroid Build Coastguard Worker 
784*dfc6aa5cSAndroid Build Coastguard Worker struct jpeg_progress_mgr {
785*dfc6aa5cSAndroid Build Coastguard Worker   void (*progress_monitor) (j_common_ptr cinfo);
786*dfc6aa5cSAndroid Build Coastguard Worker 
787*dfc6aa5cSAndroid Build Coastguard Worker   long pass_counter;            /* work units completed in this pass */
788*dfc6aa5cSAndroid Build Coastguard Worker   long pass_limit;              /* total number of work units in this pass */
789*dfc6aa5cSAndroid Build Coastguard Worker   int completed_passes;         /* passes completed so far */
790*dfc6aa5cSAndroid Build Coastguard Worker   int total_passes;             /* total number of passes expected */
791*dfc6aa5cSAndroid Build Coastguard Worker };
792*dfc6aa5cSAndroid Build Coastguard Worker 
793*dfc6aa5cSAndroid Build Coastguard Worker 
794*dfc6aa5cSAndroid Build Coastguard Worker /* Data destination object for compression */
795*dfc6aa5cSAndroid Build Coastguard Worker 
796*dfc6aa5cSAndroid Build Coastguard Worker struct jpeg_destination_mgr {
797*dfc6aa5cSAndroid Build Coastguard Worker   JOCTET *next_output_byte;     /* => next byte to write in buffer */
798*dfc6aa5cSAndroid Build Coastguard Worker   size_t free_in_buffer;        /* # of byte spaces remaining in buffer */
799*dfc6aa5cSAndroid Build Coastguard Worker 
800*dfc6aa5cSAndroid Build Coastguard Worker   void (*init_destination) (j_compress_ptr cinfo);
801*dfc6aa5cSAndroid Build Coastguard Worker   boolean (*empty_output_buffer) (j_compress_ptr cinfo);
802*dfc6aa5cSAndroid Build Coastguard Worker   void (*term_destination) (j_compress_ptr cinfo);
803*dfc6aa5cSAndroid Build Coastguard Worker };
804*dfc6aa5cSAndroid Build Coastguard Worker 
805*dfc6aa5cSAndroid Build Coastguard Worker 
806*dfc6aa5cSAndroid Build Coastguard Worker /* Data source object for decompression */
807*dfc6aa5cSAndroid Build Coastguard Worker 
808*dfc6aa5cSAndroid Build Coastguard Worker struct jpeg_source_mgr {
809*dfc6aa5cSAndroid Build Coastguard Worker   const JOCTET *next_input_byte; /* => next byte to read from buffer */
810*dfc6aa5cSAndroid Build Coastguard Worker   size_t bytes_in_buffer;       /* # of bytes remaining in buffer */
811*dfc6aa5cSAndroid Build Coastguard Worker 
812*dfc6aa5cSAndroid Build Coastguard Worker   void (*init_source) (j_decompress_ptr cinfo);
813*dfc6aa5cSAndroid Build Coastguard Worker   boolean (*fill_input_buffer) (j_decompress_ptr cinfo);
814*dfc6aa5cSAndroid Build Coastguard Worker   void (*skip_input_data) (j_decompress_ptr cinfo, long num_bytes);
815*dfc6aa5cSAndroid Build Coastguard Worker   boolean (*resync_to_restart) (j_decompress_ptr cinfo, int desired);
816*dfc6aa5cSAndroid Build Coastguard Worker   void (*term_source) (j_decompress_ptr cinfo);
817*dfc6aa5cSAndroid Build Coastguard Worker };
818*dfc6aa5cSAndroid Build Coastguard Worker 
819*dfc6aa5cSAndroid Build Coastguard Worker 
820*dfc6aa5cSAndroid Build Coastguard Worker /* Memory manager object.
821*dfc6aa5cSAndroid Build Coastguard Worker  * Allocates "small" objects (a few K total), "large" objects (tens of K),
822*dfc6aa5cSAndroid Build Coastguard Worker  * and "really big" objects (virtual arrays with backing store if needed).
823*dfc6aa5cSAndroid Build Coastguard Worker  * The memory manager does not allow individual objects to be freed; rather,
824*dfc6aa5cSAndroid Build Coastguard Worker  * each created object is assigned to a pool, and whole pools can be freed
825*dfc6aa5cSAndroid Build Coastguard Worker  * at once.  This is faster and more convenient than remembering exactly what
826*dfc6aa5cSAndroid Build Coastguard Worker  * to free, especially where malloc()/free() are not too speedy.
827*dfc6aa5cSAndroid Build Coastguard Worker  * NB: alloc routines never return NULL.  They exit to error_exit if not
828*dfc6aa5cSAndroid Build Coastguard Worker  * successful.
829*dfc6aa5cSAndroid Build Coastguard Worker  */
830*dfc6aa5cSAndroid Build Coastguard Worker 
831*dfc6aa5cSAndroid Build Coastguard Worker #define JPOOL_PERMANENT  0      /* lasts until master record is destroyed */
832*dfc6aa5cSAndroid Build Coastguard Worker #define JPOOL_IMAGE      1      /* lasts until done with image/datastream */
833*dfc6aa5cSAndroid Build Coastguard Worker #define JPOOL_NUMPOOLS   2
834*dfc6aa5cSAndroid Build Coastguard Worker 
835*dfc6aa5cSAndroid Build Coastguard Worker typedef struct jvirt_sarray_control *jvirt_sarray_ptr;
836*dfc6aa5cSAndroid Build Coastguard Worker typedef struct jvirt_barray_control *jvirt_barray_ptr;
837*dfc6aa5cSAndroid Build Coastguard Worker 
838*dfc6aa5cSAndroid Build Coastguard Worker 
839*dfc6aa5cSAndroid Build Coastguard Worker struct jpeg_memory_mgr {
840*dfc6aa5cSAndroid Build Coastguard Worker   /* Method pointers */
841*dfc6aa5cSAndroid Build Coastguard Worker   void *(*alloc_small) (j_common_ptr cinfo, int pool_id, size_t sizeofobject);
842*dfc6aa5cSAndroid Build Coastguard Worker   void *(*alloc_large) (j_common_ptr cinfo, int pool_id,
843*dfc6aa5cSAndroid Build Coastguard Worker                         size_t sizeofobject);
844*dfc6aa5cSAndroid Build Coastguard Worker   JSAMPARRAY (*alloc_sarray) (j_common_ptr cinfo, int pool_id,
845*dfc6aa5cSAndroid Build Coastguard Worker                               JDIMENSION samplesperrow, JDIMENSION numrows);
846*dfc6aa5cSAndroid Build Coastguard Worker   JBLOCKARRAY (*alloc_barray) (j_common_ptr cinfo, int pool_id,
847*dfc6aa5cSAndroid Build Coastguard Worker                                JDIMENSION blocksperrow, JDIMENSION numrows);
848*dfc6aa5cSAndroid Build Coastguard Worker   jvirt_sarray_ptr (*request_virt_sarray) (j_common_ptr cinfo, int pool_id,
849*dfc6aa5cSAndroid Build Coastguard Worker                                            boolean pre_zero,
850*dfc6aa5cSAndroid Build Coastguard Worker                                            JDIMENSION samplesperrow,
851*dfc6aa5cSAndroid Build Coastguard Worker                                            JDIMENSION numrows,
852*dfc6aa5cSAndroid Build Coastguard Worker                                            JDIMENSION maxaccess);
853*dfc6aa5cSAndroid Build Coastguard Worker   jvirt_barray_ptr (*request_virt_barray) (j_common_ptr cinfo, int pool_id,
854*dfc6aa5cSAndroid Build Coastguard Worker                                            boolean pre_zero,
855*dfc6aa5cSAndroid Build Coastguard Worker                                            JDIMENSION blocksperrow,
856*dfc6aa5cSAndroid Build Coastguard Worker                                            JDIMENSION numrows,
857*dfc6aa5cSAndroid Build Coastguard Worker                                            JDIMENSION maxaccess);
858*dfc6aa5cSAndroid Build Coastguard Worker   void (*realize_virt_arrays) (j_common_ptr cinfo);
859*dfc6aa5cSAndroid Build Coastguard Worker   JSAMPARRAY (*access_virt_sarray) (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
860*dfc6aa5cSAndroid Build Coastguard Worker                                     JDIMENSION start_row, JDIMENSION num_rows,
861*dfc6aa5cSAndroid Build Coastguard Worker                                     boolean writable);
862*dfc6aa5cSAndroid Build Coastguard Worker   JBLOCKARRAY (*access_virt_barray) (j_common_ptr cinfo, jvirt_barray_ptr ptr,
863*dfc6aa5cSAndroid Build Coastguard Worker                                      JDIMENSION start_row, JDIMENSION num_rows,
864*dfc6aa5cSAndroid Build Coastguard Worker                                      boolean writable);
865*dfc6aa5cSAndroid Build Coastguard Worker   void (*free_pool) (j_common_ptr cinfo, int pool_id);
866*dfc6aa5cSAndroid Build Coastguard Worker   void (*self_destruct) (j_common_ptr cinfo);
867*dfc6aa5cSAndroid Build Coastguard Worker 
868*dfc6aa5cSAndroid Build Coastguard Worker   /* Limit on memory allocation for this JPEG object.  (Note that this is
869*dfc6aa5cSAndroid Build Coastguard Worker    * merely advisory, not a guaranteed maximum; it only affects the space
870*dfc6aa5cSAndroid Build Coastguard Worker    * used for virtual-array buffers.)  May be changed by outer application
871*dfc6aa5cSAndroid Build Coastguard Worker    * after creating the JPEG object.
872*dfc6aa5cSAndroid Build Coastguard Worker    */
873*dfc6aa5cSAndroid Build Coastguard Worker   long max_memory_to_use;
874*dfc6aa5cSAndroid Build Coastguard Worker 
875*dfc6aa5cSAndroid Build Coastguard Worker   /* Maximum allocation request accepted by alloc_large. */
876*dfc6aa5cSAndroid Build Coastguard Worker   long max_alloc_chunk;
877*dfc6aa5cSAndroid Build Coastguard Worker };
878*dfc6aa5cSAndroid Build Coastguard Worker 
879*dfc6aa5cSAndroid Build Coastguard Worker 
880*dfc6aa5cSAndroid Build Coastguard Worker /* Routine signature for application-supplied marker processing methods.
881*dfc6aa5cSAndroid Build Coastguard Worker  * Need not pass marker code since it is stored in cinfo->unread_marker.
882*dfc6aa5cSAndroid Build Coastguard Worker  */
883*dfc6aa5cSAndroid Build Coastguard Worker typedef boolean (*jpeg_marker_parser_method) (j_decompress_ptr cinfo);
884*dfc6aa5cSAndroid Build Coastguard Worker 
885*dfc6aa5cSAndroid Build Coastguard Worker 
886*dfc6aa5cSAndroid Build Coastguard Worker /* Originally, this macro was used as a way of defining function prototypes
887*dfc6aa5cSAndroid Build Coastguard Worker  * for both modern compilers as well as older compilers that did not support
888*dfc6aa5cSAndroid Build Coastguard Worker  * prototype parameters.  libjpeg-turbo has never supported these older,
889*dfc6aa5cSAndroid Build Coastguard Worker  * non-ANSI compilers, but the macro is still included because there is some
890*dfc6aa5cSAndroid Build Coastguard Worker  * software out there that uses it.
891*dfc6aa5cSAndroid Build Coastguard Worker  */
892*dfc6aa5cSAndroid Build Coastguard Worker 
893*dfc6aa5cSAndroid Build Coastguard Worker #define JPP(arglist)    arglist
894*dfc6aa5cSAndroid Build Coastguard Worker 
895*dfc6aa5cSAndroid Build Coastguard Worker 
896*dfc6aa5cSAndroid Build Coastguard Worker /* Default error-management setup */
897*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(struct jpeg_error_mgr *) jpeg_std_error(struct jpeg_error_mgr *err);
898*dfc6aa5cSAndroid Build Coastguard Worker 
899*dfc6aa5cSAndroid Build Coastguard Worker /* Initialization of JPEG compression objects.
900*dfc6aa5cSAndroid Build Coastguard Worker  * jpeg_create_compress() and jpeg_create_decompress() are the exported
901*dfc6aa5cSAndroid Build Coastguard Worker  * names that applications should call.  These expand to calls on
902*dfc6aa5cSAndroid Build Coastguard Worker  * jpeg_CreateCompress and jpeg_CreateDecompress with additional information
903*dfc6aa5cSAndroid Build Coastguard Worker  * passed for version mismatch checking.
904*dfc6aa5cSAndroid Build Coastguard Worker  * NB: you must set up the error-manager BEFORE calling jpeg_create_xxx.
905*dfc6aa5cSAndroid Build Coastguard Worker  */
906*dfc6aa5cSAndroid Build Coastguard Worker #define jpeg_create_compress(cinfo) \
907*dfc6aa5cSAndroid Build Coastguard Worker   jpeg_CreateCompress((cinfo), JPEG_LIB_VERSION, \
908*dfc6aa5cSAndroid Build Coastguard Worker                       (size_t)sizeof(struct jpeg_compress_struct))
909*dfc6aa5cSAndroid Build Coastguard Worker #define jpeg_create_decompress(cinfo) \
910*dfc6aa5cSAndroid Build Coastguard Worker   jpeg_CreateDecompress((cinfo), JPEG_LIB_VERSION, \
911*dfc6aa5cSAndroid Build Coastguard Worker                         (size_t)sizeof(struct jpeg_decompress_struct))
912*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jpeg_CreateCompress(j_compress_ptr cinfo, int version,
913*dfc6aa5cSAndroid Build Coastguard Worker                                  size_t structsize);
914*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jpeg_CreateDecompress(j_decompress_ptr cinfo, int version,
915*dfc6aa5cSAndroid Build Coastguard Worker                                    size_t structsize);
916*dfc6aa5cSAndroid Build Coastguard Worker /* Destruction of JPEG compression objects */
917*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jpeg_destroy_compress(j_compress_ptr cinfo);
918*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jpeg_destroy_decompress(j_decompress_ptr cinfo);
919*dfc6aa5cSAndroid Build Coastguard Worker 
920*dfc6aa5cSAndroid Build Coastguard Worker /* Standard data source and destination managers: stdio streams. */
921*dfc6aa5cSAndroid Build Coastguard Worker /* Caller is responsible for opening the file before and closing after. */
922*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jpeg_stdio_dest(j_compress_ptr cinfo, FILE *outfile);
923*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jpeg_stdio_src(j_decompress_ptr cinfo, FILE *infile);
924*dfc6aa5cSAndroid Build Coastguard Worker 
925*dfc6aa5cSAndroid Build Coastguard Worker #if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
926*dfc6aa5cSAndroid Build Coastguard Worker /* Data source and destination managers: memory buffers. */
927*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jpeg_mem_dest(j_compress_ptr cinfo, unsigned char **outbuffer,
928*dfc6aa5cSAndroid Build Coastguard Worker                            unsigned long *outsize);
929*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jpeg_mem_src(j_decompress_ptr cinfo,
930*dfc6aa5cSAndroid Build Coastguard Worker                           const unsigned char *inbuffer, unsigned long insize);
931*dfc6aa5cSAndroid Build Coastguard Worker #endif
932*dfc6aa5cSAndroid Build Coastguard Worker 
933*dfc6aa5cSAndroid Build Coastguard Worker /* Default parameter setup for compression */
934*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jpeg_set_defaults(j_compress_ptr cinfo);
935*dfc6aa5cSAndroid Build Coastguard Worker /* Compression parameter setup aids */
936*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jpeg_set_colorspace(j_compress_ptr cinfo,
937*dfc6aa5cSAndroid Build Coastguard Worker                                  J_COLOR_SPACE colorspace);
938*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jpeg_default_colorspace(j_compress_ptr cinfo);
939*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jpeg_set_quality(j_compress_ptr cinfo, int quality,
940*dfc6aa5cSAndroid Build Coastguard Worker                               boolean force_baseline);
941*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jpeg_set_linear_quality(j_compress_ptr cinfo, int scale_factor,
942*dfc6aa5cSAndroid Build Coastguard Worker                                      boolean force_baseline);
943*dfc6aa5cSAndroid Build Coastguard Worker #if JPEG_LIB_VERSION >= 70
944*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jpeg_default_qtables(j_compress_ptr cinfo,
945*dfc6aa5cSAndroid Build Coastguard Worker                                   boolean force_baseline);
946*dfc6aa5cSAndroid Build Coastguard Worker #endif
947*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jpeg_add_quant_table(j_compress_ptr cinfo, int which_tbl,
948*dfc6aa5cSAndroid Build Coastguard Worker                                   const unsigned int *basic_table,
949*dfc6aa5cSAndroid Build Coastguard Worker                                   int scale_factor, boolean force_baseline);
950*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(int) jpeg_quality_scaling(int quality);
951*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jpeg_simple_progression(j_compress_ptr cinfo);
952*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jpeg_suppress_tables(j_compress_ptr cinfo, boolean suppress);
953*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(JQUANT_TBL *) jpeg_alloc_quant_table(j_common_ptr cinfo);
954*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(JHUFF_TBL *) jpeg_alloc_huff_table(j_common_ptr cinfo);
955*dfc6aa5cSAndroid Build Coastguard Worker 
956*dfc6aa5cSAndroid Build Coastguard Worker /* Main entry points for compression */
957*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jpeg_start_compress(j_compress_ptr cinfo,
958*dfc6aa5cSAndroid Build Coastguard Worker                                  boolean write_all_tables);
959*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(JDIMENSION) jpeg_write_scanlines(j_compress_ptr cinfo,
960*dfc6aa5cSAndroid Build Coastguard Worker                                         JSAMPARRAY scanlines,
961*dfc6aa5cSAndroid Build Coastguard Worker                                         JDIMENSION num_lines);
962*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jpeg_finish_compress(j_compress_ptr cinfo);
963*dfc6aa5cSAndroid Build Coastguard Worker 
964*dfc6aa5cSAndroid Build Coastguard Worker #if JPEG_LIB_VERSION >= 70
965*dfc6aa5cSAndroid Build Coastguard Worker /* Precalculate JPEG dimensions for current compression parameters. */
966*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jpeg_calc_jpeg_dimensions(j_compress_ptr cinfo);
967*dfc6aa5cSAndroid Build Coastguard Worker #endif
968*dfc6aa5cSAndroid Build Coastguard Worker 
969*dfc6aa5cSAndroid Build Coastguard Worker /* Replaces jpeg_write_scanlines when writing raw downsampled data. */
970*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(JDIMENSION) jpeg_write_raw_data(j_compress_ptr cinfo, JSAMPIMAGE data,
971*dfc6aa5cSAndroid Build Coastguard Worker                                        JDIMENSION num_lines);
972*dfc6aa5cSAndroid Build Coastguard Worker 
973*dfc6aa5cSAndroid Build Coastguard Worker /* Write a special marker.  See libjpeg.txt concerning safe usage. */
974*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jpeg_write_marker(j_compress_ptr cinfo, int marker,
975*dfc6aa5cSAndroid Build Coastguard Worker                                const JOCTET *dataptr, unsigned int datalen);
976*dfc6aa5cSAndroid Build Coastguard Worker /* Same, but piecemeal. */
977*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jpeg_write_m_header(j_compress_ptr cinfo, int marker,
978*dfc6aa5cSAndroid Build Coastguard Worker                                  unsigned int datalen);
979*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jpeg_write_m_byte(j_compress_ptr cinfo, int val);
980*dfc6aa5cSAndroid Build Coastguard Worker 
981*dfc6aa5cSAndroid Build Coastguard Worker /* Alternate compression function: just write an abbreviated table file */
982*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jpeg_write_tables(j_compress_ptr cinfo);
983*dfc6aa5cSAndroid Build Coastguard Worker 
984*dfc6aa5cSAndroid Build Coastguard Worker /* Write ICC profile.  See libjpeg.txt for usage information. */
985*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jpeg_write_icc_profile(j_compress_ptr cinfo,
986*dfc6aa5cSAndroid Build Coastguard Worker                                     const JOCTET *icc_data_ptr,
987*dfc6aa5cSAndroid Build Coastguard Worker                                     unsigned int icc_data_len);
988*dfc6aa5cSAndroid Build Coastguard Worker 
989*dfc6aa5cSAndroid Build Coastguard Worker 
990*dfc6aa5cSAndroid Build Coastguard Worker /* Decompression startup: read start of JPEG datastream to see what's there */
991*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(int) jpeg_read_header(j_decompress_ptr cinfo, boolean require_image);
992*dfc6aa5cSAndroid Build Coastguard Worker /* Return value is one of: */
993*dfc6aa5cSAndroid Build Coastguard Worker #define JPEG_SUSPENDED           0 /* Suspended due to lack of input data */
994*dfc6aa5cSAndroid Build Coastguard Worker #define JPEG_HEADER_OK           1 /* Found valid image datastream */
995*dfc6aa5cSAndroid Build Coastguard Worker #define JPEG_HEADER_TABLES_ONLY  2 /* Found valid table-specs-only datastream */
996*dfc6aa5cSAndroid Build Coastguard Worker /* If you pass require_image = TRUE (normal case), you need not check for
997*dfc6aa5cSAndroid Build Coastguard Worker  * a TABLES_ONLY return code; an abbreviated file will cause an error exit.
998*dfc6aa5cSAndroid Build Coastguard Worker  * JPEG_SUSPENDED is only possible if you use a data source module that can
999*dfc6aa5cSAndroid Build Coastguard Worker  * give a suspension return (the stdio source module doesn't).
1000*dfc6aa5cSAndroid Build Coastguard Worker  */
1001*dfc6aa5cSAndroid Build Coastguard Worker 
1002*dfc6aa5cSAndroid Build Coastguard Worker /* Main entry points for decompression */
1003*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(boolean) jpeg_start_decompress(j_decompress_ptr cinfo);
1004*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(JDIMENSION) jpeg_read_scanlines(j_decompress_ptr cinfo,
1005*dfc6aa5cSAndroid Build Coastguard Worker                                        JSAMPARRAY scanlines,
1006*dfc6aa5cSAndroid Build Coastguard Worker                                        JDIMENSION max_lines);
1007*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(JDIMENSION) jpeg_skip_scanlines(j_decompress_ptr cinfo,
1008*dfc6aa5cSAndroid Build Coastguard Worker                                        JDIMENSION num_lines);
1009*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jpeg_crop_scanline(j_decompress_ptr cinfo, JDIMENSION *xoffset,
1010*dfc6aa5cSAndroid Build Coastguard Worker                                 JDIMENSION *width);
1011*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(boolean) jpeg_finish_decompress(j_decompress_ptr cinfo);
1012*dfc6aa5cSAndroid Build Coastguard Worker 
1013*dfc6aa5cSAndroid Build Coastguard Worker /* Replaces jpeg_read_scanlines when reading raw downsampled data. */
1014*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(JDIMENSION) jpeg_read_raw_data(j_decompress_ptr cinfo, JSAMPIMAGE data,
1015*dfc6aa5cSAndroid Build Coastguard Worker                                       JDIMENSION max_lines);
1016*dfc6aa5cSAndroid Build Coastguard Worker 
1017*dfc6aa5cSAndroid Build Coastguard Worker /* Additional entry points for buffered-image mode. */
1018*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(boolean) jpeg_has_multiple_scans(j_decompress_ptr cinfo);
1019*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(boolean) jpeg_start_output(j_decompress_ptr cinfo, int scan_number);
1020*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(boolean) jpeg_finish_output(j_decompress_ptr cinfo);
1021*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(boolean) jpeg_input_complete(j_decompress_ptr cinfo);
1022*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jpeg_new_colormap(j_decompress_ptr cinfo);
1023*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(int) jpeg_consume_input(j_decompress_ptr cinfo);
1024*dfc6aa5cSAndroid Build Coastguard Worker /* Return value is one of: */
1025*dfc6aa5cSAndroid Build Coastguard Worker /* #define JPEG_SUSPENDED       0    Suspended due to lack of input data */
1026*dfc6aa5cSAndroid Build Coastguard Worker #define JPEG_REACHED_SOS        1 /* Reached start of new scan */
1027*dfc6aa5cSAndroid Build Coastguard Worker #define JPEG_REACHED_EOI        2 /* Reached end of image */
1028*dfc6aa5cSAndroid Build Coastguard Worker #define JPEG_ROW_COMPLETED      3 /* Completed one iMCU row */
1029*dfc6aa5cSAndroid Build Coastguard Worker #define JPEG_SCAN_COMPLETED     4 /* Completed last iMCU row of a scan */
1030*dfc6aa5cSAndroid Build Coastguard Worker 
1031*dfc6aa5cSAndroid Build Coastguard Worker /* Precalculate output dimensions for current decompression parameters. */
1032*dfc6aa5cSAndroid Build Coastguard Worker #if JPEG_LIB_VERSION >= 80
1033*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jpeg_core_output_dimensions(j_decompress_ptr cinfo);
1034*dfc6aa5cSAndroid Build Coastguard Worker #endif
1035*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jpeg_calc_output_dimensions(j_decompress_ptr cinfo);
1036*dfc6aa5cSAndroid Build Coastguard Worker 
1037*dfc6aa5cSAndroid Build Coastguard Worker /* Control saving of COM and APPn markers into marker_list. */
1038*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jpeg_save_markers(j_decompress_ptr cinfo, int marker_code,
1039*dfc6aa5cSAndroid Build Coastguard Worker                                unsigned int length_limit);
1040*dfc6aa5cSAndroid Build Coastguard Worker 
1041*dfc6aa5cSAndroid Build Coastguard Worker /* Install a special processing method for COM or APPn markers. */
1042*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jpeg_set_marker_processor(j_decompress_ptr cinfo,
1043*dfc6aa5cSAndroid Build Coastguard Worker                                        int marker_code,
1044*dfc6aa5cSAndroid Build Coastguard Worker                                        jpeg_marker_parser_method routine);
1045*dfc6aa5cSAndroid Build Coastguard Worker 
1046*dfc6aa5cSAndroid Build Coastguard Worker /* Read or write raw DCT coefficients --- useful for lossless transcoding. */
1047*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(jvirt_barray_ptr *) jpeg_read_coefficients(j_decompress_ptr cinfo);
1048*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jpeg_write_coefficients(j_compress_ptr cinfo,
1049*dfc6aa5cSAndroid Build Coastguard Worker                                      jvirt_barray_ptr *coef_arrays);
1050*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jpeg_copy_critical_parameters(j_decompress_ptr srcinfo,
1051*dfc6aa5cSAndroid Build Coastguard Worker                                            j_compress_ptr dstinfo);
1052*dfc6aa5cSAndroid Build Coastguard Worker 
1053*dfc6aa5cSAndroid Build Coastguard Worker /* If you choose to abort compression or decompression before completing
1054*dfc6aa5cSAndroid Build Coastguard Worker  * jpeg_finish_(de)compress, then you need to clean up to release memory,
1055*dfc6aa5cSAndroid Build Coastguard Worker  * temporary files, etc.  You can just call jpeg_destroy_(de)compress
1056*dfc6aa5cSAndroid Build Coastguard Worker  * if you're done with the JPEG object, but if you want to clean it up and
1057*dfc6aa5cSAndroid Build Coastguard Worker  * reuse it, call this:
1058*dfc6aa5cSAndroid Build Coastguard Worker  */
1059*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jpeg_abort_compress(j_compress_ptr cinfo);
1060*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jpeg_abort_decompress(j_decompress_ptr cinfo);
1061*dfc6aa5cSAndroid Build Coastguard Worker 
1062*dfc6aa5cSAndroid Build Coastguard Worker /* Generic versions of jpeg_abort and jpeg_destroy that work on either
1063*dfc6aa5cSAndroid Build Coastguard Worker  * flavor of JPEG object.  These may be more convenient in some places.
1064*dfc6aa5cSAndroid Build Coastguard Worker  */
1065*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jpeg_abort(j_common_ptr cinfo);
1066*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(void) jpeg_destroy(j_common_ptr cinfo);
1067*dfc6aa5cSAndroid Build Coastguard Worker 
1068*dfc6aa5cSAndroid Build Coastguard Worker /* Default restart-marker-resync procedure for use by data source modules */
1069*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(boolean) jpeg_resync_to_restart(j_decompress_ptr cinfo, int desired);
1070*dfc6aa5cSAndroid Build Coastguard Worker 
1071*dfc6aa5cSAndroid Build Coastguard Worker /* Read ICC profile.  See libjpeg.txt for usage information. */
1072*dfc6aa5cSAndroid Build Coastguard Worker EXTERN(boolean) jpeg_read_icc_profile(j_decompress_ptr cinfo,
1073*dfc6aa5cSAndroid Build Coastguard Worker                                       JOCTET **icc_data_ptr,
1074*dfc6aa5cSAndroid Build Coastguard Worker                                       unsigned int *icc_data_len);
1075*dfc6aa5cSAndroid Build Coastguard Worker 
1076*dfc6aa5cSAndroid Build Coastguard Worker 
1077*dfc6aa5cSAndroid Build Coastguard Worker /* These marker codes are exported since applications and data source modules
1078*dfc6aa5cSAndroid Build Coastguard Worker  * are likely to want to use them.
1079*dfc6aa5cSAndroid Build Coastguard Worker  */
1080*dfc6aa5cSAndroid Build Coastguard Worker 
1081*dfc6aa5cSAndroid Build Coastguard Worker #define JPEG_RST0       0xD0    /* RST0 marker code */
1082*dfc6aa5cSAndroid Build Coastguard Worker #define JPEG_EOI        0xD9    /* EOI marker code */
1083*dfc6aa5cSAndroid Build Coastguard Worker #define JPEG_APP0       0xE0    /* APP0 marker code */
1084*dfc6aa5cSAndroid Build Coastguard Worker #define JPEG_COM        0xFE    /* COM marker code */
1085*dfc6aa5cSAndroid Build Coastguard Worker 
1086*dfc6aa5cSAndroid Build Coastguard Worker 
1087*dfc6aa5cSAndroid Build Coastguard Worker /* If we have a brain-damaged compiler that emits warnings (or worse, errors)
1088*dfc6aa5cSAndroid Build Coastguard Worker  * for structure definitions that are never filled in, keep it quiet by
1089*dfc6aa5cSAndroid Build Coastguard Worker  * supplying dummy definitions for the various substructures.
1090*dfc6aa5cSAndroid Build Coastguard Worker  */
1091*dfc6aa5cSAndroid Build Coastguard Worker 
1092*dfc6aa5cSAndroid Build Coastguard Worker #ifdef INCOMPLETE_TYPES_BROKEN
1093*dfc6aa5cSAndroid Build Coastguard Worker #ifndef JPEG_INTERNALS          /* will be defined in jpegint.h */
1094*dfc6aa5cSAndroid Build Coastguard Worker struct jvirt_sarray_control { long dummy; };
1095*dfc6aa5cSAndroid Build Coastguard Worker struct jvirt_barray_control { long dummy; };
1096*dfc6aa5cSAndroid Build Coastguard Worker struct jpeg_comp_master { long dummy; };
1097*dfc6aa5cSAndroid Build Coastguard Worker struct jpeg_c_main_controller { long dummy; };
1098*dfc6aa5cSAndroid Build Coastguard Worker struct jpeg_c_prep_controller { long dummy; };
1099*dfc6aa5cSAndroid Build Coastguard Worker struct jpeg_c_coef_controller { long dummy; };
1100*dfc6aa5cSAndroid Build Coastguard Worker struct jpeg_marker_writer { long dummy; };
1101*dfc6aa5cSAndroid Build Coastguard Worker struct jpeg_color_converter { long dummy; };
1102*dfc6aa5cSAndroid Build Coastguard Worker struct jpeg_downsampler { long dummy; };
1103*dfc6aa5cSAndroid Build Coastguard Worker struct jpeg_forward_dct { long dummy; };
1104*dfc6aa5cSAndroid Build Coastguard Worker struct jpeg_entropy_encoder { long dummy; };
1105*dfc6aa5cSAndroid Build Coastguard Worker struct jpeg_decomp_master { long dummy; };
1106*dfc6aa5cSAndroid Build Coastguard Worker struct jpeg_d_main_controller { long dummy; };
1107*dfc6aa5cSAndroid Build Coastguard Worker struct jpeg_d_coef_controller { long dummy; };
1108*dfc6aa5cSAndroid Build Coastguard Worker struct jpeg_d_post_controller { long dummy; };
1109*dfc6aa5cSAndroid Build Coastguard Worker struct jpeg_input_controller { long dummy; };
1110*dfc6aa5cSAndroid Build Coastguard Worker struct jpeg_marker_reader { long dummy; };
1111*dfc6aa5cSAndroid Build Coastguard Worker struct jpeg_entropy_decoder { long dummy; };
1112*dfc6aa5cSAndroid Build Coastguard Worker struct jpeg_inverse_dct { long dummy; };
1113*dfc6aa5cSAndroid Build Coastguard Worker struct jpeg_upsampler { long dummy; };
1114*dfc6aa5cSAndroid Build Coastguard Worker struct jpeg_color_deconverter { long dummy; };
1115*dfc6aa5cSAndroid Build Coastguard Worker struct jpeg_color_quantizer { long dummy; };
1116*dfc6aa5cSAndroid Build Coastguard Worker #endif /* JPEG_INTERNALS */
1117*dfc6aa5cSAndroid Build Coastguard Worker #endif /* INCOMPLETE_TYPES_BROKEN */
1118*dfc6aa5cSAndroid Build Coastguard Worker 
1119*dfc6aa5cSAndroid Build Coastguard Worker 
1120*dfc6aa5cSAndroid Build Coastguard Worker /*
1121*dfc6aa5cSAndroid Build Coastguard Worker  * The JPEG library modules define JPEG_INTERNALS before including this file.
1122*dfc6aa5cSAndroid Build Coastguard Worker  * The internal structure declarations are read only when that is true.
1123*dfc6aa5cSAndroid Build Coastguard Worker  * Applications using the library should not include jpegint.h, but may wish
1124*dfc6aa5cSAndroid Build Coastguard Worker  * to include jerror.h.
1125*dfc6aa5cSAndroid Build Coastguard Worker  */
1126*dfc6aa5cSAndroid Build Coastguard Worker 
1127*dfc6aa5cSAndroid Build Coastguard Worker #ifdef JPEG_INTERNALS
1128*dfc6aa5cSAndroid Build Coastguard Worker #include "jpegint.h"            /* fetch private declarations */
1129*dfc6aa5cSAndroid Build Coastguard Worker #include "jerror.h"             /* fetch error codes too */
1130*dfc6aa5cSAndroid Build Coastguard Worker #endif
1131*dfc6aa5cSAndroid Build Coastguard Worker 
1132*dfc6aa5cSAndroid Build Coastguard Worker #ifdef __cplusplus
1133*dfc6aa5cSAndroid Build Coastguard Worker #ifndef DONT_USE_EXTERN_C
1134*dfc6aa5cSAndroid Build Coastguard Worker }
1135*dfc6aa5cSAndroid Build Coastguard Worker #endif
1136*dfc6aa5cSAndroid Build Coastguard Worker #endif
1137*dfc6aa5cSAndroid Build Coastguard Worker 
1138*dfc6aa5cSAndroid Build Coastguard Worker #endif /* JPEGLIB_H */
1139