jdct.h 8.8 KB

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