jdct.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. /*
  2. * jdct.h
  3. *
  4. * Copyright (C) 1994-1996, Thomas G. Lane.
  5. * Modified 2002-2015 by Guido Vollbeding.
  6. * This file is part of the Independent JPEG Group's software.
  7. * For conditions of distribution and use, see the accompanying README file.
  8. *
  9. * This include file contains common declarations for the forward and
  10. * inverse DCT modules. These declarations are private to the DCT managers
  11. * (jcdctmgr.c, jddctmgr.c) and the individual DCT algorithms.
  12. * The individual DCT algorithms are kept in separate files to ease
  13. * machine-dependent tuning (e.g., assembly coding).
  14. */
  15. /*
  16. * A forward DCT routine is given a pointer to an input sample array and
  17. * a pointer to a work area of type DCTELEM[]; the DCT is to be performed
  18. * in-place in that buffer. Type DCTELEM is int for 8-bit samples, INT32
  19. * for 12-bit samples. (NOTE: Floating-point DCT implementations use an
  20. * array of type FAST_FLOAT, instead.)
  21. * The input data is to be fetched from the sample array starting at a
  22. * specified column. (Any row offset needed will be applied to the array
  23. * pointer before it is passed to the FDCT code.)
  24. * Note that the number of samples fetched by the FDCT routine is
  25. * DCT_h_scaled_size * DCT_v_scaled_size.
  26. * The DCT outputs are returned scaled up by a factor of 8; they therefore
  27. * have a range of +-8K for 8-bit data, +-128K for 12-bit data. This
  28. * convention improves accuracy in integer implementations and saves some
  29. * work in floating-point ones.
  30. * Quantization of the output coefficients is done by jcdctmgr.c.
  31. */
  32. #if BITS_IN_JSAMPLE == 8
  33. typedef int DCTELEM; /* 16 or 32 bits is fine */
  34. #else
  35. typedef INT32 DCTELEM; /* must have 32 bits */
  36. #endif
  37. typedef JMETHOD(void, forward_DCT_method_ptr, (DCTELEM * data,
  38. JSAMPARRAY sample_data,
  39. JDIMENSION start_col));
  40. typedef JMETHOD(void, float_DCT_method_ptr, (FAST_FLOAT * data,
  41. JSAMPARRAY sample_data,
  42. JDIMENSION start_col));
  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_h_scaled_size * DCT_v_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, assuming that MAXJSAMPLE+1
  72. * is a power of 2. See the comments with prepare_range_limit_table
  73. * (in jdmaster.c) for more info.
  74. */
  75. #define RANGE_MASK (MAXJSAMPLE * 4 + 3) /* 2 bits wider than legal samples */
  76. #define RANGE_CENTER (MAXJSAMPLE * 2 + 2)
  77. #define RANGE_SUBSET (RANGE_CENTER - CENTERJSAMPLE)
  78. #define IDCT_range_limit(cinfo) ((cinfo)->sample_range_limit - RANGE_SUBSET)
  79. /* Short forms of external names for systems with brain-damaged linkers. */
  80. #ifdef NEED_SHORT_EXTERNAL_NAMES
  81. #define jpeg_fdct_islow jFDislow
  82. #define jpeg_fdct_ifast jFDifast
  83. #define jpeg_fdct_float jFDfloat
  84. #define jpeg_fdct_7x7 jFD7x7
  85. #define jpeg_fdct_6x6 jFD6x6
  86. #define jpeg_fdct_5x5 jFD5x5
  87. #define jpeg_fdct_4x4 jFD4x4
  88. #define jpeg_fdct_3x3 jFD3x3
  89. #define jpeg_fdct_2x2 jFD2x2
  90. #define jpeg_fdct_1x1 jFD1x1
  91. #define jpeg_fdct_9x9 jFD9x9
  92. #define jpeg_fdct_10x10 jFD10x10
  93. #define jpeg_fdct_11x11 jFD11x11
  94. #define jpeg_fdct_12x12 jFD12x12
  95. #define jpeg_fdct_13x13 jFD13x13
  96. #define jpeg_fdct_14x14 jFD14x14
  97. #define jpeg_fdct_15x15 jFD15x15
  98. #define jpeg_fdct_16x16 jFD16x16
  99. #define jpeg_fdct_16x8 jFD16x8
  100. #define jpeg_fdct_14x7 jFD14x7
  101. #define jpeg_fdct_12x6 jFD12x6
  102. #define jpeg_fdct_10x5 jFD10x5
  103. #define jpeg_fdct_8x4 jFD8x4
  104. #define jpeg_fdct_6x3 jFD6x3
  105. #define jpeg_fdct_4x2 jFD4x2
  106. #define jpeg_fdct_2x1 jFD2x1
  107. #define jpeg_fdct_8x16 jFD8x16
  108. #define jpeg_fdct_7x14 jFD7x14
  109. #define jpeg_fdct_6x12 jFD6x12
  110. #define jpeg_fdct_5x10 jFD5x10
  111. #define jpeg_fdct_4x8 jFD4x8
  112. #define jpeg_fdct_3x6 jFD3x6
  113. #define jpeg_fdct_2x4 jFD2x4
  114. #define jpeg_fdct_1x2 jFD1x2
  115. #define jpeg_idct_islow jRDislow
  116. #define jpeg_idct_ifast jRDifast
  117. #define jpeg_idct_float jRDfloat
  118. #define jpeg_idct_7x7 jRD7x7
  119. #define jpeg_idct_6x6 jRD6x6
  120. #define jpeg_idct_5x5 jRD5x5
  121. #define jpeg_idct_4x4 jRD4x4
  122. #define jpeg_idct_3x3 jRD3x3
  123. #define jpeg_idct_2x2 jRD2x2
  124. #define jpeg_idct_1x1 jRD1x1
  125. #define jpeg_idct_9x9 jRD9x9
  126. #define jpeg_idct_10x10 jRD10x10
  127. #define jpeg_idct_11x11 jRD11x11
  128. #define jpeg_idct_12x12 jRD12x12
  129. #define jpeg_idct_13x13 jRD13x13
  130. #define jpeg_idct_14x14 jRD14x14
  131. #define jpeg_idct_15x15 jRD15x15
  132. #define jpeg_idct_16x16 jRD16x16
  133. #define jpeg_idct_16x8 jRD16x8
  134. #define jpeg_idct_14x7 jRD14x7
  135. #define jpeg_idct_12x6 jRD12x6
  136. #define jpeg_idct_10x5 jRD10x5
  137. #define jpeg_idct_8x4 jRD8x4
  138. #define jpeg_idct_6x3 jRD6x3
  139. #define jpeg_idct_4x2 jRD4x2
  140. #define jpeg_idct_2x1 jRD2x1
  141. #define jpeg_idct_8x16 jRD8x16
  142. #define jpeg_idct_7x14 jRD7x14
  143. #define jpeg_idct_6x12 jRD6x12
  144. #define jpeg_idct_5x10 jRD5x10
  145. #define jpeg_idct_4x8 jRD4x8
  146. #define jpeg_idct_3x6 jRD3x8
  147. #define jpeg_idct_2x4 jRD2x4
  148. #define jpeg_idct_1x2 jRD1x2
  149. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  150. /* Extern declarations for the forward and inverse DCT routines. */
  151. EXTERN(void) jpeg_fdct_islow
  152. JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
  153. EXTERN(void) jpeg_fdct_ifast
  154. JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
  155. EXTERN(void) jpeg_fdct_float
  156. JPP((FAST_FLOAT * data, JSAMPARRAY sample_data, JDIMENSION start_col));
  157. EXTERN(void) jpeg_fdct_7x7
  158. JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
  159. EXTERN(void) jpeg_fdct_6x6
  160. JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
  161. EXTERN(void) jpeg_fdct_5x5
  162. JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
  163. EXTERN(void) jpeg_fdct_4x4
  164. JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
  165. EXTERN(void) jpeg_fdct_3x3
  166. JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
  167. EXTERN(void) jpeg_fdct_2x2
  168. JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
  169. EXTERN(void) jpeg_fdct_1x1
  170. JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
  171. EXTERN(void) jpeg_fdct_9x9
  172. JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
  173. EXTERN(void) jpeg_fdct_10x10
  174. JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
  175. EXTERN(void) jpeg_fdct_11x11
  176. JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
  177. EXTERN(void) jpeg_fdct_12x12
  178. JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
  179. EXTERN(void) jpeg_fdct_13x13
  180. JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
  181. EXTERN(void) jpeg_fdct_14x14
  182. JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
  183. EXTERN(void) jpeg_fdct_15x15
  184. JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
  185. EXTERN(void) jpeg_fdct_16x16
  186. JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
  187. EXTERN(void) jpeg_fdct_16x8
  188. JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
  189. EXTERN(void) jpeg_fdct_14x7
  190. JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
  191. EXTERN(void) jpeg_fdct_12x6
  192. JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
  193. EXTERN(void) jpeg_fdct_10x5
  194. JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
  195. EXTERN(void) jpeg_fdct_8x4
  196. JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
  197. EXTERN(void) jpeg_fdct_6x3
  198. JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
  199. EXTERN(void) jpeg_fdct_4x2
  200. JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
  201. EXTERN(void) jpeg_fdct_2x1
  202. JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
  203. EXTERN(void) jpeg_fdct_8x16
  204. JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
  205. EXTERN(void) jpeg_fdct_7x14
  206. JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
  207. EXTERN(void) jpeg_fdct_6x12
  208. JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
  209. EXTERN(void) jpeg_fdct_5x10
  210. JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
  211. EXTERN(void) jpeg_fdct_4x8
  212. JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
  213. EXTERN(void) jpeg_fdct_3x6
  214. JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
  215. EXTERN(void) jpeg_fdct_2x4
  216. JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
  217. EXTERN(void) jpeg_fdct_1x2
  218. JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
  219. EXTERN(void) jpeg_idct_islow
  220. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  221. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  222. EXTERN(void) jpeg_idct_ifast
  223. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  224. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  225. EXTERN(void) jpeg_idct_float
  226. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  227. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  228. EXTERN(void) jpeg_idct_7x7
  229. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  230. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  231. EXTERN(void) jpeg_idct_6x6
  232. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  233. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  234. EXTERN(void) jpeg_idct_5x5
  235. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  236. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  237. EXTERN(void) jpeg_idct_4x4
  238. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  239. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  240. EXTERN(void) jpeg_idct_3x3
  241. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  242. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  243. EXTERN(void) jpeg_idct_2x2
  244. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  245. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  246. EXTERN(void) jpeg_idct_1x1
  247. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  248. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  249. EXTERN(void) jpeg_idct_9x9
  250. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  251. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  252. EXTERN(void) jpeg_idct_10x10
  253. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  254. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  255. EXTERN(void) jpeg_idct_11x11
  256. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  257. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  258. EXTERN(void) jpeg_idct_12x12
  259. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  260. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  261. EXTERN(void) jpeg_idct_13x13
  262. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  263. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  264. EXTERN(void) jpeg_idct_14x14
  265. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  266. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  267. EXTERN(void) jpeg_idct_15x15
  268. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  269. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  270. EXTERN(void) jpeg_idct_16x16
  271. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  272. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  273. EXTERN(void) jpeg_idct_16x8
  274. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  275. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  276. EXTERN(void) jpeg_idct_14x7
  277. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  278. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  279. EXTERN(void) jpeg_idct_12x6
  280. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  281. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  282. EXTERN(void) jpeg_idct_10x5
  283. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  284. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  285. EXTERN(void) jpeg_idct_8x4
  286. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  287. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  288. EXTERN(void) jpeg_idct_6x3
  289. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  290. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  291. EXTERN(void) jpeg_idct_4x2
  292. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  293. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  294. EXTERN(void) jpeg_idct_2x1
  295. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  296. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  297. EXTERN(void) jpeg_idct_8x16
  298. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  299. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  300. EXTERN(void) jpeg_idct_7x14
  301. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  302. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  303. EXTERN(void) jpeg_idct_6x12
  304. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  305. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  306. EXTERN(void) jpeg_idct_5x10
  307. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  308. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  309. EXTERN(void) jpeg_idct_4x8
  310. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  311. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  312. EXTERN(void) jpeg_idct_3x6
  313. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  314. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  315. EXTERN(void) jpeg_idct_2x4
  316. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  317. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  318. EXTERN(void) jpeg_idct_1x2
  319. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  320. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  321. /*
  322. * Macros for handling fixed-point arithmetic; these are used by many
  323. * but not all of the DCT/IDCT modules.
  324. *
  325. * All values are expected to be of type INT32.
  326. * Fractional constants are scaled left by CONST_BITS bits.
  327. * CONST_BITS is defined within each module using these macros,
  328. * and may differ from one module to the next.
  329. */
  330. #define ONE ((INT32) 1)
  331. #define CONST_SCALE (ONE << CONST_BITS)
  332. /* Convert a positive real constant to an integer scaled by CONST_SCALE.
  333. * Caution: some C compilers fail to reduce "FIX(constant)" at compile time,
  334. * thus causing a lot of useless floating-point operations at run time.
  335. */
  336. #define FIX(x) ((INT32) ((x) * CONST_SCALE + 0.5))
  337. /* Descale and correctly round an INT32 value that's scaled by N bits.
  338. * We assume RIGHT_SHIFT rounds towards minus infinity, so adding
  339. * the fudge factor is correct for either sign of X.
  340. */
  341. #define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n)
  342. /* Multiply an INT32 variable by an INT32 constant to yield an INT32 result.
  343. * This macro is used only when the two inputs will actually be no more than
  344. * 16 bits wide, so that a 16x16->32 bit multiply can be used instead of a
  345. * full 32x32 multiply. This provides a useful speedup on many machines.
  346. * Unfortunately there is no way to specify a 16x16->32 multiply portably
  347. * in C, but some C compilers will do the right thing if you provide the
  348. * correct combination of casts.
  349. */
  350. #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
  351. #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT16) (const)))
  352. #endif
  353. #ifdef SHORTxLCONST_32 /* known to work with Microsoft C 6.0 */
  354. #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT32) (const)))
  355. #endif
  356. #ifndef MULTIPLY16C16 /* default definition */
  357. #define MULTIPLY16C16(var,const) ((var) * (const))
  358. #endif
  359. /* Same except both inputs are variables. */
  360. #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
  361. #define MULTIPLY16V16(var1,var2) (((INT16) (var1)) * ((INT16) (var2)))
  362. #endif
  363. #ifndef MULTIPLY16V16 /* default definition */
  364. #define MULTIPLY16V16(var1,var2) ((var1) * (var2))
  365. #endif
  366. /* Like RIGHT_SHIFT, but applies to a DCTELEM.
  367. * We assume that int right shift is unsigned if INT32 right shift is.
  368. */
  369. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  370. #define ISHIFT_TEMPS DCTELEM ishift_temp;
  371. #if BITS_IN_JSAMPLE == 8
  372. #define DCTELEMBITS 16 /* DCTELEM may be 16 or 32 bits */
  373. #else
  374. #define DCTELEMBITS 32 /* DCTELEM must be 32 bits */
  375. #endif
  376. #define IRIGHT_SHIFT(x,shft) \
  377. ((ishift_temp = (x)) < 0 ? \
  378. (ishift_temp >> (shft)) | ((~((DCTELEM) 0)) << (DCTELEMBITS-(shft))) : \
  379. (ishift_temp >> (shft)))
  380. #else
  381. #define ISHIFT_TEMPS
  382. #define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
  383. #endif