/*1* jdct.h2*3* This file was part of the Independent JPEG Group's software:4* Copyright (C) 1994-1996, Thomas G. Lane.5* libjpeg-turbo Modifications:6* Copyright (C) 2015, D. R. Commander.7* For conditions of distribution and use, see the accompanying README.ijg8* file.9*10* This include file contains common declarations for the forward and11* inverse DCT modules. These declarations are private to the DCT managers12* (jcdctmgr.c, jddctmgr.c) and the individual DCT algorithms.13* The individual DCT algorithms are kept in separate files to ease14* machine-dependent tuning (e.g., assembly coding).15*/161718/*19* A forward DCT routine is given a pointer to a work area of type DCTELEM[];20* the DCT is to be performed in-place in that buffer. Type DCTELEM is int21* for 8-bit samples, JLONG for 12-bit samples. (NOTE: Floating-point DCT22* implementations use an array of type FAST_FLOAT, instead.)23* The DCT inputs are expected to be signed (range +-CENTERJSAMPLE).24* The DCT outputs are returned scaled up by a factor of 8; they therefore25* have a range of +-8K for 8-bit data, +-128K for 12-bit data. This26* convention improves accuracy in integer implementations and saves some27* work in floating-point ones.28* Quantization of the output coefficients is done by jcdctmgr.c. This29* step requires an unsigned type and also one with twice the bits.30*/3132#if BITS_IN_JSAMPLE == 833#ifndef WITH_SIMD34typedef int DCTELEM; /* 16 or 32 bits is fine */35typedef unsigned int UDCTELEM;36typedef unsigned long long UDCTELEM2;37#else38typedef short DCTELEM; /* prefer 16 bit with SIMD for parellelism */39typedef unsigned short UDCTELEM;40typedef unsigned int UDCTELEM2;41#endif42#else43typedef JLONG DCTELEM; /* must have 32 bits */44typedef unsigned long long UDCTELEM2;45#endif464748/*49* An inverse DCT routine is given a pointer to the input JBLOCK and a pointer50* to an output sample array. The routine must dequantize the input data as51* well as perform the IDCT; for dequantization, it uses the multiplier table52* pointed to by compptr->dct_table. The output data is to be placed into the53* sample array starting at a specified column. (Any row offset needed will54* be applied to the array pointer before it is passed to the IDCT code.)55* Note that the number of samples emitted by the IDCT routine is56* DCT_scaled_size * DCT_scaled_size.57*/5859/* typedef inverse_DCT_method_ptr is declared in jpegint.h */6061/*62* Each IDCT routine has its own ideas about the best dct_table element type.63*/6465typedef MULTIPLIER ISLOW_MULT_TYPE; /* short or int, whichever is faster */66#if BITS_IN_JSAMPLE == 867typedef MULTIPLIER IFAST_MULT_TYPE; /* 16 bits is OK, use short if faster */68#define IFAST_SCALE_BITS 2 /* fractional bits in scale factors */69#else70typedef JLONG IFAST_MULT_TYPE; /* need 32 bits for scaled quantizers */71#define IFAST_SCALE_BITS 13 /* fractional bits in scale factors */72#endif73typedef FAST_FLOAT FLOAT_MULT_TYPE; /* preferred floating type */747576/*77* Each IDCT routine is responsible for range-limiting its results and78* converting them to unsigned form (0..MAXJSAMPLE). The raw outputs could79* be quite far out of range if the input data is corrupt, so a bulletproof80* range-limiting step is required. We use a mask-and-table-lookup method81* to do the combined operations quickly. See the comments with82* prepare_range_limit_table (in jdmaster.c) for more info.83*/8485#define IDCT_range_limit(cinfo) ((cinfo)->sample_range_limit + CENTERJSAMPLE)8687#define RANGE_MASK (MAXJSAMPLE * 4 + 3) /* 2 bits wider than legal samples */888990/* Extern declarations for the forward and inverse DCT routines. */9192EXTERN(void) jpeg_fdct_islow (DCTELEM *data);93EXTERN(void) jpeg_fdct_ifast (DCTELEM *data);94EXTERN(void) jpeg_fdct_float (FAST_FLOAT *data);9596EXTERN(void) jpeg_idct_islow97(j_decompress_ptr cinfo, jpeg_component_info *compptr,98JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col);99EXTERN(void) jpeg_idct_ifast100(j_decompress_ptr cinfo, jpeg_component_info *compptr,101JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col);102EXTERN(void) jpeg_idct_float103(j_decompress_ptr cinfo, jpeg_component_info *compptr,104JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col);105EXTERN(void) jpeg_idct_7x7106(j_decompress_ptr cinfo, jpeg_component_info *compptr,107JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col);108EXTERN(void) jpeg_idct_6x6109(j_decompress_ptr cinfo, jpeg_component_info *compptr,110JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col);111EXTERN(void) jpeg_idct_5x5112(j_decompress_ptr cinfo, jpeg_component_info *compptr,113JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col);114EXTERN(void) jpeg_idct_4x4115(j_decompress_ptr cinfo, jpeg_component_info *compptr,116JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col);117EXTERN(void) jpeg_idct_3x3118(j_decompress_ptr cinfo, jpeg_component_info *compptr,119JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col);120EXTERN(void) jpeg_idct_2x2121(j_decompress_ptr cinfo, jpeg_component_info *compptr,122JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col);123EXTERN(void) jpeg_idct_1x1124(j_decompress_ptr cinfo, jpeg_component_info *compptr,125JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col);126EXTERN(void) jpeg_idct_9x9127(j_decompress_ptr cinfo, jpeg_component_info *compptr,128JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col);129EXTERN(void) jpeg_idct_10x10130(j_decompress_ptr cinfo, jpeg_component_info *compptr,131JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col);132EXTERN(void) jpeg_idct_11x11133(j_decompress_ptr cinfo, jpeg_component_info *compptr,134JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col);135EXTERN(void) jpeg_idct_12x12136(j_decompress_ptr cinfo, jpeg_component_info *compptr,137JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col);138EXTERN(void) jpeg_idct_13x13139(j_decompress_ptr cinfo, jpeg_component_info *compptr,140JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col);141EXTERN(void) jpeg_idct_14x14142(j_decompress_ptr cinfo, jpeg_component_info *compptr,143JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col);144EXTERN(void) jpeg_idct_15x15145(j_decompress_ptr cinfo, jpeg_component_info *compptr,146JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col);147EXTERN(void) jpeg_idct_16x16148(j_decompress_ptr cinfo, jpeg_component_info *compptr,149JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col);150151152/*153* Macros for handling fixed-point arithmetic; these are used by many154* but not all of the DCT/IDCT modules.155*156* All values are expected to be of type JLONG.157* Fractional constants are scaled left by CONST_BITS bits.158* CONST_BITS is defined within each module using these macros,159* and may differ from one module to the next.160*/161162#define ONE ((JLONG) 1)163#define CONST_SCALE (ONE << CONST_BITS)164165/* Convert a positive real constant to an integer scaled by CONST_SCALE.166* Caution: some C compilers fail to reduce "FIX(constant)" at compile time,167* thus causing a lot of useless floating-point operations at run time.168*/169170#define FIX(x) ((JLONG) ((x) * CONST_SCALE + 0.5))171172/* Descale and correctly round a JLONG value that's scaled by N bits.173* We assume RIGHT_SHIFT rounds towards minus infinity, so adding174* the fudge factor is correct for either sign of X.175*/176177#define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n)178179/* Multiply a JLONG variable by a JLONG constant to yield a JLONG result.180* This macro is used only when the two inputs will actually be no more than181* 16 bits wide, so that a 16x16->32 bit multiply can be used instead of a182* full 32x32 multiply. This provides a useful speedup on many machines.183* Unfortunately there is no way to specify a 16x16->32 multiply portably184* in C, but some C compilers will do the right thing if you provide the185* correct combination of casts.186*/187188#ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */189#define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT16) (const)))190#endif191#ifdef SHORTxLCONST_32 /* known to work with Microsoft C 6.0 */192#define MULTIPLY16C16(var,const) (((INT16) (var)) * ((JLONG) (const)))193#endif194195#ifndef MULTIPLY16C16 /* default definition */196#define MULTIPLY16C16(var,const) ((var) * (const))197#endif198199/* Same except both inputs are variables. */200201#ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */202#define MULTIPLY16V16(var1,var2) (((INT16) (var1)) * ((INT16) (var2)))203#endif204205#ifndef MULTIPLY16V16 /* default definition */206#define MULTIPLY16V16(var1,var2) ((var1) * (var2))207#endif208209210