📄 jpegdata.h
字号:
/*
* jpegdata.h
*
* Copyright (C) 1991, 1992, Thomas G. Lane.
* This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file.
*
* This file defines shared data structures for the various JPEG modules.
*/
/*
* You might need to change some of the following declarations if you are
* using the JPEG software within a surrounding application program
* or porting it to an unusual system.
*/
/* If the source or destination of image data is not to be stdio streams,
* these types may need work. You can replace them with some kind of
* pointer or indicator that is useful to you, or just ignore 'em.
* Note that the user interface and the various jrdxxx/jwrxxx modules
* will also need work for non-stdio input/output.
*/
typedef int FILE;
typedef FILE * JFILEREF; /* source or dest of JPEG-compressed data */
typedef FILE * IFILEREF; /* source or dest of non-JPEG image data */
/* These defines are used in all function definitions and extern declarations.
* You could modify them if you need to change function linkage conventions,
* as is shown below for use with C++. Another application would be to make
* all functions global for use with code profilers that require it.
* NOTE: the C++ test does the right thing if you are reading this include
* file in a C++ application to link to JPEG code that's been compiled with a
* regular C compiler. I'm not sure it works if you try to compile the JPEG
* code with C++.
*/
#define METHODDEF static /* a function called through method pointers */
#define LOCAL static /* a function used only in its module */
#define GLOBAL /* a function referenced thru EXTERNs */
#ifdef __cplusplus
#define EXTERN extern "C" /* a reference to a GLOBAL function */
#else
#define EXTERN extern /* a reference to a GLOBAL function */
#endif
/* Here is the pseudo-keyword for declaring pointers that must be "far"
* on 80x86 machines. Most of the specialized coding for 80x86 is handled
* by just saying "FAR *" where such a pointer is needed. In a few places
* explicit coding is needed; see uses of the NEED_FAR_POINTERS symbol.
*/
#ifdef NEED_FAR_POINTERS
#define FAR far
#else
#define FAR
#endif
/* The remaining declarations are not system-dependent, we hope. */
/*
* NOTE: if you have an ancient, strict-K&R C compiler, it may choke on the
* similarly-named fields in Compress_info_struct and Decompress_info_struct.
* If this happens, you can get around it by rearranging the two structs so
* that the similarly-named fields appear first and in the same order in
* each struct. Since such compilers are now pretty rare, we haven't done
* this in the portable code, preferring to maintain a logical ordering.
*/
/* This macro is used to declare a "method", that is, a function pointer. */
/* We want to supply prototype parameters if the compiler can cope. */
/* Note that the arglist parameter must be parenthesized! */
#ifdef PROTO
#define METHOD(type,methodname,arglist) type (*methodname) arglist
#else
#define METHOD(type,methodname,arglist) type (*methodname) ()
#endif
/* Forward references to lists of method pointers */
typedef struct External_methods_struct * external_methods_ptr;
typedef struct Compress_methods_struct * compress_methods_ptr;
typedef struct Decompress_methods_struct * decompress_methods_ptr;
/* Data structures for images containing either samples or coefficients. */
/* Note that the topmost (leftmost) index is always color component. */
/* On 80x86 machines, the image arrays are too big for near pointers, */
/* but the pointer arrays can fit in near memory. */
typedef JSAMPLE FAR *JSAMPROW; /* ptr to one image row of pixel samples. */
typedef JSAMPROW *JSAMPARRAY; /* ptr to some rows (a 2-D sample array) */
typedef JSAMPARRAY *JSAMPIMAGE; /* a 3-D sample array: top index is color */
#define DCTSIZE 8 /* The basic DCT block is 8x8 samples */
#define DCTSIZE2 64 /* DCTSIZE squared; # of elements in a block */
typedef JCOEF JBLOCK[DCTSIZE2]; /* one block of coefficients */
typedef JBLOCK FAR *JBLOCKROW; /* pointer to one row of coefficient blocks */
typedef JBLOCKROW *JBLOCKARRAY; /* a 2-D array of coefficient blocks */
typedef JBLOCKARRAY *JBLOCKIMAGE; /* a 3-D array of coefficient blocks */
typedef JCOEF FAR *JCOEFPTR; /* useful in a couple of places */
/* The input and output data of the DCT transform subroutines are of
* the following type, which need not be the same as JCOEF.
* For example, on a machine with fast floating point, it might make sense
* to recode the DCT routines to use floating point; then DCTELEM would be
* 'float' or 'double'.
*/
typedef JCOEF DCTELEM;
typedef DCTELEM DCTBLOCK[DCTSIZE2];
/* Types for JPEG compression parameters and working tables. */
typedef enum { /* defines known color spaces */
CS_UNKNOWN, /* error/unspecified */
CS_GRAYSCALE, /* monochrome (only 1 component) */
CS_RGB, /* red/green/blue */
CS_YCbCr, /* Y/Cb/Cr (also known as YUV) */
CS_YIQ, /* Y/I/Q */
CS_CMYK /* C/M/Y/K */
} COLOR_SPACE;
typedef struct { /* Basic info about one component */
/* These values are fixed over the whole image */
/* For compression, they must be supplied by the user interface; */
/* for decompression, they are read from the SOF marker. */
short component_id; /* identifier for this component (0..255) */
short component_index; /* its index in SOF or cinfo->comp_info[] */
short h_samp_factor; /* horizontal sampling factor (1..4) */
short v_samp_factor; /* vertical sampling factor (1..4) */
short quant_tbl_no; /* quantization table selector (0..3) */
/* These values may vary between scans */
/* For compression, they must be supplied by the user interface; */
/* for decompression, they are read from the SOS marker. */
short dc_tbl_no; /* DC entropy table selector (0..3) */
short ac_tbl_no; /* AC entropy table selector (0..3) */
/* These values are computed during compression or decompression startup */
long true_comp_width; /* component's image width in samples */
long true_comp_height; /* component's image height in samples */
/* the above are the logical dimensions of the downsampled image */
/* These values are computed before starting a scan of the component */
short MCU_width; /* number of blocks per MCU, horizontally */
short MCU_height; /* number of blocks per MCU, vertically */
short MCU_blocks; /* MCU_width * MCU_height */
long downsampled_width; /* image width in samples, after expansion */
long downsampled_height; /* image height in samples, after expansion */
/* the above are the true_comp_xxx values rounded up to multiples of */
/* the MCU dimensions; these are the working dimensions of the array */
/* as it is passed through the DCT or IDCT step. NOTE: these values */
/* differ depending on whether the component is interleaved or not!! */
} jpeg_component_info;
/* DCT coefficient quantization tables.
* For 8-bit precision, 'INT16' should be good enough for quantization values;
* for more precision, we go for the full 16 bits. 'INT16' provides a useful
* speedup on many machines (multiplication & division of JCOEFs by
* quantization values is a significant chunk of the runtime).
* Note: the values in a QUANT_TBL are always given in zigzag order.
*/
#ifdef EIGHT_BIT_SAMPLES
typedef INT16 QUANT_VAL; /* element of a quantization table */
#else
typedef UINT16 QUANT_VAL; /* element of a quantization table */
#endif
typedef QUANT_VAL QUANT_TBL[DCTSIZE2]; /* A quantization table */
typedef QUANT_VAL * QUANT_TBL_PTR; /* pointer to same */
typedef struct { /* A Huffman coding table */
/* These two fields directly represent the contents of a JPEG DHT marker */
UINT8 bits[17]; /* bits[k] = # of symbols with codes of */
/* length k bits; bits[0] is unused */
UINT8 huffval[256]; /* The symbols, in order of incr code length */
/* This field is used only during compression. It's initialized FALSE when
* the table is created, and set TRUE when it's been output to the file.
*/
boolean sent_table; /* TRUE when table has been output */
/* The remaining fields are computed from the above to allow more efficient
* coding and decoding. These fields should be considered private to the
* Huffman compression & decompression modules.
*/
/* encoding tables: */
UINT16 ehufco[256]; /* code for each symbol */
char ehufsi[256]; /* length of code for each symbol */
/* decoding tables: (element [0] of each array is unused) */
UINT16 mincode[17]; /* smallest code of length k */
INT32 maxcode[18]; /* largest code of length k (-1 if none) */
/* (maxcode[17] is a sentinel to ensure huff_DECODE terminates) */
short valptr[17]; /* huffval[] index of 1st symbol of length k */
} HUFF_TBL;
#define NUM_QUANT_TBLS 4 /* quantization tables are numbered 0..3 */
#define NUM_HUFF_TBLS 4 /* Huffman tables are numbered 0..3 */
#define NUM_ARITH_TBLS 16 /* arith-coding tables are numbered 0..15 */
#define MAX_COMPS_IN_SCAN 4 /* JPEG limit on # of components in one scan */
#define MAX_SAMP_FACTOR 4 /* JPEG limit on sampling factors */
#define MAX_BLOCKS_IN_MCU 10 /* JPEG limit on # of blocks in an MCU */
/* Working data for compression */
struct Compress_info_struct {
/*
* All of these fields shall be established by the user interface before
* calling jpeg_compress, or by the input_init or c_ui_method_selection
* methods.
* Most parameters can be set to reasonable defaults by j_c_defaults.
* Note that the UI must supply the storage for the main methods struct,
* though it sets only a few of the methods there.
*/
compress_methods_ptr methods; /* Points to list of methods to use */
external_methods_ptr emethods; /* Points to list of methods to use */
IFILEREF input_file; /* tells input routines where to read image */
JFILEREF output_file; /* tells output routines where to write JPEG */
long image_width; /* input image width */
long image_height; /* input image height */
short input_components; /* # of color components in input image */
short data_precision; /* bits of precision in image data */
COLOR_SPACE in_color_space; /* colorspace of input file */
COLOR_SPACE jpeg_color_space; /* colorspace of JPEG file */
double input_gamma; /* image gamma of input file */
boolean write_JFIF_header; /* should a JFIF marker be written? */
/* These three values are not used by the JPEG code, only copied */
/* into the JFIF APP0 marker. density_unit can be 0 for unknown, */
/* 1 for dots/inch, or 2 for dots/cm. Note that the pixel aspect */
/* ratio is defined by X_density/Y_density even when density_unit=0. */
UINT8 density_unit; /* JFIF code for pixel size units */
UINT16 X_density; /* Horizontal pixel density */
UINT16 Y_density; /* Vertical pixel density */
short num_components; /* # of color components in JPEG image */
jpeg_component_info * comp_info;
/* comp_info[i] describes component that appears i'th in SOF */
QUANT_TBL_PTR quant_tbl_ptrs[NUM_QUANT_TBLS];
/* ptrs to coefficient quantization tables, or NULL if not defined */
HUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
HUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
/* ptrs to Huffman coding tables, or NULL if not defined */
UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arithmetic-coding tables */
UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arithmetic-coding tables */
UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arithmetic-coding tables */
boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
boolean interleave; /* TRUE=interleaved output, FALSE=not */
boolean optimize_coding; /* TRUE=optimize entropy encoding parms */
boolean CCIR601_sampling; /* TRUE=first samples are cosited */
int smoothing_factor; /* 1..100, or 0 for no input smoothing */
/* The restart interval can be specified in absolute MCUs by setting
* restart_interval, or in MCU rows by setting restart_in_rows
* (in which case the correct restart_interval will be figured
* for each scan).
*/
UINT16 restart_interval;/* MCUs per restart interval, or 0 for no restart */
int restart_in_rows; /* if > 0, MCU rows per restart interval */
/*
* These fields are computed during jpeg_compress startup
*/
short max_h_samp_factor; /* largest h_samp_factor */
short max_v_samp_factor; /* largest v_samp_factor */
/*
* These fields may be useful for progress monitoring
*/
int total_passes; /* number of passes expected */
int completed_passes; /* number of passes completed so far */
/*
* These fields are valid during any one scan
*/
short comps_in_scan; /* # of JPEG components output this time */
jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
/* *cur_comp_info[i] describes component that appears i'th in SOS */
long MCUs_per_row; /* # of MCUs across the image */
long MCU_rows_in_scan; /* # of MCU rows in the image */
short blocks_in_MCU; /* # of DCT blocks per MCU */
short MCU_membership[MAX_BLOCKS_IN_MCU];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -