136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/*
236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * jpeglib.h
336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane *
4a73e870ad02de20c2b34cb3a5382c2846c2afbe3DRC * This file was part of the Independent JPEG Group's software:
55ead57a34a398aa798f35bd7a6abad19b2e453e2Thomas G. Lane * Copyright (C) 1991-1998, Thomas G. Lane.
65996a25e2f50d20d6a8f09830724035b49c3927bGuido Vollbeding * Modified 2002-2009 by Guido Vollbeding.
7da13af6b8d5427af89bbdc5698b4e09d0ea814feDRC * libjpeg-turbo Modifications:
80ef076fb7b326dc201b4ab3bd30fefd4e35ad1c4DRC * Copyright (C) 2009-2011, 2013-2014, 2016, D. R. Commander.
9ac30a1bf12751bd82e56158eb9456a28d9c086f3DRC * Copyright (C) 2015, Google, Inc.
1036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * For conditions of distribution and use, see the accompanying README file.
1136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane *
1236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * This file defines the application interface for the JPEG library.
1336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * Most applications using the library need only include this file,
1436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * and perhaps jerror.h if they want to know the exact error codes.
1536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane */
1636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
179ba2f5ed3649fb6de83d3c16e4dba1443aaca983Thomas G. Lane#ifndef JPEGLIB_H
189ba2f5ed3649fb6de83d3c16e4dba1443aaca983Thomas G. Lane#define JPEGLIB_H
199ba2f5ed3649fb6de83d3c16e4dba1443aaca983Thomas G. Lane
2036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/*
2136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * First we include the configuration files that record how this
2236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * installation of the JPEG library is set up.  jconfig.h can be
2336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * generated automatically for many systems.  jmorecfg.h contains
2436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * manual configuration options that most people need not worry about.
2536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane */
2636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
27b775351012af176720429ac21d11682a0b75b4b7DRC#ifndef JCONFIG_INCLUDED        /* in case jinclude.h already did */
28b775351012af176720429ac21d11682a0b75b4b7DRC#include "jconfig.h"            /* widely used configuration options */
2936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#endif
30b775351012af176720429ac21d11682a0b75b4b7DRC#include "jmorecfg.h"           /* seldom changed options */
3136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
3236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
335996a25e2f50d20d6a8f09830724035b49c3927bGuido Vollbeding#ifdef __cplusplus
345996a25e2f50d20d6a8f09830724035b49c3927bGuido Vollbeding#ifndef DONT_USE_EXTERN_C
355996a25e2f50d20d6a8f09830724035b49c3927bGuido Vollbedingextern "C" {
365996a25e2f50d20d6a8f09830724035b49c3927bGuido Vollbeding#endif
375996a25e2f50d20d6a8f09830724035b49c3927bGuido Vollbeding#endif
3836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
3936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
4036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Various constants determining the sizes of things.
4136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * All of these are specified by the JPEG standard, so don't change them
4236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * if you want to be compatible.
4336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane */
4436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
45b775351012af176720429ac21d11682a0b75b4b7DRC#define DCTSIZE             8   /* The basic DCT block is 8x8 samples */
46b775351012af176720429ac21d11682a0b75b4b7DRC#define DCTSIZE2            64  /* DCTSIZE squared; # of elements in a block */
47b775351012af176720429ac21d11682a0b75b4b7DRC#define NUM_QUANT_TBLS      4   /* Quantization tables are numbered 0..3 */
48b775351012af176720429ac21d11682a0b75b4b7DRC#define NUM_HUFF_TBLS       4   /* Huffman tables are numbered 0..3 */
49b775351012af176720429ac21d11682a0b75b4b7DRC#define NUM_ARITH_TBLS      16  /* Arith-coding tables are numbered 0..15 */
50b775351012af176720429ac21d11682a0b75b4b7DRC#define MAX_COMPS_IN_SCAN   4   /* JPEG limit on # of components in one scan */
51b775351012af176720429ac21d11682a0b75b4b7DRC#define MAX_SAMP_FACTOR     4   /* JPEG limit on sampling factors */
52bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane/* Unfortunately, some bozo at Adobe saw no reason to be bound by the standard;
53bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane * the PostScript DCT filter can emit files with many more than 10 blocks/MCU.
54bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane * If you happen to run across such a file, you can up D_MAX_BLOCKS_IN_MCU
55bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane * to handle it.  We even let you do this from the jconfig.h file.  However,
56bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane * we strongly discourage changing C_MAX_BLOCKS_IN_MCU; just because Adobe
57bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane * sometimes emits noncompliant files doesn't mean you should too.
58bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane */
59bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane#define C_MAX_BLOCKS_IN_MCU   10 /* compressor's limit on blocks per MCU */
60bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane#ifndef D_MAX_BLOCKS_IN_MCU
61bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane#define D_MAX_BLOCKS_IN_MCU   10 /* decompressor's limit on blocks per MCU */
62bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane#endif
6336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
6436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
6536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Data structures for images (arrays of samples and of DCT coefficients).
6636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane */
6736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
685033f3e19a31e8ad40c1a79700365aefe5664494DRCtypedef JSAMPLE *JSAMPROW;      /* ptr to one image row of pixel samples. */
69b775351012af176720429ac21d11682a0b75b4b7DRCtypedef JSAMPROW *JSAMPARRAY;   /* ptr to some rows (a 2-D sample array) */
70b775351012af176720429ac21d11682a0b75b4b7DRCtypedef JSAMPARRAY *JSAMPIMAGE; /* a 3-D sample array: top index is color */
7136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
72b775351012af176720429ac21d11682a0b75b4b7DRCtypedef JCOEF JBLOCK[DCTSIZE2]; /* one block of coefficients */
735033f3e19a31e8ad40c1a79700365aefe5664494DRCtypedef JBLOCK *JBLOCKROW;      /* pointer to one row of coefficient blocks */
74b775351012af176720429ac21d11682a0b75b4b7DRCtypedef JBLOCKROW *JBLOCKARRAY;         /* a 2-D array of coefficient blocks */
75b775351012af176720429ac21d11682a0b75b4b7DRCtypedef JBLOCKARRAY *JBLOCKIMAGE;       /* a 3-D array of coefficient blocks */
7636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
775033f3e19a31e8ad40c1a79700365aefe5664494DRCtypedef JCOEF *JCOEFPTR;        /* useful in a couple of places */
7836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
7936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
8036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Types for JPEG compression parameters and working tables. */
8136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
8236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
8336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* DCT coefficient quantization tables. */
8436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
8536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanetypedef struct {
86489583f5165e05d37302e8eeec58104ea0109127Thomas G. Lane  /* This array gives the coefficient quantizers in natural array order
87489583f5165e05d37302e8eeec58104ea0109127Thomas G. Lane   * (not the zigzag order in which they are stored in a JPEG DQT marker).
88489583f5165e05d37302e8eeec58104ea0109127Thomas G. Lane   * CAUTION: IJG versions prior to v6a kept this array in zigzag order.
8936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   */
90b775351012af176720429ac21d11682a0b75b4b7DRC  UINT16 quantval[DCTSIZE2];    /* quantization step for each coefficient */
9136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* This field is used only during compression.  It's initialized FALSE when
9236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * the table is created, and set TRUE when it's been output to the file.
9336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * You could suppress output of a table by setting this to TRUE.
9436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * (See jpeg_suppress_tables for an example.)
9536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   */
96b775351012af176720429ac21d11682a0b75b4b7DRC  boolean sent_table;           /* TRUE when table has been output */
9736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane} JQUANT_TBL;
9836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
9936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
10036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Huffman coding tables. */
10136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
10236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanetypedef struct {
10336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* These two fields directly represent the contents of a JPEG DHT marker */
104b775351012af176720429ac21d11682a0b75b4b7DRC  UINT8 bits[17];               /* bits[k] = # of symbols with codes of */
105b775351012af176720429ac21d11682a0b75b4b7DRC                                /* length k bits; bits[0] is unused */
106b775351012af176720429ac21d11682a0b75b4b7DRC  UINT8 huffval[256];           /* The symbols, in order of incr code length */
10736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* This field is used only during compression.  It's initialized FALSE when
10836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * the table is created, and set TRUE when it's been output to the file.
10936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * You could suppress output of a table by setting this to TRUE.
11036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * (See jpeg_suppress_tables for an example.)
11136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   */
112b775351012af176720429ac21d11682a0b75b4b7DRC  boolean sent_table;           /* TRUE when table has been output */
11336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane} JHUFF_TBL;
11436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
11536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
11636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Basic info about one component (color channel). */
11736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
11836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanetypedef struct {
11936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* These values are fixed over the whole image. */
12036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* For compression, they must be supplied by parameter setup; */
12136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* for decompression, they are read from the SOF marker. */
122b775351012af176720429ac21d11682a0b75b4b7DRC  int component_id;             /* identifier for this component (0..255) */
123b775351012af176720429ac21d11682a0b75b4b7DRC  int component_index;          /* its index in SOF or cinfo->comp_info[] */
124b775351012af176720429ac21d11682a0b75b4b7DRC  int h_samp_factor;            /* horizontal sampling factor (1..4) */
125b775351012af176720429ac21d11682a0b75b4b7DRC  int v_samp_factor;            /* vertical sampling factor (1..4) */
126b775351012af176720429ac21d11682a0b75b4b7DRC  int quant_tbl_no;             /* quantization table selector (0..3) */
12736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* These values may vary between scans. */
12836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* For compression, they must be supplied by parameter setup; */
12936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* for decompression, they are read from the SOS marker. */
130bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane  /* The decompressor output side may not use these variables. */
131b775351012af176720429ac21d11682a0b75b4b7DRC  int dc_tbl_no;                /* DC entropy table selector (0..3) */
132b775351012af176720429ac21d11682a0b75b4b7DRC  int ac_tbl_no;                /* AC entropy table selector (0..3) */
133b775351012af176720429ac21d11682a0b75b4b7DRC
13436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* Remaining fields should be treated as private by applications. */
135b775351012af176720429ac21d11682a0b75b4b7DRC
13636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* These values are computed during compression or decompression startup: */
13736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* Component's size in DCT blocks.
13836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * Any dummy blocks added to complete an MCU are not counted; therefore
13936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * these values do not depend on whether a scan is interleaved or not.
14036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   */
14136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  JDIMENSION width_in_blocks;
14236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  JDIMENSION height_in_blocks;
14336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* Size of a DCT block in samples.  Always DCTSIZE for compression.
14436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * For decompression this is the size of the output from one DCT block,
14536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * reflecting any scaling we choose to apply during the IDCT step.
146fe9c907b45809f44444f3a0045eafff0ddf0dacdDRC   * Values from 1 to 16 are supported.
147fe9c907b45809f44444f3a0045eafff0ddf0dacdDRC   * Note that different components may receive different IDCT scalings.
14836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   */
14910acd811d06d3f1a5743875028d6396ac70df0efDRC#if JPEG_LIB_VERSION >= 70
15010acd811d06d3f1a5743875028d6396ac70df0efDRC  int DCT_h_scaled_size;
15110acd811d06d3f1a5743875028d6396ac70df0efDRC  int DCT_v_scaled_size;
15210acd811d06d3f1a5743875028d6396ac70df0efDRC#else
15336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  int DCT_scaled_size;
15410acd811d06d3f1a5743875028d6396ac70df0efDRC#endif
15536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* The downsampled dimensions are the component's actual, unpadded number
15636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * of samples at the main buffer (preprocessing/compression interface), thus
15736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * downsampled_width = ceil(image_width * Hi/Hmax)
15836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * and similarly for height.  For decompression, IDCT scaling is included, so
15910acd811d06d3f1a5743875028d6396ac70df0efDRC   * downsampled_width = ceil(image_width * Hi/Hmax * DCT_[h_]scaled_size/DCTSIZE)
16036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   */
161b775351012af176720429ac21d11682a0b75b4b7DRC  JDIMENSION downsampled_width;  /* actual width in samples */
16236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  JDIMENSION downsampled_height; /* actual height in samples */
16336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* This flag is used only for decompression.  In cases where some of the
16436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * components will be ignored (eg grayscale output from YCbCr image),
16536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * we can skip most computations for the unused components.
16636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   */
167b775351012af176720429ac21d11682a0b75b4b7DRC  boolean component_needed;     /* do we need the value of this component? */
16836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
169bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane  /* These values are computed before starting a scan of the component. */
170bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane  /* The decompressor output side may not use these variables. */
171b775351012af176720429ac21d11682a0b75b4b7DRC  int MCU_width;                /* number of blocks per MCU, horizontally */
172b775351012af176720429ac21d11682a0b75b4b7DRC  int MCU_height;               /* number of blocks per MCU, vertically */
173b775351012af176720429ac21d11682a0b75b4b7DRC  int MCU_blocks;               /* MCU_width * MCU_height */
174b775351012af176720429ac21d11682a0b75b4b7DRC  int MCU_sample_width;         /* MCU width in samples, MCU_width*DCT_[h_]scaled_size */
175b775351012af176720429ac21d11682a0b75b4b7DRC  int last_col_width;           /* # of non-dummy blocks across in last MCU */
176b775351012af176720429ac21d11682a0b75b4b7DRC  int last_row_height;          /* # of non-dummy blocks down in last MCU */
17736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
178bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane  /* Saved quantization table for component; NULL if none yet saved.
179bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane   * See jdinput.c comments about the need for this information.
180489583f5165e05d37302e8eeec58104ea0109127Thomas G. Lane   * This field is currently used only for decompression.
181bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane   */
182bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane  JQUANT_TBL * quant_table;
183bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane
18436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* Private per-component storage for DCT or IDCT subsystem. */
18536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  void * dct_table;
18636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane} jpeg_component_info;
18736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
18836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
189bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane/* The script for encoding a multiple-scan file is an array of these: */
190bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane
191bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lanetypedef struct {
192b775351012af176720429ac21d11682a0b75b4b7DRC  int comps_in_scan;            /* number of components encoded in this scan */
193bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane  int component_index[MAX_COMPS_IN_SCAN]; /* their SOF/comp_info[] indexes */
194b775351012af176720429ac21d11682a0b75b4b7DRC  int Ss, Se;                   /* progressive JPEG spectral selection parms */
195b775351012af176720429ac21d11682a0b75b4b7DRC  int Ah, Al;                   /* progressive JPEG successive approx. parms */
196bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane} jpeg_scan_info;
197bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane
1985ead57a34a398aa798f35bd7a6abad19b2e453e2Thomas G. Lane/* The decompressor can save APPn and COM markers in a list of these: */
1995ead57a34a398aa798f35bd7a6abad19b2e453e2Thomas G. Lane
2005033f3e19a31e8ad40c1a79700365aefe5664494DRCtypedef struct jpeg_marker_struct * jpeg_saved_marker_ptr;
2015ead57a34a398aa798f35bd7a6abad19b2e453e2Thomas G. Lane
2025ead57a34a398aa798f35bd7a6abad19b2e453e2Thomas G. Lanestruct jpeg_marker_struct {
203b775351012af176720429ac21d11682a0b75b4b7DRC  jpeg_saved_marker_ptr next;   /* next in list, or NULL */
204b775351012af176720429ac21d11682a0b75b4b7DRC  UINT8 marker;                 /* marker code: JPEG_COM, or JPEG_APP0+n */
205b775351012af176720429ac21d11682a0b75b4b7DRC  unsigned int original_length; /* # bytes of data in the file */
206b775351012af176720429ac21d11682a0b75b4b7DRC  unsigned int data_length;     /* # bytes of data saved at data[] */
2075033f3e19a31e8ad40c1a79700365aefe5664494DRC  JOCTET * data;                /* the data contained in the marker */
2085ead57a34a398aa798f35bd7a6abad19b2e453e2Thomas G. Lane  /* the marker length word is not counted in data_length or original_length */
2095ead57a34a398aa798f35bd7a6abad19b2e453e2Thomas G. Lane};
210bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane
21136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Known color spaces. */
21236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
213f25c071eb745268452206bb633561b770c4d62eaDRC#define JCS_EXTENSIONS 1
21467ce3b2352fe1f7511edbfed74ec6960e41e97dcDRC#define JCS_ALPHA_EXTENSIONS 1
215f25c071eb745268452206bb633561b770c4d62eaDRC
21636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanetypedef enum {
217333e9187c8a6f69833baaee51ccd802b0e093cc1DRC  JCS_UNKNOWN,            /* error/unspecified */
218333e9187c8a6f69833baaee51ccd802b0e093cc1DRC  JCS_GRAYSCALE,          /* monochrome */
219333e9187c8a6f69833baaee51ccd802b0e093cc1DRC  JCS_RGB,                /* red/green/blue as specified by the RGB_RED,
220333e9187c8a6f69833baaee51ccd802b0e093cc1DRC                             RGB_GREEN, RGB_BLUE, and RGB_PIXELSIZE macros */
221333e9187c8a6f69833baaee51ccd802b0e093cc1DRC  JCS_YCbCr,              /* Y/Cb/Cr (also known as YUV) */
222333e9187c8a6f69833baaee51ccd802b0e093cc1DRC  JCS_CMYK,               /* C/M/Y/K */
223333e9187c8a6f69833baaee51ccd802b0e093cc1DRC  JCS_YCCK,               /* Y/Cb/Cr/K */
224333e9187c8a6f69833baaee51ccd802b0e093cc1DRC  JCS_EXT_RGB,            /* red/green/blue */
225333e9187c8a6f69833baaee51ccd802b0e093cc1DRC  JCS_EXT_RGBX,           /* red/green/blue/x */
226333e9187c8a6f69833baaee51ccd802b0e093cc1DRC  JCS_EXT_BGR,            /* blue/green/red */
227333e9187c8a6f69833baaee51ccd802b0e093cc1DRC  JCS_EXT_BGRX,           /* blue/green/red/x */
228333e9187c8a6f69833baaee51ccd802b0e093cc1DRC  JCS_EXT_XBGR,           /* x/blue/green/red */
229333e9187c8a6f69833baaee51ccd802b0e093cc1DRC  JCS_EXT_XRGB,           /* x/red/green/blue */
230333e9187c8a6f69833baaee51ccd802b0e093cc1DRC  /* When out_color_space it set to JCS_EXT_RGBX, JCS_EXT_BGRX, JCS_EXT_XBGR,
231333e9187c8a6f69833baaee51ccd802b0e093cc1DRC     or JCS_EXT_XRGB during decompression, the X byte is undefined, and in
232333e9187c8a6f69833baaee51ccd802b0e093cc1DRC     order to ensure the best performance, libjpeg-turbo can set that byte to
233333e9187c8a6f69833baaee51ccd802b0e093cc1DRC     whatever value it wishes.  Use the following colorspace constants to
234333e9187c8a6f69833baaee51ccd802b0e093cc1DRC     ensure that the X byte is set to 0xFF, so that it can be interpreted as an
235333e9187c8a6f69833baaee51ccd802b0e093cc1DRC     opaque alpha channel. */
236333e9187c8a6f69833baaee51ccd802b0e093cc1DRC  JCS_EXT_RGBA,           /* red/green/blue/alpha */
237333e9187c8a6f69833baaee51ccd802b0e093cc1DRC  JCS_EXT_BGRA,           /* blue/green/red/alpha */
238333e9187c8a6f69833baaee51ccd802b0e093cc1DRC  JCS_EXT_ABGR,           /* alpha/blue/green/red */
23978df2e6115b0e579432d01cb034132cd4402a1baDRC  JCS_EXT_ARGB,           /* alpha/red/green/blue */
24078df2e6115b0e579432d01cb034132cd4402a1baDRC  JCS_RGB565              /* 5-bit red/6-bit green/5-bit blue */
24136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane} J_COLOR_SPACE;
24236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
24336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* DCT/IDCT algorithm options. */
24436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
24536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanetypedef enum {
246333e9187c8a6f69833baaee51ccd802b0e093cc1DRC  JDCT_ISLOW,             /* slow but accurate integer algorithm */
247333e9187c8a6f69833baaee51ccd802b0e093cc1DRC  JDCT_IFAST,             /* faster, less accurate integer method */
248333e9187c8a6f69833baaee51ccd802b0e093cc1DRC  JDCT_FLOAT              /* floating-point: accurate, fast on fast HW */
24936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane} J_DCT_METHOD;
25036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
251b775351012af176720429ac21d11682a0b75b4b7DRC#ifndef JDCT_DEFAULT            /* may be overridden in jconfig.h */
25236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#define JDCT_DEFAULT  JDCT_ISLOW
25336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#endif
254b775351012af176720429ac21d11682a0b75b4b7DRC#ifndef JDCT_FASTEST            /* may be overridden in jconfig.h */
25536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#define JDCT_FASTEST  JDCT_IFAST
25636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#endif
25736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
25836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Dithering options for decompression. */
25936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
26036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanetypedef enum {
261333e9187c8a6f69833baaee51ccd802b0e093cc1DRC  JDITHER_NONE,           /* no dithering */
262333e9187c8a6f69833baaee51ccd802b0e093cc1DRC  JDITHER_ORDERED,        /* simple ordered dither */
263333e9187c8a6f69833baaee51ccd802b0e093cc1DRC  JDITHER_FS              /* Floyd-Steinberg error diffusion dither */
26436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane} J_DITHER_MODE;
26536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
26636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
26736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Common fields between JPEG compression and decompression master structs. */
26836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
26936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#define jpeg_common_fields \
270b775351012af176720429ac21d11682a0b75b4b7DRC  struct jpeg_error_mgr * err;  /* Error handler module */\
271b775351012af176720429ac21d11682a0b75b4b7DRC  struct jpeg_memory_mgr * mem; /* Memory manager module */\
27236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  struct jpeg_progress_mgr * progress; /* Progress monitor, or NULL if none */\
273b775351012af176720429ac21d11682a0b75b4b7DRC  void * client_data;           /* Available for use by application */\
274b775351012af176720429ac21d11682a0b75b4b7DRC  boolean is_decompressor;      /* So common code can tell which is which */\
275b775351012af176720429ac21d11682a0b75b4b7DRC  int global_state              /* For checking call sequence validity */
27636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
27736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Routines that are to be used by both halves of the library are declared
27836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * to receive a pointer to this structure.  There are no actual instances of
27936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * jpeg_common_struct, only of jpeg_compress_struct and jpeg_decompress_struct.
28036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane */
28136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jpeg_common_struct {
282b775351012af176720429ac21d11682a0b75b4b7DRC  jpeg_common_fields;           /* Fields common to both master struct types */
28336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* Additional fields follow in an actual jpeg_compress_struct or
28436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * jpeg_decompress_struct.  All three structs must agree on these
28536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * initial fields!  (This would be a lot cleaner in C++.)
28636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   */
28736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane};
28836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
28936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanetypedef struct jpeg_common_struct * j_common_ptr;
29036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanetypedef struct jpeg_compress_struct * j_compress_ptr;
29136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanetypedef struct jpeg_decompress_struct * j_decompress_ptr;
29236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
29336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
29436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Master record for a compression instance */
29536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
29636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jpeg_compress_struct {
297b775351012af176720429ac21d11682a0b75b4b7DRC  jpeg_common_fields;           /* Fields shared with jpeg_decompress_struct */
29836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
29936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* Destination for compressed data */
30036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  struct jpeg_destination_mgr * dest;
30136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
30236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* Description of source image --- these fields must be filled in by
30336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * outer application before starting compression.  in_color_space must
30436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * be correct before you can even call jpeg_set_defaults().
30536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   */
30636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
307b775351012af176720429ac21d11682a0b75b4b7DRC  JDIMENSION image_width;       /* input image width */
308b775351012af176720429ac21d11682a0b75b4b7DRC  JDIMENSION image_height;      /* input image height */
309b775351012af176720429ac21d11682a0b75b4b7DRC  int input_components;         /* # of color components in input image */
310b775351012af176720429ac21d11682a0b75b4b7DRC  J_COLOR_SPACE in_color_space; /* colorspace of input image */
31136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
312b775351012af176720429ac21d11682a0b75b4b7DRC  double input_gamma;           /* image gamma of input image */
31336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
31436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* Compression parameters --- these fields must be set before calling
31536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * jpeg_start_compress().  We recommend calling jpeg_set_defaults() to
31636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * initialize everything to reasonable defaults, then changing anything
31736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * the application specifically wants to change.  That way you won't get
31836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * burnt when new parameters are added.  Also note that there are several
31936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * helper routines to simplify changing parameters.
32036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   */
32136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
32236a6eec93250e390d1028b3372078810b4428eafDRC#if JPEG_LIB_VERSION >= 70
3235996a25e2f50d20d6a8f09830724035b49c3927bGuido Vollbeding  unsigned int scale_num, scale_denom; /* fraction by which to scale image */
3245996a25e2f50d20d6a8f09830724035b49c3927bGuido Vollbeding
325b775351012af176720429ac21d11682a0b75b4b7DRC  JDIMENSION jpeg_width;        /* scaled JPEG image width */
326b775351012af176720429ac21d11682a0b75b4b7DRC  JDIMENSION jpeg_height;       /* scaled JPEG image height */
3275996a25e2f50d20d6a8f09830724035b49c3927bGuido Vollbeding  /* Dimensions of actual JPEG image that will be written to file,
3285996a25e2f50d20d6a8f09830724035b49c3927bGuido Vollbeding   * derived from input dimensions by scaling factors above.
3295996a25e2f50d20d6a8f09830724035b49c3927bGuido Vollbeding   * These fields are computed by jpeg_start_compress().
3305996a25e2f50d20d6a8f09830724035b49c3927bGuido Vollbeding   * You can also use jpeg_calc_jpeg_dimensions() to determine these values
3315996a25e2f50d20d6a8f09830724035b49c3927bGuido Vollbeding   * in advance of calling jpeg_start_compress().
3325996a25e2f50d20d6a8f09830724035b49c3927bGuido Vollbeding   */
33336a6eec93250e390d1028b3372078810b4428eafDRC#endif
3345996a25e2f50d20d6a8f09830724035b49c3927bGuido Vollbeding
335b775351012af176720429ac21d11682a0b75b4b7DRC  int data_precision;           /* bits of precision in image data */
33636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
337b775351012af176720429ac21d11682a0b75b4b7DRC  int num_components;           /* # of color components in JPEG image */
33836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
33936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
34036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  jpeg_component_info * comp_info;
34136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* comp_info[i] describes component that appears i'th in SOF */
3425996a25e2f50d20d6a8f09830724035b49c3927bGuido Vollbeding
34336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
34436a6eec93250e390d1028b3372078810b4428eafDRC#if JPEG_LIB_VERSION >= 70
3455996a25e2f50d20d6a8f09830724035b49c3927bGuido Vollbeding  int q_scale_factor[NUM_QUANT_TBLS];
34636a6eec93250e390d1028b3372078810b4428eafDRC#endif
3475996a25e2f50d20d6a8f09830724035b49c3927bGuido Vollbeding  /* ptrs to coefficient quantization tables, or NULL if not defined,
3485996a25e2f50d20d6a8f09830724035b49c3927bGuido Vollbeding   * and corresponding scale factors (percentage, initialized 100).
3495996a25e2f50d20d6a8f09830724035b49c3927bGuido Vollbeding   */
3505996a25e2f50d20d6a8f09830724035b49c3927bGuido Vollbeding
35136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
35236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
35336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* ptrs to Huffman coding tables, or NULL if not defined */
3545996a25e2f50d20d6a8f09830724035b49c3927bGuido Vollbeding
35536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
35636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
35736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
35836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
359b775351012af176720429ac21d11682a0b75b4b7DRC  int num_scans;                /* # of entries in scan_info array */
360bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane  const jpeg_scan_info * scan_info; /* script for multi-scan file, or NULL */
361bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane  /* The default value of scan_info is NULL, which causes a single-scan
362bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane   * sequential JPEG file to be emitted.  To create a multi-scan file,
363bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane   * set num_scans and scan_info to point to an array of scan definitions.
364bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane   */
365bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane
366b775351012af176720429ac21d11682a0b75b4b7DRC  boolean raw_data_in;          /* TRUE=caller supplies downsampled data */
367b775351012af176720429ac21d11682a0b75b4b7DRC  boolean arith_code;           /* TRUE=arithmetic coding, FALSE=Huffman */
368b775351012af176720429ac21d11682a0b75b4b7DRC  boolean optimize_coding;      /* TRUE=optimize entropy encoding parms */
369b775351012af176720429ac21d11682a0b75b4b7DRC  boolean CCIR601_sampling;     /* TRUE=first samples are cosited */
37036a6eec93250e390d1028b3372078810b4428eafDRC#if JPEG_LIB_VERSION >= 70
3715996a25e2f50d20d6a8f09830724035b49c3927bGuido Vollbeding  boolean do_fancy_downsampling; /* TRUE=apply fancy downsampling */
37236a6eec93250e390d1028b3372078810b4428eafDRC#endif
373b775351012af176720429ac21d11682a0b75b4b7DRC  int smoothing_factor;         /* 1..100, or 0 for no input smoothing */
374b775351012af176720429ac21d11682a0b75b4b7DRC  J_DCT_METHOD dct_method;      /* DCT algorithm selector */
37536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
37636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* The restart interval can be specified in absolute MCUs by setting
37736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * restart_interval, or in MCU rows by setting restart_in_rows
37836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * (in which case the correct restart_interval will be figured
37936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * for each scan).
38036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   */
38136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  unsigned int restart_interval; /* MCUs per restart, or 0 for no restart */
382b775351012af176720429ac21d11682a0b75b4b7DRC  int restart_in_rows;          /* if > 0, MCU rows per restart interval */
38336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
38436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* Parameters controlling emission of special markers. */
38536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
386b775351012af176720429ac21d11682a0b75b4b7DRC  boolean write_JFIF_header;    /* should a JFIF marker be written? */
387b775351012af176720429ac21d11682a0b75b4b7DRC  UINT8 JFIF_major_version;     /* What to write for the JFIF version number */
3885ead57a34a398aa798f35bd7a6abad19b2e453e2Thomas G. Lane  UINT8 JFIF_minor_version;
38936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* These three values are not used by the JPEG code, merely copied */
39036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* into the JFIF APP0 marker.  density_unit can be 0 for unknown, */
39136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* 1 for dots/inch, or 2 for dots/cm.  Note that the pixel aspect */
39236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* ratio is defined by X_density/Y_density even when density_unit=0. */
393b775351012af176720429ac21d11682a0b75b4b7DRC  UINT8 density_unit;           /* JFIF code for pixel size units */
394b775351012af176720429ac21d11682a0b75b4b7DRC  UINT16 X_density;             /* Horizontal pixel density */
395b775351012af176720429ac21d11682a0b75b4b7DRC  UINT16 Y_density;             /* Vertical pixel density */
396b775351012af176720429ac21d11682a0b75b4b7DRC  boolean write_Adobe_marker;   /* should an Adobe marker be written? */
397b775351012af176720429ac21d11682a0b75b4b7DRC
39836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* State variable: index of next scanline to be written to
39936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * jpeg_write_scanlines().  Application may use this to control its
40036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * processing loop, e.g., "while (next_scanline < image_height)".
40136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   */
40236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
403b775351012af176720429ac21d11682a0b75b4b7DRC  JDIMENSION next_scanline;     /* 0 .. image_height-1  */
40436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
40536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* Remaining fields are known throughout compressor, but generally
40636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * should not be touched by a surrounding application.
40736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   */
40836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
40936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /*
41036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * These fields are computed during compression startup
41136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   */
412b775351012af176720429ac21d11682a0b75b4b7DRC  boolean progressive_mode;     /* TRUE if scan script uses progressive mode */
413b775351012af176720429ac21d11682a0b75b4b7DRC  int max_h_samp_factor;        /* largest h_samp_factor */
414b775351012af176720429ac21d11682a0b75b4b7DRC  int max_v_samp_factor;        /* largest v_samp_factor */
41536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
41636a6eec93250e390d1028b3372078810b4428eafDRC#if JPEG_LIB_VERSION >= 70
417b775351012af176720429ac21d11682a0b75b4b7DRC  int min_DCT_h_scaled_size;    /* smallest DCT_h_scaled_size of any component */
418b775351012af176720429ac21d11682a0b75b4b7DRC  int min_DCT_v_scaled_size;    /* smallest DCT_v_scaled_size of any component */
41936a6eec93250e390d1028b3372078810b4428eafDRC#endif
4205996a25e2f50d20d6a8f09830724035b49c3927bGuido Vollbeding
421b775351012af176720429ac21d11682a0b75b4b7DRC  JDIMENSION total_iMCU_rows;   /* # of iMCU rows to be input to coef ctlr */
42236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* The coefficient controller receives data in units of MCU rows as defined
42336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * for fully interleaved scans (whether the JPEG file is interleaved or not).
42436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * There are v_samp_factor * DCTSIZE sample rows of each component in an
42536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * "iMCU" (interleaved MCU) row.
42636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   */
427b775351012af176720429ac21d11682a0b75b4b7DRC
42836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /*
42936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * These fields are valid during any one scan.
43036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * They describe the components and MCUs actually appearing in the scan.
43136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   */
432b775351012af176720429ac21d11682a0b75b4b7DRC  int comps_in_scan;            /* # of JPEG components in this scan */
43336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
43436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* *cur_comp_info[i] describes component that appears i'th in SOS */
435b775351012af176720429ac21d11682a0b75b4b7DRC
436b775351012af176720429ac21d11682a0b75b4b7DRC  JDIMENSION MCUs_per_row;      /* # of MCUs across the image */
437b775351012af176720429ac21d11682a0b75b4b7DRC  JDIMENSION MCU_rows_in_scan;  /* # of MCU rows in the image */
438b775351012af176720429ac21d11682a0b75b4b7DRC
439b775351012af176720429ac21d11682a0b75b4b7DRC  int blocks_in_MCU;            /* # of DCT blocks per MCU */
440bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane  int MCU_membership[C_MAX_BLOCKS_IN_MCU];
44136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* MCU_membership[i] is index in cur_comp_info of component owning */
44236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* i'th block in an MCU */
44336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
444b775351012af176720429ac21d11682a0b75b4b7DRC  int Ss, Se, Ah, Al;           /* progressive JPEG parameters for scan */
445bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane
44636a6eec93250e390d1028b3372078810b4428eafDRC#if JPEG_LIB_VERSION >= 80
447b775351012af176720429ac21d11682a0b75b4b7DRC  int block_size;               /* the basic DCT block size: 1..16 */
448b775351012af176720429ac21d11682a0b75b4b7DRC  const int * natural_order;    /* natural-order position array */
449b775351012af176720429ac21d11682a0b75b4b7DRC  int lim_Se;                   /* min( Se, DCTSIZE2-1 ) */
45036a6eec93250e390d1028b3372078810b4428eafDRC#endif
451989630f70cf1af69ebfefca8910d1647bf189712Guido Vollbeding
45236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /*
45336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * Links to compression subobjects (methods and private variables of modules)
45436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   */
45536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  struct jpeg_comp_master * master;
45636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  struct jpeg_c_main_controller * main;
45736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  struct jpeg_c_prep_controller * prep;
45836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  struct jpeg_c_coef_controller * coef;
45936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  struct jpeg_marker_writer * marker;
46036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  struct jpeg_color_converter * cconvert;
46136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  struct jpeg_downsampler * downsample;
46236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  struct jpeg_forward_dct * fdct;
46336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  struct jpeg_entropy_encoder * entropy;
4645ead57a34a398aa798f35bd7a6abad19b2e453e2Thomas G. Lane  jpeg_scan_info * script_space; /* workspace for jpeg_simple_progression */
4655ead57a34a398aa798f35bd7a6abad19b2e453e2Thomas G. Lane  int script_space_size;
46636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane};
46736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
46836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
46936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Master record for a decompression instance */
47036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
47136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jpeg_decompress_struct {
472b775351012af176720429ac21d11682a0b75b4b7DRC  jpeg_common_fields;           /* Fields shared with jpeg_compress_struct */
47336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
47436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* Source of compressed data */
47536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  struct jpeg_source_mgr * src;
47636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
47736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* Basic description of image --- filled in by jpeg_read_header(). */
47836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* Application may inspect these values to decide how to process image. */
47936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
480b775351012af176720429ac21d11682a0b75b4b7DRC  JDIMENSION image_width;       /* nominal image width (from SOF marker) */
481b775351012af176720429ac21d11682a0b75b4b7DRC  JDIMENSION image_height;      /* nominal image height */
482b775351012af176720429ac21d11682a0b75b4b7DRC  int num_components;           /* # of color components in JPEG image */
48336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
48436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
48536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* Decompression processing parameters --- these fields must be set before
48636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * calling jpeg_start_decompress().  Note that jpeg_read_header() initializes
48736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * them to default values.
48836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   */
48936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
49036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  J_COLOR_SPACE out_color_space; /* colorspace for output */
49136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
49236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  unsigned int scale_num, scale_denom; /* fraction by which to scale image */
49336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
494b775351012af176720429ac21d11682a0b75b4b7DRC  double output_gamma;          /* image gamma wanted in output */
49536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
496b775351012af176720429ac21d11682a0b75b4b7DRC  boolean buffered_image;       /* TRUE=multiple output passes */
497b775351012af176720429ac21d11682a0b75b4b7DRC  boolean raw_data_out;         /* TRUE=downsampled data wanted */
49836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
499b775351012af176720429ac21d11682a0b75b4b7DRC  J_DCT_METHOD dct_method;      /* IDCT algorithm selector */
500b775351012af176720429ac21d11682a0b75b4b7DRC  boolean do_fancy_upsampling;  /* TRUE=apply fancy upsampling */
501b775351012af176720429ac21d11682a0b75b4b7DRC  boolean do_block_smoothing;   /* TRUE=apply interblock smoothing */
502bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane
503b775351012af176720429ac21d11682a0b75b4b7DRC  boolean quantize_colors;      /* TRUE=colormapped output wanted */
50436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* the following are ignored if not quantize_colors: */
505b775351012af176720429ac21d11682a0b75b4b7DRC  J_DITHER_MODE dither_mode;    /* type of color dithering to use */
506b775351012af176720429ac21d11682a0b75b4b7DRC  boolean two_pass_quantize;    /* TRUE=use two-pass color quantization */
507b775351012af176720429ac21d11682a0b75b4b7DRC  int desired_number_of_colors; /* max # colors to use in created colormap */
508bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane  /* these are significant only in buffered-image mode: */
509b775351012af176720429ac21d11682a0b75b4b7DRC  boolean enable_1pass_quant;   /* enable future use of 1-pass quantizer */
510bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane  boolean enable_external_quant;/* enable future use of external colormap */
511b775351012af176720429ac21d11682a0b75b4b7DRC  boolean enable_2pass_quant;   /* enable future use of 2-pass quantizer */
51236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
51336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* Description of actual output image that will be returned to application.
51436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * These fields are computed by jpeg_start_decompress().
51536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * You can also use jpeg_calc_output_dimensions() to determine these values
51636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * in advance of calling jpeg_start_decompress().
51736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   */
51836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
519b775351012af176720429ac21d11682a0b75b4b7DRC  JDIMENSION output_width;      /* scaled image width */
520b775351012af176720429ac21d11682a0b75b4b7DRC  JDIMENSION output_height;     /* scaled image height */
521b775351012af176720429ac21d11682a0b75b4b7DRC  int out_color_components;     /* # of color components in out_color_space */
522b775351012af176720429ac21d11682a0b75b4b7DRC  int output_components;        /* # of color components returned */
52336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* output_components is 1 (a colormap index) when quantizing colors;
52436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * otherwise it equals out_color_components.
52536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   */
526b775351012af176720429ac21d11682a0b75b4b7DRC  int rec_outbuf_height;        /* min recommended height of scanline buffer */
52736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* If the buffer passed to jpeg_read_scanlines() is less than this many rows
52836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * high, space and time will be wasted due to unnecessary data copying.
52936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * Usually rec_outbuf_height will be 1 or 2, at most 4.
53036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   */
53136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
53236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* When quantizing colors, the output colormap is described by these fields.
53336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * The application can supply a colormap by setting colormap non-NULL before
53436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * calling jpeg_start_decompress; otherwise a colormap is created during
535bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane   * jpeg_start_decompress or jpeg_start_output.
53636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * The map has out_color_components rows and actual_number_of_colors columns.
53736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   */
538b775351012af176720429ac21d11682a0b75b4b7DRC  int actual_number_of_colors;  /* number of entries in use */
539b775351012af176720429ac21d11682a0b75b4b7DRC  JSAMPARRAY colormap;          /* The color map as a 2-D pixel array */
54036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
541bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane  /* State variables: these variables indicate the progress of decompression.
542bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane   * The application may examine these but must not modify them.
54336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   */
54436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
545bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane  /* Row index of next scanline to be read from jpeg_read_scanlines().
546bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane   * Application may use this to control its processing loop, e.g.,
547bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane   * "while (output_scanline < output_height)".
548bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane   */
549b775351012af176720429ac21d11682a0b75b4b7DRC  JDIMENSION output_scanline;   /* 0 .. output_height-1  */
55036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
551bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane  /* Current input scan number and number of iMCU rows completed in scan.
552bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane   * These indicate the progress of the decompressor input side.
553bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane   */
554b775351012af176720429ac21d11682a0b75b4b7DRC  int input_scan_number;        /* Number of SOS markers seen so far */
555b775351012af176720429ac21d11682a0b75b4b7DRC  JDIMENSION input_iMCU_row;    /* Number of iMCU rows completed */
556bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane
557bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane  /* The "output scan number" is the notional scan being displayed by the
558bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane   * output side.  The decompressor will not allow output scan/row number
559bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane   * to get ahead of input scan/row, but it can fall arbitrarily far behind.
560bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane   */
561b775351012af176720429ac21d11682a0b75b4b7DRC  int output_scan_number;       /* Nominal scan number being displayed */
562b775351012af176720429ac21d11682a0b75b4b7DRC  JDIMENSION output_iMCU_row;   /* Number of iMCU rows read */
563bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane
564bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane  /* Current progression status.  coef_bits[c][i] indicates the precision
565bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane   * with which component c's DCT coefficient i (in zigzag order) is known.
566bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane   * It is -1 when no data has yet been received, otherwise it is the point
567bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane   * transform (shift) value for the most recent scan of the coefficient
568bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane   * (thus, 0 at completion of the progression).
569bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane   * This pointer is NULL when reading a non-progressive file.
570bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane   */
571b775351012af176720429ac21d11682a0b75b4b7DRC  int (*coef_bits)[DCTSIZE2];   /* -1 or current Al value for each coef */
572bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane
57336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* Internal JPEG parameters --- the application usually need not look at
574bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane   * these fields.  Note that the decompressor output side may not use
575bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane   * any parameters that can change between scans.
57636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   */
57736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
57836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* Quantization and Huffman tables are carried forward across input
57936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * datastreams when processing abbreviated JPEG datastreams.
58036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   */
58136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
58236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
58336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* ptrs to coefficient quantization tables, or NULL if not defined */
58436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
58536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
58636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
58736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* ptrs to Huffman coding tables, or NULL if not defined */
58836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
58936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* These parameters are never carried across datastreams, since they
59036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * are given in SOF/SOS markers or defined to be reset by SOI.
59136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   */
59236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
593b775351012af176720429ac21d11682a0b75b4b7DRC  int data_precision;           /* bits of precision in image data */
59436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
59536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  jpeg_component_info * comp_info;
59636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* comp_info[i] describes component that appears i'th in SOF */
59736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
59836a6eec93250e390d1028b3372078810b4428eafDRC#if JPEG_LIB_VERSION >= 80
599b775351012af176720429ac21d11682a0b75b4b7DRC  boolean is_baseline;          /* TRUE if Baseline SOF0 encountered */
60036a6eec93250e390d1028b3372078810b4428eafDRC#endif
601b775351012af176720429ac21d11682a0b75b4b7DRC  boolean progressive_mode;     /* TRUE if SOFn specifies progressive mode */
602b775351012af176720429ac21d11682a0b75b4b7DRC  boolean arith_code;           /* TRUE=arithmetic coding, FALSE=Huffman */
603bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane
60436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
60536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
60636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
60736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
60836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  unsigned int restart_interval; /* MCUs per restart interval, or 0 for no restart */
60936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
61036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* These fields record data obtained from optional markers recognized by
61136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * the JPEG library.
61236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   */
613b775351012af176720429ac21d11682a0b75b4b7DRC  boolean saw_JFIF_marker;      /* TRUE iff a JFIF APP0 marker was found */
6145ead57a34a398aa798f35bd7a6abad19b2e453e2Thomas G. Lane  /* Data copied from JFIF marker; only valid if saw_JFIF_marker is TRUE: */
615b775351012af176720429ac21d11682a0b75b4b7DRC  UINT8 JFIF_major_version;     /* JFIF version number */
6165ead57a34a398aa798f35bd7a6abad19b2e453e2Thomas G. Lane  UINT8 JFIF_minor_version;
617b775351012af176720429ac21d11682a0b75b4b7DRC  UINT8 density_unit;           /* JFIF code for pixel size units */
618b775351012af176720429ac21d11682a0b75b4b7DRC  UINT16 X_density;             /* Horizontal pixel density */
619b775351012af176720429ac21d11682a0b75b4b7DRC  UINT16 Y_density;             /* Vertical pixel density */
620b775351012af176720429ac21d11682a0b75b4b7DRC  boolean saw_Adobe_marker;     /* TRUE iff an Adobe APP14 marker was found */
621b775351012af176720429ac21d11682a0b75b4b7DRC  UINT8 Adobe_transform;        /* Color transform code from Adobe marker */
62236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
623b775351012af176720429ac21d11682a0b75b4b7DRC  boolean CCIR601_sampling;     /* TRUE=first samples are cosited */
62436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
6255ead57a34a398aa798f35bd7a6abad19b2e453e2Thomas G. Lane  /* Aside from the specific data retained from APPn markers known to the
6265ead57a34a398aa798f35bd7a6abad19b2e453e2Thomas G. Lane   * library, the uninterpreted contents of any or all APPn and COM markers
6275ead57a34a398aa798f35bd7a6abad19b2e453e2Thomas G. Lane   * can be saved in a list for examination by the application.
6285ead57a34a398aa798f35bd7a6abad19b2e453e2Thomas G. Lane   */
6295ead57a34a398aa798f35bd7a6abad19b2e453e2Thomas G. Lane  jpeg_saved_marker_ptr marker_list; /* Head of list of saved markers */
6305ead57a34a398aa798f35bd7a6abad19b2e453e2Thomas G. Lane
63136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* Remaining fields are known throughout decompressor, but generally
63236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * should not be touched by a surrounding application.
63336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   */
63436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
63536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /*
63636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * These fields are computed during decompression startup
63736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   */
638b775351012af176720429ac21d11682a0b75b4b7DRC  int max_h_samp_factor;        /* largest h_samp_factor */
639b775351012af176720429ac21d11682a0b75b4b7DRC  int max_v_samp_factor;        /* largest v_samp_factor */
64036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
64136a6eec93250e390d1028b3372078810b4428eafDRC#if JPEG_LIB_VERSION >= 70
642b775351012af176720429ac21d11682a0b75b4b7DRC  int min_DCT_h_scaled_size;    /* smallest DCT_h_scaled_size of any component */
643b775351012af176720429ac21d11682a0b75b4b7DRC  int min_DCT_v_scaled_size;    /* smallest DCT_v_scaled_size of any component */
64436a6eec93250e390d1028b3372078810b4428eafDRC#else
645b775351012af176720429ac21d11682a0b75b4b7DRC  int min_DCT_scaled_size;      /* smallest DCT_scaled_size of any component */
64636a6eec93250e390d1028b3372078810b4428eafDRC#endif
64736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
648b775351012af176720429ac21d11682a0b75b4b7DRC  JDIMENSION total_iMCU_rows;   /* # of iMCU rows in image */
649bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane  /* The coefficient controller's input and output progress is measured in
650bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane   * units of "iMCU" (interleaved MCU) rows.  These are the same as MCU rows
651bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane   * in fully interleaved JPEG scans, but are used whether the scan is
652bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane   * interleaved or not.  We define an iMCU row as v_samp_factor DCT block
653bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane   * rows of each component.  Therefore, the IDCT output contains
65436a6eec93250e390d1028b3372078810b4428eafDRC   * v_samp_factor*DCT_[v_]scaled_size sample rows of a component per iMCU row.
65536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   */
65636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
65736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  JSAMPLE * sample_range_limit; /* table for fast range-limiting */
65836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
65936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /*
66036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * These fields are valid during any one scan.
66136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * They describe the components and MCUs actually appearing in the scan.
662bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane   * Note that the decompressor output side must not use these fields.
66336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   */
664b775351012af176720429ac21d11682a0b75b4b7DRC  int comps_in_scan;            /* # of JPEG components in this scan */
66536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
66636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* *cur_comp_info[i] describes component that appears i'th in SOS */
66736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
668b775351012af176720429ac21d11682a0b75b4b7DRC  JDIMENSION MCUs_per_row;      /* # of MCUs across the image */
669b775351012af176720429ac21d11682a0b75b4b7DRC  JDIMENSION MCU_rows_in_scan;  /* # of MCU rows in the image */
67036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
671b775351012af176720429ac21d11682a0b75b4b7DRC  int blocks_in_MCU;            /* # of DCT blocks per MCU */
672bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane  int MCU_membership[D_MAX_BLOCKS_IN_MCU];
67336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* MCU_membership[i] is index in cur_comp_info of component owning */
67436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* i'th block in an MCU */
67536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
676b775351012af176720429ac21d11682a0b75b4b7DRC  int Ss, Se, Ah, Al;           /* progressive JPEG parameters for scan */
677bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane
67836a6eec93250e390d1028b3372078810b4428eafDRC#if JPEG_LIB_VERSION >= 80
679989630f70cf1af69ebfefca8910d1647bf189712Guido Vollbeding  /* These fields are derived from Se of first SOS marker.
680989630f70cf1af69ebfefca8910d1647bf189712Guido Vollbeding   */
681b775351012af176720429ac21d11682a0b75b4b7DRC  int block_size;               /* the basic DCT block size: 1..16 */
682989630f70cf1af69ebfefca8910d1647bf189712Guido Vollbeding  const int * natural_order; /* natural-order position array for entropy decode */
683b775351012af176720429ac21d11682a0b75b4b7DRC  int lim_Se;                   /* min( Se, DCTSIZE2-1 ) for entropy decode */
68436a6eec93250e390d1028b3372078810b4428eafDRC#endif
685989630f70cf1af69ebfefca8910d1647bf189712Guido Vollbeding
68636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* This field is shared between entropy decoder and marker parser.
68736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * It is either zero or the code of a JPEG marker that has been
68836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * read from the data source, but has not yet been processed.
68936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   */
69036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  int unread_marker;
69136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
69236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /*
69336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * Links to decompression subobjects (methods, private variables of modules)
69436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   */
69536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  struct jpeg_decomp_master * master;
69636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  struct jpeg_d_main_controller * main;
69736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  struct jpeg_d_coef_controller * coef;
69836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  struct jpeg_d_post_controller * post;
699bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane  struct jpeg_input_controller * inputctl;
70036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  struct jpeg_marker_reader * marker;
70136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  struct jpeg_entropy_decoder * entropy;
70236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  struct jpeg_inverse_dct * idct;
70336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  struct jpeg_upsampler * upsample;
70436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  struct jpeg_color_deconverter * cconvert;
70536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  struct jpeg_color_quantizer * cquantize;
70636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane};
70736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
70836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
70936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* "Object" declarations for JPEG modules that may be supplied or called
71036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * directly by the surrounding application.
71136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * As with all objects in the JPEG library, these structs only define the
71236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * publicly visible methods and state variables of a module.  Additional
71336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * private fields may exist after the public ones.
71436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane */
71536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
71636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
71736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Error handler object */
71836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
71936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jpeg_error_mgr {
72036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* Error exit handler: does not return to caller */
721bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*error_exit) (j_common_ptr cinfo);
72236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* Conditionally emit a trace or warning message */
723bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*emit_message) (j_common_ptr cinfo, int msg_level);
72436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* Routine that actually outputs a trace or error message */
725bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*output_message) (j_common_ptr cinfo);
72636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* Format a message string for the most recent JPEG error or message */
727bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*format_message) (j_common_ptr cinfo, char * buffer);
728b775351012af176720429ac21d11682a0b75b4b7DRC#define JMSG_LENGTH_MAX  200    /* recommended size of format_message buffer */
72936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* Reset error state variables at start of a new image */
730bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*reset_error_mgr) (j_common_ptr cinfo);
731b775351012af176720429ac21d11682a0b75b4b7DRC
73236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* The message ID code and any parameters are saved here.
73336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * A message can have one string parameter or up to 8 int parameters.
73436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   */
73536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  int msg_code;
73636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#define JMSG_STR_PARM_MAX  80
73736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  union {
73836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane    int i[8];
73936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane    char s[JMSG_STR_PARM_MAX];
74036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  } msg_parm;
741b775351012af176720429ac21d11682a0b75b4b7DRC
74236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* Standard state variables for error facility */
743b775351012af176720429ac21d11682a0b75b4b7DRC
744b775351012af176720429ac21d11682a0b75b4b7DRC  int trace_level;              /* max msg_level that will be displayed */
745b775351012af176720429ac21d11682a0b75b4b7DRC
74636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* For recoverable corrupt-data errors, we emit a warning message,
74736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * but keep going unless emit_message chooses to abort.  emit_message
74836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * should count warnings in num_warnings.  The surrounding application
74936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * can check for bad data by seeing if num_warnings is nonzero at the
75036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * end of processing.
75136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   */
752b775351012af176720429ac21d11682a0b75b4b7DRC  long num_warnings;            /* number of corrupt-data warnings */
75336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
75436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* These fields point to the table(s) of error message strings.
75536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * An application can change the table pointer to switch to a different
75636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * message list (typically, to change the language in which errors are
75736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * reported).  Some applications may wish to add additional error codes
75836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * that will be handled by the JPEG library error mechanism; the second
75936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * table pointer is used for this purpose.
76036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   *
76136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * First table includes all errors generated by JPEG library itself.
76236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * Error code 0 is reserved for a "no such error string" message.
76336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   */
76436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  const char * const * jpeg_message_table; /* Library errors */
76536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  int last_jpeg_message;    /* Table contains strings 0..last_jpeg_message */
76636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* Second table can be added by application (see cjpeg/djpeg for example).
76736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * It contains strings numbered first_addon_message..last_addon_message.
76836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   */
76936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  const char * const * addon_message_table; /* Non-library errors */
770b775351012af176720429ac21d11682a0b75b4b7DRC  int first_addon_message;      /* code for first string in addon table */
771b775351012af176720429ac21d11682a0b75b4b7DRC  int last_addon_message;       /* code for last string in addon table */
77236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane};
77336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
77436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
77536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Progress monitor object */
77636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
77736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jpeg_progress_mgr {
778bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*progress_monitor) (j_common_ptr cinfo);
77936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
780b775351012af176720429ac21d11682a0b75b4b7DRC  long pass_counter;            /* work units completed in this pass */
781b775351012af176720429ac21d11682a0b75b4b7DRC  long pass_limit;              /* total number of work units in this pass */
782b775351012af176720429ac21d11682a0b75b4b7DRC  int completed_passes;         /* passes completed so far */
783b775351012af176720429ac21d11682a0b75b4b7DRC  int total_passes;             /* total number of passes expected */
78436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane};
78536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
78636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
78736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Data destination object for compression */
78836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
78936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jpeg_destination_mgr {
790b775351012af176720429ac21d11682a0b75b4b7DRC  JOCTET * next_output_byte;    /* => next byte to write in buffer */
791b775351012af176720429ac21d11682a0b75b4b7DRC  size_t free_in_buffer;        /* # of byte spaces remaining in buffer */
79236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
793bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*init_destination) (j_compress_ptr cinfo);
794bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  boolean (*empty_output_buffer) (j_compress_ptr cinfo);
795bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*term_destination) (j_compress_ptr cinfo);
79636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane};
79736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
79836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
79936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Data source object for decompression */
80036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
80136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jpeg_source_mgr {
80236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  const JOCTET * next_input_byte; /* => next byte to read from buffer */
803b775351012af176720429ac21d11682a0b75b4b7DRC  size_t bytes_in_buffer;       /* # of bytes remaining in buffer */
80436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
805bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*init_source) (j_decompress_ptr cinfo);
806bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  boolean (*fill_input_buffer) (j_decompress_ptr cinfo);
807bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*skip_input_data) (j_decompress_ptr cinfo, long num_bytes);
808bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  boolean (*resync_to_restart) (j_decompress_ptr cinfo, int desired);
809bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*term_source) (j_decompress_ptr cinfo);
81036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane};
81136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
81236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
81336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Memory manager object.
81436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * Allocates "small" objects (a few K total), "large" objects (tens of K),
81536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * and "really big" objects (virtual arrays with backing store if needed).
81636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * The memory manager does not allow individual objects to be freed; rather,
81736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * each created object is assigned to a pool, and whole pools can be freed
81836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * at once.  This is faster and more convenient than remembering exactly what
81936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * to free, especially where malloc()/free() are not too speedy.
82036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * NB: alloc routines never return NULL.  They exit to error_exit if not
82136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * successful.
82236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane */
82336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
824b775351012af176720429ac21d11682a0b75b4b7DRC#define JPOOL_PERMANENT 0       /* lasts until master record is destroyed */
825b775351012af176720429ac21d11682a0b75b4b7DRC#define JPOOL_IMAGE     1       /* lasts until done with image/datastream */
826b775351012af176720429ac21d11682a0b75b4b7DRC#define JPOOL_NUMPOOLS  2
82736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
82836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanetypedef struct jvirt_sarray_control * jvirt_sarray_ptr;
82936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanetypedef struct jvirt_barray_control * jvirt_barray_ptr;
83036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
83136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
83236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jpeg_memory_mgr {
83336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* Method pointers */
834bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void * (*alloc_small) (j_common_ptr cinfo, int pool_id, size_t sizeofobject);
8355033f3e19a31e8ad40c1a79700365aefe5664494DRC  void * (*alloc_large) (j_common_ptr cinfo, int pool_id,
8365033f3e19a31e8ad40c1a79700365aefe5664494DRC                         size_t sizeofobject);
837bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  JSAMPARRAY (*alloc_sarray) (j_common_ptr cinfo, int pool_id,
838bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                              JDIMENSION samplesperrow, JDIMENSION numrows);
839bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  JBLOCKARRAY (*alloc_barray) (j_common_ptr cinfo, int pool_id,
840bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                               JDIMENSION blocksperrow, JDIMENSION numrows);
841bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  jvirt_sarray_ptr (*request_virt_sarray) (j_common_ptr cinfo, int pool_id,
842bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                                           boolean pre_zero,
843bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                                           JDIMENSION samplesperrow,
844bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                                           JDIMENSION numrows,
845bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                                           JDIMENSION maxaccess);
846bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  jvirt_barray_ptr (*request_virt_barray) (j_common_ptr cinfo, int pool_id,
847bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                                           boolean pre_zero,
848bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                                           JDIMENSION blocksperrow,
849bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                                           JDIMENSION numrows,
850bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                                           JDIMENSION maxaccess);
851bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*realize_virt_arrays) (j_common_ptr cinfo);
852bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  JSAMPARRAY (*access_virt_sarray) (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
853bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                                    JDIMENSION start_row, JDIMENSION num_rows,
854bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                                    boolean writable);
855bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  JBLOCKARRAY (*access_virt_barray) (j_common_ptr cinfo, jvirt_barray_ptr ptr,
856bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                                     JDIMENSION start_row, JDIMENSION num_rows,
857bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                                     boolean writable);
858bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*free_pool) (j_common_ptr cinfo, int pool_id);
859bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC  void (*self_destruct) (j_common_ptr cinfo);
86036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
86136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  /* Limit on memory allocation for this JPEG object.  (Note that this is
86236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * merely advisory, not a guaranteed maximum; it only affects the space
86336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * used for virtual-array buffers.)  May be changed by outer application
86436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   * after creating the JPEG object.
86536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane   */
86636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane  long max_memory_to_use;
8675ead57a34a398aa798f35bd7a6abad19b2e453e2Thomas G. Lane
8685ead57a34a398aa798f35bd7a6abad19b2e453e2Thomas G. Lane  /* Maximum allocation request accepted by alloc_large. */
8695ead57a34a398aa798f35bd7a6abad19b2e453e2Thomas G. Lane  long max_alloc_chunk;
87036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane};
87136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
87236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
87336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Routine signature for application-supplied marker processing methods.
87436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * Need not pass marker code since it is stored in cinfo->unread_marker.
87536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane */
876bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCtypedef boolean (*jpeg_marker_parser_method) (j_decompress_ptr cinfo);
87736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
87836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
879e2dd3e3e5cb479f8596325e72f0595a31bf79921DRC/* Originally, this macro was used as a way of defining function prototypes
880e2dd3e3e5cb479f8596325e72f0595a31bf79921DRC * for both modern compilers as well as older compilers that did not support
8812a6b8316fce86aa05c00bf44a29a28d2e9aec99cDRC * prototype parameters.  libjpeg-turbo has never supported these older,
8822a6b8316fce86aa05c00bf44a29a28d2e9aec99cDRC * non-ANSI compilers, but the macro is still included because there is some
8832a6b8316fce86aa05c00bf44a29a28d2e9aec99cDRC * software out there that uses it.
884e2dd3e3e5cb479f8596325e72f0595a31bf79921DRC */
885e2dd3e3e5cb479f8596325e72f0595a31bf79921DRC
886e2dd3e3e5cb479f8596325e72f0595a31bf79921DRC#define JPP(arglist)    arglist
887e2dd3e3e5cb479f8596325e72f0595a31bf79921DRC
888e2dd3e3e5cb479f8596325e72f0595a31bf79921DRC
88936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Default error-management setup */
890bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(struct jpeg_error_mgr *) jpeg_std_error (struct jpeg_error_mgr * err);
891489583f5165e05d37302e8eeec58104ea0109127Thomas G. Lane
892489583f5165e05d37302e8eeec58104ea0109127Thomas G. Lane/* Initialization of JPEG compression objects.
893489583f5165e05d37302e8eeec58104ea0109127Thomas G. Lane * jpeg_create_compress() and jpeg_create_decompress() are the exported
894489583f5165e05d37302e8eeec58104ea0109127Thomas G. Lane * names that applications should call.  These expand to calls on
895489583f5165e05d37302e8eeec58104ea0109127Thomas G. Lane * jpeg_CreateCompress and jpeg_CreateDecompress with additional information
896489583f5165e05d37302e8eeec58104ea0109127Thomas G. Lane * passed for version mismatch checking.
897489583f5165e05d37302e8eeec58104ea0109127Thomas G. Lane * NB: you must set up the error-manager BEFORE calling jpeg_create_xxx.
898489583f5165e05d37302e8eeec58104ea0109127Thomas G. Lane */
899489583f5165e05d37302e8eeec58104ea0109127Thomas G. Lane#define jpeg_create_compress(cinfo) \
900489583f5165e05d37302e8eeec58104ea0109127Thomas G. Lane    jpeg_CreateCompress((cinfo), JPEG_LIB_VERSION, \
901b775351012af176720429ac21d11682a0b75b4b7DRC                        (size_t) sizeof(struct jpeg_compress_struct))
902489583f5165e05d37302e8eeec58104ea0109127Thomas G. Lane#define jpeg_create_decompress(cinfo) \
903489583f5165e05d37302e8eeec58104ea0109127Thomas G. Lane    jpeg_CreateDecompress((cinfo), JPEG_LIB_VERSION, \
904b775351012af176720429ac21d11682a0b75b4b7DRC                          (size_t) sizeof(struct jpeg_decompress_struct))
905bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jpeg_CreateCompress (j_compress_ptr cinfo, int version,
906bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                                  size_t structsize);
907bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jpeg_CreateDecompress (j_decompress_ptr cinfo, int version,
908bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                                    size_t structsize);
909489583f5165e05d37302e8eeec58104ea0109127Thomas G. Lane/* Destruction of JPEG compression objects */
910bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jpeg_destroy_compress (j_compress_ptr cinfo);
911bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jpeg_destroy_decompress (j_decompress_ptr cinfo);
91236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
91336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Standard data source and destination managers: stdio streams. */
91436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Caller is responsible for opening the file before and closing after. */
915bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jpeg_stdio_dest (j_compress_ptr cinfo, FILE * outfile);
916bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jpeg_stdio_src (j_decompress_ptr cinfo, FILE * infile);
91736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
918ab70623eb29e09e67222be5b9e1ea320fe5aa0e9DRC#if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
919989630f70cf1af69ebfefca8910d1647bf189712Guido Vollbeding/* Data source and destination managers: memory buffers. */
920bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jpeg_mem_dest (j_compress_ptr cinfo, unsigned char ** outbuffer,
921bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                            unsigned long * outsize);
922bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jpeg_mem_src (j_decompress_ptr cinfo, unsigned char * inbuffer,
923bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                           unsigned long insize);
92436a6eec93250e390d1028b3372078810b4428eafDRC#endif
925989630f70cf1af69ebfefca8910d1647bf189712Guido Vollbeding
92636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Default parameter setup for compression */
927bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jpeg_set_defaults (j_compress_ptr cinfo);
92836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Compression parameter setup aids */
929bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jpeg_set_colorspace (j_compress_ptr cinfo,
930bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                                  J_COLOR_SPACE colorspace);
931bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jpeg_default_colorspace (j_compress_ptr cinfo);
932bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jpeg_set_quality (j_compress_ptr cinfo, int quality,
933bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                               boolean force_baseline);
934bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor,
935bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                                      boolean force_baseline);
93636a6eec93250e390d1028b3372078810b4428eafDRC#if JPEG_LIB_VERSION >= 70
937bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jpeg_default_qtables (j_compress_ptr cinfo,
938bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                                   boolean force_baseline);
93936a6eec93250e390d1028b3372078810b4428eafDRC#endif
940bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl,
941bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                                   const unsigned int *basic_table,
942bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                                   int scale_factor, boolean force_baseline);
943bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(int) jpeg_quality_scaling (int quality);
944bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jpeg_simple_progression (j_compress_ptr cinfo);
945bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress);
946bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(JQUANT_TBL *) jpeg_alloc_quant_table (j_common_ptr cinfo);
947bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(JHUFF_TBL *) jpeg_alloc_huff_table (j_common_ptr cinfo);
94836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
94936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Main entry points for compression */
950bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jpeg_start_compress (j_compress_ptr cinfo,
951bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                                  boolean write_all_tables);
952bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(JDIMENSION) jpeg_write_scanlines (j_compress_ptr cinfo,
953bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                                         JSAMPARRAY scanlines,
954bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                                         JDIMENSION num_lines);
955bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jpeg_finish_compress (j_compress_ptr cinfo);
95636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
95736a6eec93250e390d1028b3372078810b4428eafDRC#if JPEG_LIB_VERSION >= 70
9585996a25e2f50d20d6a8f09830724035b49c3927bGuido Vollbeding/* Precalculate JPEG dimensions for current compression parameters. */
959bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jpeg_calc_jpeg_dimensions (j_compress_ptr cinfo);
96036a6eec93250e390d1028b3372078810b4428eafDRC#endif
9615996a25e2f50d20d6a8f09830724035b49c3927bGuido Vollbeding
96236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Replaces jpeg_write_scanlines when writing raw downsampled data. */
963bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(JDIMENSION) jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data,
964bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                                        JDIMENSION num_lines);
96536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
9665996a25e2f50d20d6a8f09830724035b49c3927bGuido Vollbeding/* Write a special marker.  See libjpeg.txt concerning safe usage. */
967bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jpeg_write_marker (j_compress_ptr cinfo, int marker,
968bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                                const JOCTET * dataptr, unsigned int datalen);
9695ead57a34a398aa798f35bd7a6abad19b2e453e2Thomas G. Lane/* Same, but piecemeal. */
970bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jpeg_write_m_header (j_compress_ptr cinfo, int marker,
971bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                                  unsigned int datalen);
972bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jpeg_write_m_byte (j_compress_ptr cinfo, int val);
97336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
97436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Alternate compression function: just write an abbreviated table file */
975bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jpeg_write_tables (j_compress_ptr cinfo);
97636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
97736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Decompression startup: read start of JPEG datastream to see what's there */
978bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(int) jpeg_read_header (j_decompress_ptr cinfo, boolean require_image);
97936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Return value is one of: */
980b775351012af176720429ac21d11682a0b75b4b7DRC#define JPEG_SUSPENDED          0 /* Suspended due to lack of input data */
981b775351012af176720429ac21d11682a0b75b4b7DRC#define JPEG_HEADER_OK          1 /* Found valid image datastream */
982b775351012af176720429ac21d11682a0b75b4b7DRC#define JPEG_HEADER_TABLES_ONLY 2 /* Found valid table-specs-only datastream */
98336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* If you pass require_image = TRUE (normal case), you need not check for
98436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * a TABLES_ONLY return code; an abbreviated file will cause an error exit.
98536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * JPEG_SUSPENDED is only possible if you use a data source module that can
98636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * give a suspension return (the stdio source module doesn't).
98736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane */
98836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
98936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Main entry points for decompression */
990bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(boolean) jpeg_start_decompress (j_decompress_ptr cinfo);
991bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(JDIMENSION) jpeg_read_scanlines (j_decompress_ptr cinfo,
992bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                                        JSAMPARRAY scanlines,
993bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                                        JDIMENSION max_lines);
994ac30a1bf12751bd82e56158eb9456a28d9c086f3DRCEXTERN(JDIMENSION) jpeg_skip_scanlines (j_decompress_ptr cinfo,
995ac30a1bf12751bd82e56158eb9456a28d9c086f3DRC                                        JDIMENSION num_lines);
9960ef076fb7b326dc201b4ab3bd30fefd4e35ad1c4DRCEXTERN(void) jpeg_crop_scanline (j_decompress_ptr cinfo, JDIMENSION *xoffset,
9970ef076fb7b326dc201b4ab3bd30fefd4e35ad1c4DRC                                 JDIMENSION *width);
998bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(boolean) jpeg_finish_decompress (j_decompress_ptr cinfo);
99936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
100036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Replaces jpeg_read_scanlines when reading raw downsampled data. */
1001bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(JDIMENSION) jpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data,
1002bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                                       JDIMENSION max_lines);
100336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
1004bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane/* Additional entry points for buffered-image mode. */
1005bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(boolean) jpeg_has_multiple_scans (j_decompress_ptr cinfo);
1006bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(boolean) jpeg_start_output (j_decompress_ptr cinfo, int scan_number);
1007bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(boolean) jpeg_finish_output (j_decompress_ptr cinfo);
1008bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(boolean) jpeg_input_complete (j_decompress_ptr cinfo);
1009bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jpeg_new_colormap (j_decompress_ptr cinfo);
1010bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(int) jpeg_consume_input (j_decompress_ptr cinfo);
1011bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane/* Return value is one of: */
1012b775351012af176720429ac21d11682a0b75b4b7DRC/* #define JPEG_SUSPENDED       0    Suspended due to lack of input data */
1013b775351012af176720429ac21d11682a0b75b4b7DRC#define JPEG_REACHED_SOS        1 /* Reached start of new scan */
1014b775351012af176720429ac21d11682a0b75b4b7DRC#define JPEG_REACHED_EOI        2 /* Reached end of image */
1015b775351012af176720429ac21d11682a0b75b4b7DRC#define JPEG_ROW_COMPLETED      3 /* Completed one iMCU row */
1016b775351012af176720429ac21d11682a0b75b4b7DRC#define JPEG_SCAN_COMPLETED     4 /* Completed last iMCU row of a scan */
1017bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane
101836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Precalculate output dimensions for current decompression parameters. */
101936a6eec93250e390d1028b3372078810b4428eafDRC#if JPEG_LIB_VERSION >= 80
1020bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jpeg_core_output_dimensions (j_decompress_ptr cinfo);
102136a6eec93250e390d1028b3372078810b4428eafDRC#endif
1022bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jpeg_calc_output_dimensions (j_decompress_ptr cinfo);
102336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
10245ead57a34a398aa798f35bd7a6abad19b2e453e2Thomas G. Lane/* Control saving of COM and APPn markers into marker_list. */
1025bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jpeg_save_markers (j_decompress_ptr cinfo, int marker_code,
1026bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                                unsigned int length_limit);
10275ead57a34a398aa798f35bd7a6abad19b2e453e2Thomas G. Lane
102836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Install a special processing method for COM or APPn markers. */
1029bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jpeg_set_marker_processor (j_decompress_ptr cinfo,
1030bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                                        int marker_code,
1031bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                                        jpeg_marker_parser_method routine);
103236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
1033bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane/* Read or write raw DCT coefficients --- useful for lossless transcoding. */
1034bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(jvirt_barray_ptr *) jpeg_read_coefficients (j_decompress_ptr cinfo);
1035bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jpeg_write_coefficients (j_compress_ptr cinfo,
1036bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                                      jvirt_barray_ptr * coef_arrays);
1037bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
1038bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRC                                            j_compress_ptr dstinfo);
1039bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lane
104036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* If you choose to abort compression or decompression before completing
104136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * jpeg_finish_(de)compress, then you need to clean up to release memory,
104236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * temporary files, etc.  You can just call jpeg_destroy_(de)compress
104336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * if you're done with the JPEG object, but if you want to clean it up and
104436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * reuse it, call this:
104536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane */
1046bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jpeg_abort_compress (j_compress_ptr cinfo);
1047bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jpeg_abort_decompress (j_decompress_ptr cinfo);
104836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
104936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Generic versions of jpeg_abort and jpeg_destroy that work on either
105036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * flavor of JPEG object.  These may be more convenient in some places.
105136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane */
1052bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jpeg_abort (j_common_ptr cinfo);
1053bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(void) jpeg_destroy (j_common_ptr cinfo);
105436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
105536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* Default restart-marker-resync procedure for use by data source modules */
1056bc56b754e1a6a1db9ccadf64d6dda8a74140e1a3DRCEXTERN(boolean) jpeg_resync_to_restart (j_decompress_ptr cinfo, int desired);
105736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
105836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
105936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* These marker codes are exported since applications and data source modules
106036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * are likely to want to use them.
106136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane */
106236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
1063b775351012af176720429ac21d11682a0b75b4b7DRC#define JPEG_RST0       0xD0    /* RST0 marker code */
1064b775351012af176720429ac21d11682a0b75b4b7DRC#define JPEG_EOI        0xD9    /* EOI marker code */
1065b775351012af176720429ac21d11682a0b75b4b7DRC#define JPEG_APP0       0xE0    /* APP0 marker code */
1066b775351012af176720429ac21d11682a0b75b4b7DRC#define JPEG_COM        0xFE    /* COM marker code */
106736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
106836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
106936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/* If we have a brain-damaged compiler that emits warnings (or worse, errors)
107036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * for structure definitions that are never filled in, keep it quiet by
107136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * supplying dummy definitions for the various substructures.
107236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane */
107336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
107436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#ifdef INCOMPLETE_TYPES_BROKEN
1075b775351012af176720429ac21d11682a0b75b4b7DRC#ifndef JPEG_INTERNALS          /* will be defined in jpegint.h */
107636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jvirt_sarray_control { long dummy; };
107736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jvirt_barray_control { long dummy; };
107836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jpeg_comp_master { long dummy; };
107936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jpeg_c_main_controller { long dummy; };
108036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jpeg_c_prep_controller { long dummy; };
108136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jpeg_c_coef_controller { long dummy; };
108236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jpeg_marker_writer { long dummy; };
108336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jpeg_color_converter { long dummy; };
108436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jpeg_downsampler { long dummy; };
108536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jpeg_forward_dct { long dummy; };
108636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jpeg_entropy_encoder { long dummy; };
108736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jpeg_decomp_master { long dummy; };
108836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jpeg_d_main_controller { long dummy; };
108936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jpeg_d_coef_controller { long dummy; };
109036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jpeg_d_post_controller { long dummy; };
1091bc79e0680a45d1ca330d690dae0340c8e17ab5e3Thomas G. Lanestruct jpeg_input_controller { long dummy; };
109236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jpeg_marker_reader { long dummy; };
109336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jpeg_entropy_decoder { long dummy; };
109436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jpeg_inverse_dct { long dummy; };
109536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jpeg_upsampler { long dummy; };
109636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jpeg_color_deconverter { long dummy; };
109736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lanestruct jpeg_color_quantizer { long dummy; };
109836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#endif /* JPEG_INTERNALS */
109936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#endif /* INCOMPLETE_TYPES_BROKEN */
110036a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
110136a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
110236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane/*
110336a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * The JPEG library modules define JPEG_INTERNALS before including this file.
110436a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * The internal structure declarations are read only when that is true.
110536a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * Applications using the library should not include jpegint.h, but may wish
110636a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane * to include jerror.h.
110736a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane */
110836a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane
110936a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#ifdef JPEG_INTERNALS
1110b775351012af176720429ac21d11682a0b75b4b7DRC#include "jpegint.h"            /* fetch private declarations */
1111b775351012af176720429ac21d11682a0b75b4b7DRC#include "jerror.h"             /* fetch error codes too */
111236a4ccccd33f5cc9df62949554af87129ced7f84Thomas G. Lane#endif
11139ba2f5ed3649fb6de83d3c16e4dba1443aaca983Thomas G. Lane
1114ca3cebbaef953bb1290e19ca5c9096981a106b90DRC#ifdef __cplusplus
11155996a25e2f50d20d6a8f09830724035b49c3927bGuido Vollbeding#ifndef DONT_USE_EXTERN_C
1116ca3cebbaef953bb1290e19ca5c9096981a106b90DRC}
1117ca3cebbaef953bb1290e19ca5c9096981a106b90DRC#endif
11185996a25e2f50d20d6a8f09830724035b49c3927bGuido Vollbeding#endif
1119ca3cebbaef953bb1290e19ca5c9096981a106b90DRC
11209ba2f5ed3649fb6de83d3c16e4dba1443aaca983Thomas G. Lane#endif /* JPEGLIB_H */
1121