media/libjpeg/jdct.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /*
michael@0 2 * jdct.h
michael@0 3 *
michael@0 4 * Copyright (C) 1994-1996, Thomas G. Lane.
michael@0 5 * This file is part of the Independent JPEG Group's software.
michael@0 6 * For conditions of distribution and use, see the accompanying README file.
michael@0 7 *
michael@0 8 * This include file contains common declarations for the forward and
michael@0 9 * inverse DCT modules. These declarations are private to the DCT managers
michael@0 10 * (jcdctmgr.c, jddctmgr.c) and the individual DCT algorithms.
michael@0 11 * The individual DCT algorithms are kept in separate files to ease
michael@0 12 * machine-dependent tuning (e.g., assembly coding).
michael@0 13 */
michael@0 14
michael@0 15
michael@0 16 /*
michael@0 17 * A forward DCT routine is given a pointer to a work area of type DCTELEM[];
michael@0 18 * the DCT is to be performed in-place in that buffer. Type DCTELEM is int
michael@0 19 * for 8-bit samples, INT32 for 12-bit samples. (NOTE: Floating-point DCT
michael@0 20 * implementations use an array of type FAST_FLOAT, instead.)
michael@0 21 * The DCT inputs are expected to be signed (range +-CENTERJSAMPLE).
michael@0 22 * The DCT outputs are returned scaled up by a factor of 8; they therefore
michael@0 23 * have a range of +-8K for 8-bit data, +-128K for 12-bit data. This
michael@0 24 * convention improves accuracy in integer implementations and saves some
michael@0 25 * work in floating-point ones.
michael@0 26 * Quantization of the output coefficients is done by jcdctmgr.c. This
michael@0 27 * step requires an unsigned type and also one with twice the bits.
michael@0 28 */
michael@0 29
michael@0 30 #if BITS_IN_JSAMPLE == 8
michael@0 31 #ifndef WITH_SIMD
michael@0 32 typedef int DCTELEM; /* 16 or 32 bits is fine */
michael@0 33 typedef unsigned int UDCTELEM;
michael@0 34 typedef unsigned long long UDCTELEM2;
michael@0 35 #else
michael@0 36 typedef short DCTELEM; /* prefer 16 bit with SIMD for parellelism */
michael@0 37 typedef unsigned short UDCTELEM;
michael@0 38 typedef unsigned int UDCTELEM2;
michael@0 39 #endif
michael@0 40 #else
michael@0 41 typedef INT32 DCTELEM; /* must have 32 bits */
michael@0 42 typedef UINT32 UDCTELEM;
michael@0 43 typedef unsigned long long UDCTELEM2;
michael@0 44 #endif
michael@0 45
michael@0 46
michael@0 47 /*
michael@0 48 * An inverse DCT routine is given a pointer to the input JBLOCK and a pointer
michael@0 49 * to an output sample array. The routine must dequantize the input data as
michael@0 50 * well as perform the IDCT; for dequantization, it uses the multiplier table
michael@0 51 * pointed to by compptr->dct_table. The output data is to be placed into the
michael@0 52 * sample array starting at a specified column. (Any row offset needed will
michael@0 53 * be applied to the array pointer before it is passed to the IDCT code.)
michael@0 54 * Note that the number of samples emitted by the IDCT routine is
michael@0 55 * DCT_scaled_size * DCT_scaled_size.
michael@0 56 */
michael@0 57
michael@0 58 /* typedef inverse_DCT_method_ptr is declared in jpegint.h */
michael@0 59
michael@0 60 /*
michael@0 61 * Each IDCT routine has its own ideas about the best dct_table element type.
michael@0 62 */
michael@0 63
michael@0 64 typedef MULTIPLIER ISLOW_MULT_TYPE; /* short or int, whichever is faster */
michael@0 65 #if BITS_IN_JSAMPLE == 8
michael@0 66 typedef MULTIPLIER IFAST_MULT_TYPE; /* 16 bits is OK, use short if faster */
michael@0 67 #define IFAST_SCALE_BITS 2 /* fractional bits in scale factors */
michael@0 68 #else
michael@0 69 typedef INT32 IFAST_MULT_TYPE; /* need 32 bits for scaled quantizers */
michael@0 70 #define IFAST_SCALE_BITS 13 /* fractional bits in scale factors */
michael@0 71 #endif
michael@0 72 typedef FAST_FLOAT FLOAT_MULT_TYPE; /* preferred floating type */
michael@0 73
michael@0 74
michael@0 75 /*
michael@0 76 * Each IDCT routine is responsible for range-limiting its results and
michael@0 77 * converting them to unsigned form (0..MAXJSAMPLE). The raw outputs could
michael@0 78 * be quite far out of range if the input data is corrupt, so a bulletproof
michael@0 79 * range-limiting step is required. We use a mask-and-table-lookup method
michael@0 80 * to do the combined operations quickly. See the comments with
michael@0 81 * prepare_range_limit_table (in jdmaster.c) for more info.
michael@0 82 */
michael@0 83
michael@0 84 #define IDCT_range_limit(cinfo) ((cinfo)->sample_range_limit + CENTERJSAMPLE)
michael@0 85
michael@0 86 #define RANGE_MASK (MAXJSAMPLE * 4 + 3) /* 2 bits wider than legal samples */
michael@0 87
michael@0 88
michael@0 89 /* Short forms of external names for systems with brain-damaged linkers. */
michael@0 90
michael@0 91 #ifdef NEED_SHORT_EXTERNAL_NAMES
michael@0 92 #define jpeg_fdct_islow jFDislow
michael@0 93 #define jpeg_fdct_ifast jFDifast
michael@0 94 #define jpeg_fdct_float jFDfloat
michael@0 95 #define jpeg_idct_islow jRDislow
michael@0 96 #define jpeg_idct_ifast jRDifast
michael@0 97 #define jpeg_idct_float jRDfloat
michael@0 98 #define jpeg_idct_7x7 jRD7x7
michael@0 99 #define jpeg_idct_6x6 jRD6x6
michael@0 100 #define jpeg_idct_5x5 jRD5x5
michael@0 101 #define jpeg_idct_4x4 jRD4x4
michael@0 102 #define jpeg_idct_3x3 jRD3x3
michael@0 103 #define jpeg_idct_2x2 jRD2x2
michael@0 104 #define jpeg_idct_1x1 jRD1x1
michael@0 105 #define jpeg_idct_9x9 jRD9x9
michael@0 106 #define jpeg_idct_10x10 jRD10x10
michael@0 107 #define jpeg_idct_11x11 jRD11x11
michael@0 108 #define jpeg_idct_12x12 jRD12x12
michael@0 109 #define jpeg_idct_13x13 jRD13x13
michael@0 110 #define jpeg_idct_14x14 jRD14x14
michael@0 111 #define jpeg_idct_15x15 jRD15x15
michael@0 112 #define jpeg_idct_16x16 jRD16x16
michael@0 113 #endif /* NEED_SHORT_EXTERNAL_NAMES */
michael@0 114
michael@0 115 /* Extern declarations for the forward and inverse DCT routines. */
michael@0 116
michael@0 117 EXTERN(void) jpeg_fdct_islow JPP((DCTELEM * data));
michael@0 118 EXTERN(void) jpeg_fdct_ifast JPP((DCTELEM * data));
michael@0 119 EXTERN(void) jpeg_fdct_float JPP((FAST_FLOAT * data));
michael@0 120
michael@0 121 EXTERN(void) jpeg_idct_islow
michael@0 122 JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
michael@0 123 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
michael@0 124 EXTERN(void) jpeg_idct_ifast
michael@0 125 JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
michael@0 126 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
michael@0 127 EXTERN(void) jpeg_idct_float
michael@0 128 JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
michael@0 129 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
michael@0 130 EXTERN(void) jpeg_idct_7x7
michael@0 131 JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
michael@0 132 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
michael@0 133 EXTERN(void) jpeg_idct_6x6
michael@0 134 JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
michael@0 135 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
michael@0 136 EXTERN(void) jpeg_idct_5x5
michael@0 137 JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
michael@0 138 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
michael@0 139 EXTERN(void) jpeg_idct_4x4
michael@0 140 JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
michael@0 141 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
michael@0 142 EXTERN(void) jpeg_idct_3x3
michael@0 143 JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
michael@0 144 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
michael@0 145 EXTERN(void) jpeg_idct_2x2
michael@0 146 JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
michael@0 147 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
michael@0 148 EXTERN(void) jpeg_idct_1x1
michael@0 149 JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
michael@0 150 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
michael@0 151 EXTERN(void) jpeg_idct_9x9
michael@0 152 JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
michael@0 153 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
michael@0 154 EXTERN(void) jpeg_idct_10x10
michael@0 155 JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
michael@0 156 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
michael@0 157 EXTERN(void) jpeg_idct_11x11
michael@0 158 JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
michael@0 159 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
michael@0 160 EXTERN(void) jpeg_idct_12x12
michael@0 161 JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
michael@0 162 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
michael@0 163 EXTERN(void) jpeg_idct_13x13
michael@0 164 JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
michael@0 165 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
michael@0 166 EXTERN(void) jpeg_idct_14x14
michael@0 167 JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
michael@0 168 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
michael@0 169 EXTERN(void) jpeg_idct_15x15
michael@0 170 JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
michael@0 171 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
michael@0 172 EXTERN(void) jpeg_idct_16x16
michael@0 173 JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
michael@0 174 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
michael@0 175
michael@0 176
michael@0 177 /*
michael@0 178 * Macros for handling fixed-point arithmetic; these are used by many
michael@0 179 * but not all of the DCT/IDCT modules.
michael@0 180 *
michael@0 181 * All values are expected to be of type INT32.
michael@0 182 * Fractional constants are scaled left by CONST_BITS bits.
michael@0 183 * CONST_BITS is defined within each module using these macros,
michael@0 184 * and may differ from one module to the next.
michael@0 185 */
michael@0 186
michael@0 187 #define ONE ((INT32) 1)
michael@0 188 #define CONST_SCALE (ONE << CONST_BITS)
michael@0 189
michael@0 190 /* Convert a positive real constant to an integer scaled by CONST_SCALE.
michael@0 191 * Caution: some C compilers fail to reduce "FIX(constant)" at compile time,
michael@0 192 * thus causing a lot of useless floating-point operations at run time.
michael@0 193 */
michael@0 194
michael@0 195 #define FIX(x) ((INT32) ((x) * CONST_SCALE + 0.5))
michael@0 196
michael@0 197 /* Descale and correctly round an INT32 value that's scaled by N bits.
michael@0 198 * We assume RIGHT_SHIFT rounds towards minus infinity, so adding
michael@0 199 * the fudge factor is correct for either sign of X.
michael@0 200 */
michael@0 201
michael@0 202 #define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n)
michael@0 203
michael@0 204 /* Multiply an INT32 variable by an INT32 constant to yield an INT32 result.
michael@0 205 * This macro is used only when the two inputs will actually be no more than
michael@0 206 * 16 bits wide, so that a 16x16->32 bit multiply can be used instead of a
michael@0 207 * full 32x32 multiply. This provides a useful speedup on many machines.
michael@0 208 * Unfortunately there is no way to specify a 16x16->32 multiply portably
michael@0 209 * in C, but some C compilers will do the right thing if you provide the
michael@0 210 * correct combination of casts.
michael@0 211 */
michael@0 212
michael@0 213 #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
michael@0 214 #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT16) (const)))
michael@0 215 #endif
michael@0 216 #ifdef SHORTxLCONST_32 /* known to work with Microsoft C 6.0 */
michael@0 217 #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT32) (const)))
michael@0 218 #endif
michael@0 219
michael@0 220 #ifndef MULTIPLY16C16 /* default definition */
michael@0 221 #define MULTIPLY16C16(var,const) ((var) * (const))
michael@0 222 #endif
michael@0 223
michael@0 224 /* Same except both inputs are variables. */
michael@0 225
michael@0 226 #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
michael@0 227 #define MULTIPLY16V16(var1,var2) (((INT16) (var1)) * ((INT16) (var2)))
michael@0 228 #endif
michael@0 229
michael@0 230 #ifndef MULTIPLY16V16 /* default definition */
michael@0 231 #define MULTIPLY16V16(var1,var2) ((var1) * (var2))
michael@0 232 #endif

mercurial