jdct.h 17 KB

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