jdct.h 9.5 KB

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