Path: blob/master/thirdparty/libjpeg-turbo/src/jdct.h
9904 views
/*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, 2022, 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*/1617#include "jsamplecomp.h"181920/*21* A forward DCT routine is given a pointer to a work area of type DCTELEM[];22* the DCT is to be performed in-place in that buffer. Type DCTELEM is int23* for 8-bit samples, JLONG for 12-bit samples. (NOTE: Floating-point DCT24* implementations use an array of type FAST_FLOAT, instead.)25* The DCT inputs are expected to be signed (range +-_CENTERJSAMPLE).26* The DCT outputs are returned scaled up by a factor of 8; they therefore27* have a range of +-8K for 8-bit data, +-128K for 12-bit data. This28* convention improves accuracy in integer implementations and saves some29* work in floating-point ones.30* Quantization of the output coefficients is done by jcdctmgr.c. This31* step requires an unsigned type and also one with twice the bits.32*/3334#if BITS_IN_JSAMPLE == 835#ifndef WITH_SIMD36typedef int DCTELEM; /* 16 or 32 bits is fine */37typedef unsigned int UDCTELEM;38typedef unsigned long long UDCTELEM2;39#else40typedef short DCTELEM; /* prefer 16 bit with SIMD for parellelism */41typedef unsigned short UDCTELEM;42typedef unsigned int UDCTELEM2;43#endif44#else45typedef JLONG DCTELEM; /* must have 32 bits */46typedef unsigned long long UDCTELEM2;47#endif484950/*51* An inverse DCT routine is given a pointer to the input JBLOCK and a pointer52* to an output sample array. The routine must dequantize the input data as53* well as perform the IDCT; for dequantization, it uses the multiplier table54* pointed to by compptr->dct_table. The output data is to be placed into the55* sample array starting at a specified column. (Any row offset needed will56* be applied to the array pointer before it is passed to the IDCT code.)57* Note that the number of samples emitted by the IDCT routine is58* DCT_scaled_size * DCT_scaled_size.59*/6061/* typedef inverse_DCT_method_ptr is declared in jpegint.h */6263/*64* Each IDCT routine has its own ideas about the best dct_table element type.65*/6667typedef MULTIPLIER ISLOW_MULT_TYPE; /* short or int, whichever is faster */68#if BITS_IN_JSAMPLE == 869typedef MULTIPLIER IFAST_MULT_TYPE; /* 16 bits is OK, use short if faster */70#define IFAST_SCALE_BITS 2 /* fractional bits in scale factors */71#else72typedef JLONG IFAST_MULT_TYPE; /* need 32 bits for scaled quantizers */73#define IFAST_SCALE_BITS 13 /* fractional bits in scale factors */74#endif75typedef FAST_FLOAT FLOAT_MULT_TYPE; /* preferred floating type */767778/*79* Each IDCT routine is responsible for range-limiting its results and80* converting them to unsigned form (0.._MAXJSAMPLE). The raw outputs could81* be quite far out of range if the input data is corrupt, so a bulletproof82* range-limiting step is required. We use a mask-and-table-lookup method83* to do the combined operations quickly. See the comments with84* prepare_range_limit_table (in jdmaster.c) for more info.85*/8687#define IDCT_range_limit(cinfo) \88((_JSAMPLE *)((cinfo)->sample_range_limit) + _CENTERJSAMPLE)8990#define RANGE_MASK (_MAXJSAMPLE * 4 + 3) /* 2 bits wider than legal samples */919293/* Extern declarations for the forward and inverse DCT routines. */9495EXTERN(void) _jpeg_fdct_islow(DCTELEM *data);96EXTERN(void) _jpeg_fdct_ifast(DCTELEM *data);97EXTERN(void) jpeg_fdct_float(FAST_FLOAT *data);9899EXTERN(void) _jpeg_idct_islow(j_decompress_ptr cinfo,100jpeg_component_info *compptr,101JCOEFPTR coef_block, _JSAMPARRAY output_buf,102JDIMENSION output_col);103EXTERN(void) _jpeg_idct_ifast(j_decompress_ptr cinfo,104jpeg_component_info *compptr,105JCOEFPTR coef_block, _JSAMPARRAY output_buf,106JDIMENSION output_col);107EXTERN(void) _jpeg_idct_float(j_decompress_ptr cinfo,108jpeg_component_info *compptr,109JCOEFPTR coef_block, _JSAMPARRAY output_buf,110JDIMENSION output_col);111EXTERN(void) _jpeg_idct_7x7(j_decompress_ptr cinfo,112jpeg_component_info *compptr, JCOEFPTR coef_block,113_JSAMPARRAY output_buf, JDIMENSION output_col);114EXTERN(void) _jpeg_idct_6x6(j_decompress_ptr cinfo,115jpeg_component_info *compptr, JCOEFPTR coef_block,116_JSAMPARRAY output_buf, JDIMENSION output_col);117EXTERN(void) _jpeg_idct_5x5(j_decompress_ptr cinfo,118jpeg_component_info *compptr, JCOEFPTR coef_block,119_JSAMPARRAY output_buf, JDIMENSION output_col);120EXTERN(void) _jpeg_idct_4x4(j_decompress_ptr cinfo,121jpeg_component_info *compptr, JCOEFPTR coef_block,122_JSAMPARRAY output_buf, JDIMENSION output_col);123EXTERN(void) _jpeg_idct_3x3(j_decompress_ptr cinfo,124jpeg_component_info *compptr, JCOEFPTR coef_block,125_JSAMPARRAY output_buf, JDIMENSION output_col);126EXTERN(void) _jpeg_idct_2x2(j_decompress_ptr cinfo,127jpeg_component_info *compptr, JCOEFPTR coef_block,128_JSAMPARRAY output_buf, JDIMENSION output_col);129EXTERN(void) _jpeg_idct_1x1(j_decompress_ptr cinfo,130jpeg_component_info *compptr, JCOEFPTR coef_block,131_JSAMPARRAY output_buf, JDIMENSION output_col);132EXTERN(void) _jpeg_idct_9x9(j_decompress_ptr cinfo,133jpeg_component_info *compptr, JCOEFPTR coef_block,134_JSAMPARRAY output_buf, JDIMENSION output_col);135EXTERN(void) _jpeg_idct_10x10(j_decompress_ptr cinfo,136jpeg_component_info *compptr,137JCOEFPTR coef_block, _JSAMPARRAY output_buf,138JDIMENSION output_col);139EXTERN(void) _jpeg_idct_11x11(j_decompress_ptr cinfo,140jpeg_component_info *compptr,141JCOEFPTR coef_block, _JSAMPARRAY output_buf,142JDIMENSION output_col);143EXTERN(void) _jpeg_idct_12x12(j_decompress_ptr cinfo,144jpeg_component_info *compptr,145JCOEFPTR coef_block, _JSAMPARRAY output_buf,146JDIMENSION output_col);147EXTERN(void) _jpeg_idct_13x13(j_decompress_ptr cinfo,148jpeg_component_info *compptr,149JCOEFPTR coef_block, _JSAMPARRAY output_buf,150JDIMENSION output_col);151EXTERN(void) _jpeg_idct_14x14(j_decompress_ptr cinfo,152jpeg_component_info *compptr,153JCOEFPTR coef_block, _JSAMPARRAY output_buf,154JDIMENSION output_col);155EXTERN(void) _jpeg_idct_15x15(j_decompress_ptr cinfo,156jpeg_component_info *compptr,157JCOEFPTR coef_block, _JSAMPARRAY output_buf,158JDIMENSION output_col);159EXTERN(void) _jpeg_idct_16x16(j_decompress_ptr cinfo,160jpeg_component_info *compptr,161JCOEFPTR coef_block, _JSAMPARRAY output_buf,162JDIMENSION output_col);163164165/*166* Macros for handling fixed-point arithmetic; these are used by many167* but not all of the DCT/IDCT modules.168*169* All values are expected to be of type JLONG.170* Fractional constants are scaled left by CONST_BITS bits.171* CONST_BITS is defined within each module using these macros,172* and may differ from one module to the next.173*/174175#define ONE ((JLONG)1)176#define CONST_SCALE (ONE << CONST_BITS)177178/* Convert a positive real constant to an integer scaled by CONST_SCALE.179* Caution: some C compilers fail to reduce "FIX(constant)" at compile time,180* thus causing a lot of useless floating-point operations at run time.181*/182183#define FIX(x) ((JLONG)((x) * CONST_SCALE + 0.5))184185/* Descale and correctly round a JLONG value that's scaled by N bits.186* We assume RIGHT_SHIFT rounds towards minus infinity, so adding187* the fudge factor is correct for either sign of X.188*/189190#define DESCALE(x, n) RIGHT_SHIFT((x) + (ONE << ((n) - 1)), n)191192/* Multiply a JLONG variable by a JLONG constant to yield a JLONG result.193* This macro is used only when the two inputs will actually be no more than194* 16 bits wide, so that a 16x16->32 bit multiply can be used instead of a195* full 32x32 multiply. This provides a useful speedup on many machines.196* Unfortunately there is no way to specify a 16x16->32 multiply portably197* in C, but some C compilers will do the right thing if you provide the198* correct combination of casts.199*/200201#ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */202#define MULTIPLY16C16(var, const) (((INT16)(var)) * ((INT16)(const)))203#endif204#ifdef SHORTxLCONST_32 /* known to work with Microsoft C 6.0 */205#define MULTIPLY16C16(var, const) (((INT16)(var)) * ((JLONG)(const)))206#endif207208#ifndef MULTIPLY16C16 /* default definition */209#define MULTIPLY16C16(var, const) ((var) * (const))210#endif211212/* Same except both inputs are variables. */213214#ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */215#define MULTIPLY16V16(var1, var2) (((INT16)(var1)) * ((INT16)(var2)))216#endif217218#ifndef MULTIPLY16V16 /* default definition */219#define MULTIPLY16V16(var1, var2) ((var1) * (var2))220#endif221222223