/src/FreeImage/Source/LibJPEG/jidctint.c

https://bitbucket.org/cabalistic/ogredeps/ · C · 5137 lines · 3541 code · 880 blank · 716 comment · 106 complexity · 4ea27dba5316cdba15d8294ad0364aa8 MD5 · raw file

Large files are truncated click here to view the full file

  1. /*
  2. * jidctint.c
  3. *
  4. * Copyright (C) 1991-1998, Thomas G. Lane.
  5. * Modification developed 2002-2009 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 file contains a slow-but-accurate integer implementation of the
  10. * inverse DCT (Discrete Cosine Transform). In the IJG code, this routine
  11. * must also perform dequantization of the input coefficients.
  12. *
  13. * A 2-D IDCT can be done by 1-D IDCT on each column followed by 1-D IDCT
  14. * on each row (or vice versa, but it's more convenient to emit a row at
  15. * a time). Direct algorithms are also available, but they are much more
  16. * complex and seem not to be any faster when reduced to code.
  17. *
  18. * This implementation is based on an algorithm described in
  19. * C. Loeffler, A. Ligtenberg and G. Moschytz, "Practical Fast 1-D DCT
  20. * Algorithms with 11 Multiplications", Proc. Int'l. Conf. on Acoustics,
  21. * Speech, and Signal Processing 1989 (ICASSP '89), pp. 988-991.
  22. * The primary algorithm described there uses 11 multiplies and 29 adds.
  23. * We use their alternate method with 12 multiplies and 32 adds.
  24. * The advantage of this method is that no data path contains more than one
  25. * multiplication; this allows a very simple and accurate implementation in
  26. * scaled fixed-point arithmetic, with a minimal number of shifts.
  27. *
  28. * We also provide IDCT routines with various output sample block sizes for
  29. * direct resolution reduction or enlargement and for direct resolving the
  30. * common 2x1 and 1x2 subsampling cases without additional resampling: NxN
  31. * (N=1...16), 2NxN, and Nx2N (N=1...8) pixels for one 8x8 input DCT block.
  32. *
  33. * For N<8 we simply take the corresponding low-frequency coefficients of
  34. * the 8x8 input DCT block and apply an NxN point IDCT on the sub-block
  35. * to yield the downscaled outputs.
  36. * This can be seen as direct low-pass downsampling from the DCT domain
  37. * point of view rather than the usual spatial domain point of view,
  38. * yielding significant computational savings and results at least
  39. * as good as common bilinear (averaging) spatial downsampling.
  40. *
  41. * For N>8 we apply a partial NxN IDCT on the 8 input coefficients as
  42. * lower frequencies and higher frequencies assumed to be zero.
  43. * It turns out that the computational effort is similar to the 8x8 IDCT
  44. * regarding the output size.
  45. * Furthermore, the scaling and descaling is the same for all IDCT sizes.
  46. *
  47. * CAUTION: We rely on the FIX() macro except for the N=1,2,4,8 cases
  48. * since there would be too many additional constants to pre-calculate.
  49. */
  50. #define JPEG_INTERNALS
  51. #include "jinclude.h"
  52. #include "jpeglib.h"
  53. #include "jdct.h" /* Private declarations for DCT subsystem */
  54. #ifdef DCT_ISLOW_SUPPORTED
  55. /*
  56. * This module is specialized to the case DCTSIZE = 8.
  57. */
  58. #if DCTSIZE != 8
  59. Sorry, this code only copes with 8x8 DCT blocks. /* deliberate syntax err */
  60. #endif
  61. /*
  62. * The poop on this scaling stuff is as follows:
  63. *
  64. * Each 1-D IDCT step produces outputs which are a factor of sqrt(N)
  65. * larger than the true IDCT outputs. The final outputs are therefore
  66. * a factor of N larger than desired; since N=8 this can be cured by
  67. * a simple right shift at the end of the algorithm. The advantage of
  68. * this arrangement is that we save two multiplications per 1-D IDCT,
  69. * because the y0 and y4 inputs need not be divided by sqrt(N).
  70. *
  71. * We have to do addition and subtraction of the integer inputs, which
  72. * is no problem, and multiplication by fractional constants, which is
  73. * a problem to do in integer arithmetic. We multiply all the constants
  74. * by CONST_SCALE and convert them to integer constants (thus retaining
  75. * CONST_BITS bits of precision in the constants). After doing a
  76. * multiplication we have to divide the product by CONST_SCALE, with proper
  77. * rounding, to produce the correct output. This division can be done
  78. * cheaply as a right shift of CONST_BITS bits. We postpone shifting
  79. * as long as possible so that partial sums can be added together with
  80. * full fractional precision.
  81. *
  82. * The outputs of the first pass are scaled up by PASS1_BITS bits so that
  83. * they are represented to better-than-integral precision. These outputs
  84. * require BITS_IN_JSAMPLE + PASS1_BITS + 3 bits; this fits in a 16-bit word
  85. * with the recommended scaling. (To scale up 12-bit sample data further, an
  86. * intermediate INT32 array would be needed.)
  87. *
  88. * To avoid overflow of the 32-bit intermediate results in pass 2, we must
  89. * have BITS_IN_JSAMPLE + CONST_BITS + PASS1_BITS <= 26. Error analysis
  90. * shows that the values given below are the most effective.
  91. */
  92. #if BITS_IN_JSAMPLE == 8
  93. #define CONST_BITS 13
  94. #define PASS1_BITS 2
  95. #else
  96. #define CONST_BITS 13
  97. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  98. #endif
  99. /* Some C compilers fail to reduce "FIX(constant)" at compile time, thus
  100. * causing a lot of useless floating-point operations at run time.
  101. * To get around this we use the following pre-calculated constants.
  102. * If you change CONST_BITS you may want to add appropriate values.
  103. * (With a reasonable C compiler, you can just rely on the FIX() macro...)
  104. */
  105. #if CONST_BITS == 13
  106. #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
  107. #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
  108. #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
  109. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  110. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  111. #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
  112. #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
  113. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  114. #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
  115. #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
  116. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  117. #define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
  118. #else
  119. #define FIX_0_298631336 FIX(0.298631336)
  120. #define FIX_0_390180644 FIX(0.390180644)
  121. #define FIX_0_541196100 FIX(0.541196100)
  122. #define FIX_0_765366865 FIX(0.765366865)
  123. #define FIX_0_899976223 FIX(0.899976223)
  124. #define FIX_1_175875602 FIX(1.175875602)
  125. #define FIX_1_501321110 FIX(1.501321110)
  126. #define FIX_1_847759065 FIX(1.847759065)
  127. #define FIX_1_961570560 FIX(1.961570560)
  128. #define FIX_2_053119869 FIX(2.053119869)
  129. #define FIX_2_562915447 FIX(2.562915447)
  130. #define FIX_3_072711026 FIX(3.072711026)
  131. #endif
  132. /* Multiply an INT32 variable by an INT32 constant to yield an INT32 result.
  133. * For 8-bit samples with the recommended scaling, all the variable
  134. * and constant values involved are no more than 16 bits wide, so a
  135. * 16x16->32 bit multiply can be used instead of a full 32x32 multiply.
  136. * For 12-bit samples, a full 32-bit multiplication will be needed.
  137. */
  138. #if BITS_IN_JSAMPLE == 8
  139. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  140. #else
  141. #define MULTIPLY(var,const) ((var) * (const))
  142. #endif
  143. /* Dequantize a coefficient by multiplying it by the multiplier-table
  144. * entry; produce an int result. In this module, both inputs and result
  145. * are 16 bits or less, so either int or short multiply will work.
  146. */
  147. #define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
  148. /*
  149. * Perform dequantization and inverse DCT on one block of coefficients.
  150. */
  151. GLOBAL(void)
  152. jpeg_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  153. JCOEFPTR coef_block,
  154. JSAMPARRAY output_buf, JDIMENSION output_col)
  155. {
  156. INT32 tmp0, tmp1, tmp2, tmp3;
  157. INT32 tmp10, tmp11, tmp12, tmp13;
  158. INT32 z1, z2, z3;
  159. JCOEFPTR inptr;
  160. ISLOW_MULT_TYPE * quantptr;
  161. int * wsptr;
  162. JSAMPROW outptr;
  163. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  164. int ctr;
  165. int workspace[DCTSIZE2]; /* buffers data between passes */
  166. SHIFT_TEMPS
  167. /* Pass 1: process columns from input, store into work array. */
  168. /* Note results are scaled up by sqrt(8) compared to a true IDCT; */
  169. /* furthermore, we scale the results by 2**PASS1_BITS. */
  170. inptr = coef_block;
  171. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  172. wsptr = workspace;
  173. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  174. /* Due to quantization, we will usually find that many of the input
  175. * coefficients are zero, especially the AC terms. We can exploit this
  176. * by short-circuiting the IDCT calculation for any column in which all
  177. * the AC terms are zero. In that case each output is equal to the
  178. * DC coefficient (with scale factor as needed).
  179. * With typical images and quantization tables, half or more of the
  180. * column DCT calculations can be simplified this way.
  181. */
  182. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  183. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  184. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  185. inptr[DCTSIZE*7] == 0) {
  186. /* AC terms all zero */
  187. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  188. wsptr[DCTSIZE*0] = dcval;
  189. wsptr[DCTSIZE*1] = dcval;
  190. wsptr[DCTSIZE*2] = dcval;
  191. wsptr[DCTSIZE*3] = dcval;
  192. wsptr[DCTSIZE*4] = dcval;
  193. wsptr[DCTSIZE*5] = dcval;
  194. wsptr[DCTSIZE*6] = dcval;
  195. wsptr[DCTSIZE*7] = dcval;
  196. inptr++; /* advance pointers to next column */
  197. quantptr++;
  198. wsptr++;
  199. continue;
  200. }
  201. /* Even part: reverse the even part of the forward DCT. */
  202. /* The rotator is sqrt(2)*c(-6). */
  203. z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  204. z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  205. z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
  206. tmp2 = z1 + MULTIPLY(z2, FIX_0_765366865);
  207. tmp3 = z1 - MULTIPLY(z3, FIX_1_847759065);
  208. z2 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  209. z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  210. z2 <<= CONST_BITS;
  211. z3 <<= CONST_BITS;
  212. /* Add fudge factor here for final descale. */
  213. z2 += ONE << (CONST_BITS-PASS1_BITS-1);
  214. tmp0 = z2 + z3;
  215. tmp1 = z2 - z3;
  216. tmp10 = tmp0 + tmp2;
  217. tmp13 = tmp0 - tmp2;
  218. tmp11 = tmp1 + tmp3;
  219. tmp12 = tmp1 - tmp3;
  220. /* Odd part per figure 8; the matrix is unitary and hence its
  221. * transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively.
  222. */
  223. tmp0 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  224. tmp1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  225. tmp2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  226. tmp3 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  227. z2 = tmp0 + tmp2;
  228. z3 = tmp1 + tmp3;
  229. z1 = MULTIPLY(z2 + z3, FIX_1_175875602); /* sqrt(2) * c3 */
  230. z2 = MULTIPLY(z2, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  231. z3 = MULTIPLY(z3, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  232. z2 += z1;
  233. z3 += z1;
  234. z1 = MULTIPLY(tmp0 + tmp3, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  235. tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  236. tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  237. tmp0 += z1 + z2;
  238. tmp3 += z1 + z3;
  239. z1 = MULTIPLY(tmp1 + tmp2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  240. tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  241. tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  242. tmp1 += z1 + z3;
  243. tmp2 += z1 + z2;
  244. /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
  245. wsptr[DCTSIZE*0] = (int) RIGHT_SHIFT(tmp10 + tmp3, CONST_BITS-PASS1_BITS);
  246. wsptr[DCTSIZE*7] = (int) RIGHT_SHIFT(tmp10 - tmp3, CONST_BITS-PASS1_BITS);
  247. wsptr[DCTSIZE*1] = (int) RIGHT_SHIFT(tmp11 + tmp2, CONST_BITS-PASS1_BITS);
  248. wsptr[DCTSIZE*6] = (int) RIGHT_SHIFT(tmp11 - tmp2, CONST_BITS-PASS1_BITS);
  249. wsptr[DCTSIZE*2] = (int) RIGHT_SHIFT(tmp12 + tmp1, CONST_BITS-PASS1_BITS);
  250. wsptr[DCTSIZE*5] = (int) RIGHT_SHIFT(tmp12 - tmp1, CONST_BITS-PASS1_BITS);
  251. wsptr[DCTSIZE*3] = (int) RIGHT_SHIFT(tmp13 + tmp0, CONST_BITS-PASS1_BITS);
  252. wsptr[DCTSIZE*4] = (int) RIGHT_SHIFT(tmp13 - tmp0, CONST_BITS-PASS1_BITS);
  253. inptr++; /* advance pointers to next column */
  254. quantptr++;
  255. wsptr++;
  256. }
  257. /* Pass 2: process rows from work array, store into output array. */
  258. /* Note that we must descale the results by a factor of 8 == 2**3, */
  259. /* and also undo the PASS1_BITS scaling. */
  260. wsptr = workspace;
  261. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  262. outptr = output_buf[ctr] + output_col;
  263. /* Rows of zeroes can be exploited in the same way as we did with columns.
  264. * However, the column calculation has created many nonzero AC terms, so
  265. * the simplification applies less often (typically 5% to 10% of the time).
  266. * On machines with very fast multiplication, it's possible that the
  267. * test takes more time than it's worth. In that case this section
  268. * may be commented out.
  269. */
  270. #ifndef NO_ZERO_ROW_TEST
  271. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
  272. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  273. /* AC terms all zero */
  274. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  275. & RANGE_MASK];
  276. outptr[0] = dcval;
  277. outptr[1] = dcval;
  278. outptr[2] = dcval;
  279. outptr[3] = dcval;
  280. outptr[4] = dcval;
  281. outptr[5] = dcval;
  282. outptr[6] = dcval;
  283. outptr[7] = dcval;
  284. wsptr += DCTSIZE; /* advance pointer to next row */
  285. continue;
  286. }
  287. #endif
  288. /* Even part: reverse the even part of the forward DCT. */
  289. /* The rotator is sqrt(2)*c(-6). */
  290. z2 = (INT32) wsptr[2];
  291. z3 = (INT32) wsptr[6];
  292. z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
  293. tmp2 = z1 + MULTIPLY(z2, FIX_0_765366865);
  294. tmp3 = z1 - MULTIPLY(z3, FIX_1_847759065);
  295. /* Add fudge factor here for final descale. */
  296. z2 = (INT32) wsptr[0] + (ONE << (PASS1_BITS+2));
  297. z3 = (INT32) wsptr[4];
  298. tmp0 = (z2 + z3) << CONST_BITS;
  299. tmp1 = (z2 - z3) << CONST_BITS;
  300. tmp10 = tmp0 + tmp2;
  301. tmp13 = tmp0 - tmp2;
  302. tmp11 = tmp1 + tmp3;
  303. tmp12 = tmp1 - tmp3;
  304. /* Odd part per figure 8; the matrix is unitary and hence its
  305. * transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively.
  306. */
  307. tmp0 = (INT32) wsptr[7];
  308. tmp1 = (INT32) wsptr[5];
  309. tmp2 = (INT32) wsptr[3];
  310. tmp3 = (INT32) wsptr[1];
  311. z2 = tmp0 + tmp2;
  312. z3 = tmp1 + tmp3;
  313. z1 = MULTIPLY(z2 + z3, FIX_1_175875602); /* sqrt(2) * c3 */
  314. z2 = MULTIPLY(z2, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  315. z3 = MULTIPLY(z3, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  316. z2 += z1;
  317. z3 += z1;
  318. z1 = MULTIPLY(tmp0 + tmp3, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  319. tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  320. tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  321. tmp0 += z1 + z2;
  322. tmp3 += z1 + z3;
  323. z1 = MULTIPLY(tmp1 + tmp2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  324. tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  325. tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  326. tmp1 += z1 + z3;
  327. tmp2 += z1 + z2;
  328. /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
  329. outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp10 + tmp3,
  330. CONST_BITS+PASS1_BITS+3)
  331. & RANGE_MASK];
  332. outptr[7] = range_limit[(int) RIGHT_SHIFT(tmp10 - tmp3,
  333. CONST_BITS+PASS1_BITS+3)
  334. & RANGE_MASK];
  335. outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp11 + tmp2,
  336. CONST_BITS+PASS1_BITS+3)
  337. & RANGE_MASK];
  338. outptr[6] = range_limit[(int) RIGHT_SHIFT(tmp11 - tmp2,
  339. CONST_BITS+PASS1_BITS+3)
  340. & RANGE_MASK];
  341. outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp12 + tmp1,
  342. CONST_BITS+PASS1_BITS+3)
  343. & RANGE_MASK];
  344. outptr[5] = range_limit[(int) RIGHT_SHIFT(tmp12 - tmp1,
  345. CONST_BITS+PASS1_BITS+3)
  346. & RANGE_MASK];
  347. outptr[3] = range_limit[(int) RIGHT_SHIFT(tmp13 + tmp0,
  348. CONST_BITS+PASS1_BITS+3)
  349. & RANGE_MASK];
  350. outptr[4] = range_limit[(int) RIGHT_SHIFT(tmp13 - tmp0,
  351. CONST_BITS+PASS1_BITS+3)
  352. & RANGE_MASK];
  353. wsptr += DCTSIZE; /* advance pointer to next row */
  354. }
  355. }
  356. #ifdef IDCT_SCALING_SUPPORTED
  357. /*
  358. * Perform dequantization and inverse DCT on one block of coefficients,
  359. * producing a 7x7 output block.
  360. *
  361. * Optimized algorithm with 12 multiplications in the 1-D kernel.
  362. * cK represents sqrt(2) * cos(K*pi/14).
  363. */
  364. GLOBAL(void)
  365. jpeg_idct_7x7 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  366. JCOEFPTR coef_block,
  367. JSAMPARRAY output_buf, JDIMENSION output_col)
  368. {
  369. INT32 tmp0, tmp1, tmp2, tmp10, tmp11, tmp12, tmp13;
  370. INT32 z1, z2, z3;
  371. JCOEFPTR inptr;
  372. ISLOW_MULT_TYPE * quantptr;
  373. int * wsptr;
  374. JSAMPROW outptr;
  375. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  376. int ctr;
  377. int workspace[7*7]; /* buffers data between passes */
  378. SHIFT_TEMPS
  379. /* Pass 1: process columns from input, store into work array. */
  380. inptr = coef_block;
  381. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  382. wsptr = workspace;
  383. for (ctr = 0; ctr < 7; ctr++, inptr++, quantptr++, wsptr++) {
  384. /* Even part */
  385. tmp13 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  386. tmp13 <<= CONST_BITS;
  387. /* Add fudge factor here for final descale. */
  388. tmp13 += ONE << (CONST_BITS-PASS1_BITS-1);
  389. z1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  390. z2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  391. z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  392. tmp10 = MULTIPLY(z2 - z3, FIX(0.881747734)); /* c4 */
  393. tmp12 = MULTIPLY(z1 - z2, FIX(0.314692123)); /* c6 */
  394. tmp11 = tmp10 + tmp12 + tmp13 - MULTIPLY(z2, FIX(1.841218003)); /* c2+c4-c6 */
  395. tmp0 = z1 + z3;
  396. z2 -= tmp0;
  397. tmp0 = MULTIPLY(tmp0, FIX(1.274162392)) + tmp13; /* c2 */
  398. tmp10 += tmp0 - MULTIPLY(z3, FIX(0.077722536)); /* c2-c4-c6 */
  399. tmp12 += tmp0 - MULTIPLY(z1, FIX(2.470602249)); /* c2+c4+c6 */
  400. tmp13 += MULTIPLY(z2, FIX(1.414213562)); /* c0 */
  401. /* Odd part */
  402. z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  403. z2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  404. z3 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  405. tmp1 = MULTIPLY(z1 + z2, FIX(0.935414347)); /* (c3+c1-c5)/2 */
  406. tmp2 = MULTIPLY(z1 - z2, FIX(0.170262339)); /* (c3+c5-c1)/2 */
  407. tmp0 = tmp1 - tmp2;
  408. tmp1 += tmp2;
  409. tmp2 = MULTIPLY(z2 + z3, - FIX(1.378756276)); /* -c1 */
  410. tmp1 += tmp2;
  411. z2 = MULTIPLY(z1 + z3, FIX(0.613604268)); /* c5 */
  412. tmp0 += z2;
  413. tmp2 += z2 + MULTIPLY(z3, FIX(1.870828693)); /* c3+c1-c5 */
  414. /* Final output stage */
  415. wsptr[7*0] = (int) RIGHT_SHIFT(tmp10 + tmp0, CONST_BITS-PASS1_BITS);
  416. wsptr[7*6] = (int) RIGHT_SHIFT(tmp10 - tmp0, CONST_BITS-PASS1_BITS);
  417. wsptr[7*1] = (int) RIGHT_SHIFT(tmp11 + tmp1, CONST_BITS-PASS1_BITS);
  418. wsptr[7*5] = (int) RIGHT_SHIFT(tmp11 - tmp1, CONST_BITS-PASS1_BITS);
  419. wsptr[7*2] = (int) RIGHT_SHIFT(tmp12 + tmp2, CONST_BITS-PASS1_BITS);
  420. wsptr[7*4] = (int) RIGHT_SHIFT(tmp12 - tmp2, CONST_BITS-PASS1_BITS);
  421. wsptr[7*3] = (int) RIGHT_SHIFT(tmp13, CONST_BITS-PASS1_BITS);
  422. }
  423. /* Pass 2: process 7 rows from work array, store into output array. */
  424. wsptr = workspace;
  425. for (ctr = 0; ctr < 7; ctr++) {
  426. outptr = output_buf[ctr] + output_col;
  427. /* Even part */
  428. /* Add fudge factor here for final descale. */
  429. tmp13 = (INT32) wsptr[0] + (ONE << (PASS1_BITS+2));
  430. tmp13 <<= CONST_BITS;
  431. z1 = (INT32) wsptr[2];
  432. z2 = (INT32) wsptr[4];
  433. z3 = (INT32) wsptr[6];
  434. tmp10 = MULTIPLY(z2 - z3, FIX(0.881747734)); /* c4 */
  435. tmp12 = MULTIPLY(z1 - z2, FIX(0.314692123)); /* c6 */
  436. tmp11 = tmp10 + tmp12 + tmp13 - MULTIPLY(z2, FIX(1.841218003)); /* c2+c4-c6 */
  437. tmp0 = z1 + z3;
  438. z2 -= tmp0;
  439. tmp0 = MULTIPLY(tmp0, FIX(1.274162392)) + tmp13; /* c2 */
  440. tmp10 += tmp0 - MULTIPLY(z3, FIX(0.077722536)); /* c2-c4-c6 */
  441. tmp12 += tmp0 - MULTIPLY(z1, FIX(2.470602249)); /* c2+c4+c6 */
  442. tmp13 += MULTIPLY(z2, FIX(1.414213562)); /* c0 */
  443. /* Odd part */
  444. z1 = (INT32) wsptr[1];
  445. z2 = (INT32) wsptr[3];
  446. z3 = (INT32) wsptr[5];
  447. tmp1 = MULTIPLY(z1 + z2, FIX(0.935414347)); /* (c3+c1-c5)/2 */
  448. tmp2 = MULTIPLY(z1 - z2, FIX(0.170262339)); /* (c3+c5-c1)/2 */
  449. tmp0 = tmp1 - tmp2;
  450. tmp1 += tmp2;
  451. tmp2 = MULTIPLY(z2 + z3, - FIX(1.378756276)); /* -c1 */
  452. tmp1 += tmp2;
  453. z2 = MULTIPLY(z1 + z3, FIX(0.613604268)); /* c5 */
  454. tmp0 += z2;
  455. tmp2 += z2 + MULTIPLY(z3, FIX(1.870828693)); /* c3+c1-c5 */
  456. /* Final output stage */
  457. outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp10 + tmp0,
  458. CONST_BITS+PASS1_BITS+3)
  459. & RANGE_MASK];
  460. outptr[6] = range_limit[(int) RIGHT_SHIFT(tmp10 - tmp0,
  461. CONST_BITS+PASS1_BITS+3)
  462. & RANGE_MASK];
  463. outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp11 + tmp1,
  464. CONST_BITS+PASS1_BITS+3)
  465. & RANGE_MASK];
  466. outptr[5] = range_limit[(int) RIGHT_SHIFT(tmp11 - tmp1,
  467. CONST_BITS+PASS1_BITS+3)
  468. & RANGE_MASK];
  469. outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp12 + tmp2,
  470. CONST_BITS+PASS1_BITS+3)
  471. & RANGE_MASK];
  472. outptr[4] = range_limit[(int) RIGHT_SHIFT(tmp12 - tmp2,
  473. CONST_BITS+PASS1_BITS+3)
  474. & RANGE_MASK];
  475. outptr[3] = range_limit[(int) RIGHT_SHIFT(tmp13,
  476. CONST_BITS+PASS1_BITS+3)
  477. & RANGE_MASK];
  478. wsptr += 7; /* advance pointer to next row */
  479. }
  480. }
  481. /*
  482. * Perform dequantization and inverse DCT on one block of coefficients,
  483. * producing a reduced-size 6x6 output block.
  484. *
  485. * Optimized algorithm with 3 multiplications in the 1-D kernel.
  486. * cK represents sqrt(2) * cos(K*pi/12).
  487. */
  488. GLOBAL(void)
  489. jpeg_idct_6x6 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  490. JCOEFPTR coef_block,
  491. JSAMPARRAY output_buf, JDIMENSION output_col)
  492. {
  493. INT32 tmp0, tmp1, tmp2, tmp10, tmp11, tmp12;
  494. INT32 z1, z2, z3;
  495. JCOEFPTR inptr;
  496. ISLOW_MULT_TYPE * quantptr;
  497. int * wsptr;
  498. JSAMPROW outptr;
  499. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  500. int ctr;
  501. int workspace[6*6]; /* buffers data between passes */
  502. SHIFT_TEMPS
  503. /* Pass 1: process columns from input, store into work array. */
  504. inptr = coef_block;
  505. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  506. wsptr = workspace;
  507. for (ctr = 0; ctr < 6; ctr++, inptr++, quantptr++, wsptr++) {
  508. /* Even part */
  509. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  510. tmp0 <<= CONST_BITS;
  511. /* Add fudge factor here for final descale. */
  512. tmp0 += ONE << (CONST_BITS-PASS1_BITS-1);
  513. tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  514. tmp10 = MULTIPLY(tmp2, FIX(0.707106781)); /* c4 */
  515. tmp1 = tmp0 + tmp10;
  516. tmp11 = RIGHT_SHIFT(tmp0 - tmp10 - tmp10, CONST_BITS-PASS1_BITS);
  517. tmp10 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  518. tmp0 = MULTIPLY(tmp10, FIX(1.224744871)); /* c2 */
  519. tmp10 = tmp1 + tmp0;
  520. tmp12 = tmp1 - tmp0;
  521. /* Odd part */
  522. z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  523. z2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  524. z3 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  525. tmp1 = MULTIPLY(z1 + z3, FIX(0.366025404)); /* c5 */
  526. tmp0 = tmp1 + ((z1 + z2) << CONST_BITS);
  527. tmp2 = tmp1 + ((z3 - z2) << CONST_BITS);
  528. tmp1 = (z1 - z2 - z3) << PASS1_BITS;
  529. /* Final output stage */
  530. wsptr[6*0] = (int) RIGHT_SHIFT(tmp10 + tmp0, CONST_BITS-PASS1_BITS);
  531. wsptr[6*5] = (int) RIGHT_SHIFT(tmp10 - tmp0, CONST_BITS-PASS1_BITS);
  532. wsptr[6*1] = (int) (tmp11 + tmp1);
  533. wsptr[6*4] = (int) (tmp11 - tmp1);
  534. wsptr[6*2] = (int) RIGHT_SHIFT(tmp12 + tmp2, CONST_BITS-PASS1_BITS);
  535. wsptr[6*3] = (int) RIGHT_SHIFT(tmp12 - tmp2, CONST_BITS-PASS1_BITS);
  536. }
  537. /* Pass 2: process 6 rows from work array, store into output array. */
  538. wsptr = workspace;
  539. for (ctr = 0; ctr < 6; ctr++) {
  540. outptr = output_buf[ctr] + output_col;
  541. /* Even part */
  542. /* Add fudge factor here for final descale. */
  543. tmp0 = (INT32) wsptr[0] + (ONE << (PASS1_BITS+2));
  544. tmp0 <<= CONST_BITS;
  545. tmp2 = (INT32) wsptr[4];
  546. tmp10 = MULTIPLY(tmp2, FIX(0.707106781)); /* c4 */
  547. tmp1 = tmp0 + tmp10;
  548. tmp11 = tmp0 - tmp10 - tmp10;
  549. tmp10 = (INT32) wsptr[2];
  550. tmp0 = MULTIPLY(tmp10, FIX(1.224744871)); /* c2 */
  551. tmp10 = tmp1 + tmp0;
  552. tmp12 = tmp1 - tmp0;
  553. /* Odd part */
  554. z1 = (INT32) wsptr[1];
  555. z2 = (INT32) wsptr[3];
  556. z3 = (INT32) wsptr[5];
  557. tmp1 = MULTIPLY(z1 + z3, FIX(0.366025404)); /* c5 */
  558. tmp0 = tmp1 + ((z1 + z2) << CONST_BITS);
  559. tmp2 = tmp1 + ((z3 - z2) << CONST_BITS);
  560. tmp1 = (z1 - z2 - z3) << CONST_BITS;
  561. /* Final output stage */
  562. outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp10 + tmp0,
  563. CONST_BITS+PASS1_BITS+3)
  564. & RANGE_MASK];
  565. outptr[5] = range_limit[(int) RIGHT_SHIFT(tmp10 - tmp0,
  566. CONST_BITS+PASS1_BITS+3)
  567. & RANGE_MASK];
  568. outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp11 + tmp1,
  569. CONST_BITS+PASS1_BITS+3)
  570. & RANGE_MASK];
  571. outptr[4] = range_limit[(int) RIGHT_SHIFT(tmp11 - tmp1,
  572. CONST_BITS+PASS1_BITS+3)
  573. & RANGE_MASK];
  574. outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp12 + tmp2,
  575. CONST_BITS+PASS1_BITS+3)
  576. & RANGE_MASK];
  577. outptr[3] = range_limit[(int) RIGHT_SHIFT(tmp12 - tmp2,
  578. CONST_BITS+PASS1_BITS+3)
  579. & RANGE_MASK];
  580. wsptr += 6; /* advance pointer to next row */
  581. }
  582. }
  583. /*
  584. * Perform dequantization and inverse DCT on one block of coefficients,
  585. * producing a reduced-size 5x5 output block.
  586. *
  587. * Optimized algorithm with 5 multiplications in the 1-D kernel.
  588. * cK represents sqrt(2) * cos(K*pi/10).
  589. */
  590. GLOBAL(void)
  591. jpeg_idct_5x5 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  592. JCOEFPTR coef_block,
  593. JSAMPARRAY output_buf, JDIMENSION output_col)
  594. {
  595. INT32 tmp0, tmp1, tmp10, tmp11, tmp12;
  596. INT32 z1, z2, z3;
  597. JCOEFPTR inptr;
  598. ISLOW_MULT_TYPE * quantptr;
  599. int * wsptr;
  600. JSAMPROW outptr;
  601. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  602. int ctr;
  603. int workspace[5*5]; /* buffers data between passes */
  604. SHIFT_TEMPS
  605. /* Pass 1: process columns from input, store into work array. */
  606. inptr = coef_block;
  607. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  608. wsptr = workspace;
  609. for (ctr = 0; ctr < 5; ctr++, inptr++, quantptr++, wsptr++) {
  610. /* Even part */
  611. tmp12 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  612. tmp12 <<= CONST_BITS;
  613. /* Add fudge factor here for final descale. */
  614. tmp12 += ONE << (CONST_BITS-PASS1_BITS-1);
  615. tmp0 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  616. tmp1 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  617. z1 = MULTIPLY(tmp0 + tmp1, FIX(0.790569415)); /* (c2+c4)/2 */
  618. z2 = MULTIPLY(tmp0 - tmp1, FIX(0.353553391)); /* (c2-c4)/2 */
  619. z3 = tmp12 + z2;
  620. tmp10 = z3 + z1;
  621. tmp11 = z3 - z1;
  622. tmp12 -= z2 << 2;
  623. /* Odd part */
  624. z2 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  625. z3 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  626. z1 = MULTIPLY(z2 + z3, FIX(0.831253876)); /* c3 */
  627. tmp0 = z1 + MULTIPLY(z2, FIX(0.513743148)); /* c1-c3 */
  628. tmp1 = z1 - MULTIPLY(z3, FIX(2.176250899)); /* c1+c3 */
  629. /* Final output stage */
  630. wsptr[5*0] = (int) RIGHT_SHIFT(tmp10 + tmp0, CONST_BITS-PASS1_BITS);
  631. wsptr[5*4] = (int) RIGHT_SHIFT(tmp10 - tmp0, CONST_BITS-PASS1_BITS);
  632. wsptr[5*1] = (int) RIGHT_SHIFT(tmp11 + tmp1, CONST_BITS-PASS1_BITS);
  633. wsptr[5*3] = (int) RIGHT_SHIFT(tmp11 - tmp1, CONST_BITS-PASS1_BITS);
  634. wsptr[5*2] = (int) RIGHT_SHIFT(tmp12, CONST_BITS-PASS1_BITS);
  635. }
  636. /* Pass 2: process 5 rows from work array, store into output array. */
  637. wsptr = workspace;
  638. for (ctr = 0; ctr < 5; ctr++) {
  639. outptr = output_buf[ctr] + output_col;
  640. /* Even part */
  641. /* Add fudge factor here for final descale. */
  642. tmp12 = (INT32) wsptr[0] + (ONE << (PASS1_BITS+2));
  643. tmp12 <<= CONST_BITS;
  644. tmp0 = (INT32) wsptr[2];
  645. tmp1 = (INT32) wsptr[4];
  646. z1 = MULTIPLY(tmp0 + tmp1, FIX(0.790569415)); /* (c2+c4)/2 */
  647. z2 = MULTIPLY(tmp0 - tmp1, FIX(0.353553391)); /* (c2-c4)/2 */
  648. z3 = tmp12 + z2;
  649. tmp10 = z3 + z1;
  650. tmp11 = z3 - z1;
  651. tmp12 -= z2 << 2;
  652. /* Odd part */
  653. z2 = (INT32) wsptr[1];
  654. z3 = (INT32) wsptr[3];
  655. z1 = MULTIPLY(z2 + z3, FIX(0.831253876)); /* c3 */
  656. tmp0 = z1 + MULTIPLY(z2, FIX(0.513743148)); /* c1-c3 */
  657. tmp1 = z1 - MULTIPLY(z3, FIX(2.176250899)); /* c1+c3 */
  658. /* Final output stage */
  659. outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp10 + tmp0,
  660. CONST_BITS+PASS1_BITS+3)
  661. & RANGE_MASK];
  662. outptr[4] = range_limit[(int) RIGHT_SHIFT(tmp10 - tmp0,
  663. CONST_BITS+PASS1_BITS+3)
  664. & RANGE_MASK];
  665. outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp11 + tmp1,
  666. CONST_BITS+PASS1_BITS+3)
  667. & RANGE_MASK];
  668. outptr[3] = range_limit[(int) RIGHT_SHIFT(tmp11 - tmp1,
  669. CONST_BITS+PASS1_BITS+3)
  670. & RANGE_MASK];
  671. outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp12,
  672. CONST_BITS+PASS1_BITS+3)
  673. & RANGE_MASK];
  674. wsptr += 5; /* advance pointer to next row */
  675. }
  676. }
  677. /*
  678. * Perform dequantization and inverse DCT on one block of coefficients,
  679. * producing a reduced-size 4x4 output block.
  680. *
  681. * Optimized algorithm with 3 multiplications in the 1-D kernel.
  682. * cK represents sqrt(2) * cos(K*pi/16) [refers to 8-point IDCT].
  683. */
  684. GLOBAL(void)
  685. jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  686. JCOEFPTR coef_block,
  687. JSAMPARRAY output_buf, JDIMENSION output_col)
  688. {
  689. INT32 tmp0, tmp2, tmp10, tmp12;
  690. INT32 z1, z2, z3;
  691. JCOEFPTR inptr;
  692. ISLOW_MULT_TYPE * quantptr;
  693. int * wsptr;
  694. JSAMPROW outptr;
  695. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  696. int ctr;
  697. int workspace[4*4]; /* buffers data between passes */
  698. SHIFT_TEMPS
  699. /* Pass 1: process columns from input, store into work array. */
  700. inptr = coef_block;
  701. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  702. wsptr = workspace;
  703. for (ctr = 0; ctr < 4; ctr++, inptr++, quantptr++, wsptr++) {
  704. /* Even part */
  705. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  706. tmp2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  707. tmp10 = (tmp0 + tmp2) << PASS1_BITS;
  708. tmp12 = (tmp0 - tmp2) << PASS1_BITS;
  709. /* Odd part */
  710. /* Same rotation as in the even part of the 8x8 LL&M IDCT */
  711. z2 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  712. z3 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  713. z1 = MULTIPLY(z2 + z3, FIX_0_541196100); /* c6 */
  714. /* Add fudge factor here for final descale. */
  715. z1 += ONE << (CONST_BITS-PASS1_BITS-1);
  716. tmp0 = RIGHT_SHIFT(z1 + MULTIPLY(z2, FIX_0_765366865), /* c2-c6 */
  717. CONST_BITS-PASS1_BITS);
  718. tmp2 = RIGHT_SHIFT(z1 - MULTIPLY(z3, FIX_1_847759065), /* c2+c6 */
  719. CONST_BITS-PASS1_BITS);
  720. /* Final output stage */
  721. wsptr[4*0] = (int) (tmp10 + tmp0);
  722. wsptr[4*3] = (int) (tmp10 - tmp0);
  723. wsptr[4*1] = (int) (tmp12 + tmp2);
  724. wsptr[4*2] = (int) (tmp12 - tmp2);
  725. }
  726. /* Pass 2: process 4 rows from work array, store into output array. */
  727. wsptr = workspace;
  728. for (ctr = 0; ctr < 4; ctr++) {
  729. outptr = output_buf[ctr] + output_col;
  730. /* Even part */
  731. /* Add fudge factor here for final descale. */
  732. tmp0 = (INT32) wsptr[0] + (ONE << (PASS1_BITS+2));
  733. tmp2 = (INT32) wsptr[2];
  734. tmp10 = (tmp0 + tmp2) << CONST_BITS;
  735. tmp12 = (tmp0 - tmp2) << CONST_BITS;
  736. /* Odd part */
  737. /* Same rotation as in the even part of the 8x8 LL&M IDCT */
  738. z2 = (INT32) wsptr[1];
  739. z3 = (INT32) wsptr[3];
  740. z1 = MULTIPLY(z2 + z3, FIX_0_541196100); /* c6 */
  741. tmp0 = z1 + MULTIPLY(z2, FIX_0_765366865); /* c2-c6 */
  742. tmp2 = z1 - MULTIPLY(z3, FIX_1_847759065); /* c2+c6 */
  743. /* Final output stage */
  744. outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp10 + tmp0,
  745. CONST_BITS+PASS1_BITS+3)
  746. & RANGE_MASK];
  747. outptr[3] = range_limit[(int) RIGHT_SHIFT(tmp10 - tmp0,
  748. CONST_BITS+PASS1_BITS+3)
  749. & RANGE_MASK];
  750. outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp12 + tmp2,
  751. CONST_BITS+PASS1_BITS+3)
  752. & RANGE_MASK];
  753. outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp12 - tmp2,
  754. CONST_BITS+PASS1_BITS+3)
  755. & RANGE_MASK];
  756. wsptr += 4; /* advance pointer to next row */
  757. }
  758. }
  759. /*
  760. * Perform dequantization and inverse DCT on one block of coefficients,
  761. * producing a reduced-size 3x3 output block.
  762. *
  763. * Optimized algorithm with 2 multiplications in the 1-D kernel.
  764. * cK represents sqrt(2) * cos(K*pi/6).
  765. */
  766. GLOBAL(void)
  767. jpeg_idct_3x3 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  768. JCOEFPTR coef_block,
  769. JSAMPARRAY output_buf, JDIMENSION output_col)
  770. {
  771. INT32 tmp0, tmp2, tmp10, tmp12;
  772. JCOEFPTR inptr;
  773. ISLOW_MULT_TYPE * quantptr;
  774. int * wsptr;
  775. JSAMPROW outptr;
  776. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  777. int ctr;
  778. int workspace[3*3]; /* buffers data between passes */
  779. SHIFT_TEMPS
  780. /* Pass 1: process columns from input, store into work array. */
  781. inptr = coef_block;
  782. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  783. wsptr = workspace;
  784. for (ctr = 0; ctr < 3; ctr++, inptr++, quantptr++, wsptr++) {
  785. /* Even part */
  786. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  787. tmp0 <<= CONST_BITS;
  788. /* Add fudge factor here for final descale. */
  789. tmp0 += ONE << (CONST_BITS-PASS1_BITS-1);
  790. tmp2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  791. tmp12 = MULTIPLY(tmp2, FIX(0.707106781)); /* c2 */
  792. tmp10 = tmp0 + tmp12;
  793. tmp2 = tmp0 - tmp12 - tmp12;
  794. /* Odd part */
  795. tmp12 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  796. tmp0 = MULTIPLY(tmp12, FIX(1.224744871)); /* c1 */
  797. /* Final output stage */
  798. wsptr[3*0] = (int) RIGHT_SHIFT(tmp10 + tmp0, CONST_BITS-PASS1_BITS);
  799. wsptr[3*2] = (int) RIGHT_SHIFT(tmp10 - tmp0, CONST_BITS-PASS1_BITS);
  800. wsptr[3*1] = (int) RIGHT_SHIFT(tmp2, CONST_BITS-PASS1_BITS);
  801. }
  802. /* Pass 2: process 3 rows from work array, store into output array. */
  803. wsptr = workspace;
  804. for (ctr = 0; ctr < 3; ctr++) {
  805. outptr = output_buf[ctr] + output_col;
  806. /* Even part */
  807. /* Add fudge factor here for final descale. */
  808. tmp0 = (INT32) wsptr[0] + (ONE << (PASS1_BITS+2));
  809. tmp0 <<= CONST_BITS;
  810. tmp2 = (INT32) wsptr[2];
  811. tmp12 = MULTIPLY(tmp2, FIX(0.707106781)); /* c2 */
  812. tmp10 = tmp0 + tmp12;
  813. tmp2 = tmp0 - tmp12 - tmp12;
  814. /* Odd part */
  815. tmp12 = (INT32) wsptr[1];
  816. tmp0 = MULTIPLY(tmp12, FIX(1.224744871)); /* c1 */
  817. /* Final output stage */
  818. outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp10 + tmp0,
  819. CONST_BITS+PASS1_BITS+3)
  820. & RANGE_MASK];
  821. outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp10 - tmp0,
  822. CONST_BITS+PASS1_BITS+3)
  823. & RANGE_MASK];
  824. outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp2,
  825. CONST_BITS+PASS1_BITS+3)
  826. & RANGE_MASK];
  827. wsptr += 3; /* advance pointer to next row */
  828. }
  829. }
  830. /*
  831. * Perform dequantization and inverse DCT on one block of coefficients,
  832. * producing a reduced-size 2x2 output block.
  833. *
  834. * Multiplication-less algorithm.
  835. */
  836. GLOBAL(void)
  837. jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  838. JCOEFPTR coef_block,
  839. JSAMPARRAY output_buf, JDIMENSION output_col)
  840. {
  841. INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5;
  842. ISLOW_MULT_TYPE * quantptr;
  843. JSAMPROW outptr;
  844. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  845. SHIFT_TEMPS
  846. /* Pass 1: process columns from input. */
  847. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  848. /* Column 0 */
  849. tmp4 = DEQUANTIZE(coef_block[DCTSIZE*0], quantptr[DCTSIZE*0]);
  850. tmp5 = DEQUANTIZE(coef_block[DCTSIZE*1], quantptr[DCTSIZE*1]);
  851. /* Add fudge factor here for final descale. */
  852. tmp4 += ONE << 2;
  853. tmp0 = tmp4 + tmp5;
  854. tmp2 = tmp4 - tmp5;
  855. /* Column 1 */
  856. tmp4 = DEQUANTIZE(coef_block[DCTSIZE*0+1], quantptr[DCTSIZE*0+1]);
  857. tmp5 = DEQUANTIZE(coef_block[DCTSIZE*1+1], quantptr[DCTSIZE*1+1]);
  858. tmp1 = tmp4 + tmp5;
  859. tmp3 = tmp4 - tmp5;
  860. /* Pass 2: process 2 rows, store into output array. */
  861. /* Row 0 */
  862. outptr = output_buf[0] + output_col;
  863. outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp0 + tmp1, 3) & RANGE_MASK];
  864. outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp0 - tmp1, 3) & RANGE_MASK];
  865. /* Row 1 */
  866. outptr = output_buf[1] + output_col;
  867. outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp2 + tmp3, 3) & RANGE_MASK];
  868. outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp2 - tmp3, 3) & RANGE_MASK];
  869. }
  870. /*
  871. * Perform dequantization and inverse DCT on one block of coefficients,
  872. * producing a reduced-size 1x1 output block.
  873. *
  874. * We hardly need an inverse DCT routine for this: just take the
  875. * average pixel value, which is one-eighth of the DC coefficient.
  876. */
  877. GLOBAL(void)
  878. jpeg_idct_1x1 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  879. JCOEFPTR coef_block,
  880. JSAMPARRAY output_buf, JDIMENSION output_col)
  881. {
  882. int dcval;
  883. ISLOW_MULT_TYPE * quantptr;
  884. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  885. SHIFT_TEMPS
  886. /* 1x1 is trivial: just take the DC coefficient divided by 8. */
  887. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  888. dcval = DEQUANTIZE(coef_block[0], quantptr[0]);
  889. dcval = (int) DESCALE((INT32) dcval, 3);
  890. output_buf[0][output_col] = range_limit[dcval & RANGE_MASK];
  891. }
  892. /*
  893. * Perform dequantization and inverse DCT on one block of coefficients,
  894. * producing a 9x9 output block.
  895. *
  896. * Optimized algorithm with 10 multiplications in the 1-D kernel.
  897. * cK represents sqrt(2) * cos(K*pi/18).
  898. */
  899. GLOBAL(void)
  900. jpeg_idct_9x9 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  901. JCOEFPTR coef_block,
  902. JSAMPARRAY output_buf, JDIMENSION output_col)
  903. {
  904. INT32 tmp0, tmp1, tmp2, tmp3, tmp10, tmp11, tmp12, tmp13, tmp14;
  905. INT32 z1, z2, z3, z4;
  906. JCOEFPTR inptr;
  907. ISLOW_MULT_TYPE * quantptr;
  908. int * wsptr;
  909. JSAMPROW outptr;
  910. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  911. int ctr;
  912. int workspace[8*9]; /* buffers data between passes */
  913. SHIFT_TEMPS
  914. /* Pass 1: process columns from input, store into work array. */
  915. inptr = coef_block;
  916. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  917. wsptr = workspace;
  918. for (ctr = 0; ctr < 8; ctr++, inptr++, quantptr++, wsptr++) {
  919. /* Even part */
  920. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  921. tmp0 <<= CONST_BITS;
  922. /* Add fudge factor here for final descale. */
  923. tmp0 += ONE << (CONST_BITS-PASS1_BITS-1);
  924. z1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  925. z2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  926. z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  927. tmp3 = MULTIPLY(z3, FIX(0.707106781)); /* c6 */
  928. tmp1 = tmp0 + tmp3;
  929. tmp2 = tmp0 - tmp3 - tmp3;
  930. tmp0 = MULTIPLY(z1 - z2, FIX(0.707106781)); /* c6 */
  931. tmp11 = tmp2 + tmp0;
  932. tmp14 = tmp2 - tmp0 - tmp0;
  933. tmp0 = MULTIPLY(z1 + z2, FIX(1.328926049)); /* c2 */
  934. tmp2 = MULTIPLY(z1, FIX(1.083350441)); /* c4 */
  935. tmp3 = MULTIPLY(z2, FIX(0.245575608)); /* c8 */
  936. tmp10 = tmp1 + tmp0 - tmp3;
  937. tmp12 = tmp1 - tmp0 + tmp2;
  938. tmp13 = tmp1 - tmp2 + tmp3;
  939. /* Odd part */
  940. z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  941. z2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  942. z3 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  943. z4 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  944. z2 = MULTIPLY(z2, - FIX(1.224744871)); /* -c3 */
  945. tmp2 = MULTIPLY(z1 + z3, FIX(0.909038955)); /* c5 */
  946. tmp3 = MULTIPLY(z1 + z4, FIX(0.483689525)); /* c7 */
  947. tmp0 = tmp2 + tmp3 - z2;
  948. tmp1 = MULTIPLY(z3 - z4, FIX(1.392728481)); /* c1 */
  949. tmp2 += z2 - tmp1;
  950. tmp3 += z2 + tmp1;
  951. tmp1 = MULTIPLY(z1 - z3 - z4, FIX(1.224744871)); /* c3 */
  952. /* Final output stage */
  953. wsptr[8*0] = (int) RIGHT_SHIFT(tmp10 + tmp0, CONST_BITS-PASS1_BITS);
  954. wsptr[8*8] = (int) RIGHT_SHIFT(tmp10 - tmp0, CONST_BITS-PASS1_BITS);
  955. wsptr[8*1] = (int) RIGHT_SHIFT(tmp11 + tmp1, CONST_BITS-PASS1_BITS);
  956. wsptr[8*7] = (int) RIGHT_SHIFT(tmp11 - tmp1, CONST_BITS-PASS1_BITS);
  957. wsptr[8*2] = (int) RIGHT_SHIFT(tmp12 + tmp2, CONST_BITS-PASS1_BITS);
  958. wsptr[8*6] = (int) RIGHT_SHIFT(tmp12 - tmp2, CONST_BITS-PASS1_BITS);
  959. wsptr[8*3] = (int) RIGHT_SHIFT(tmp13 + tmp3, CONST_BITS-PASS1_BITS);
  960. wsptr[8*5] = (int) RIGHT_SHIFT(tmp13 - tmp3, CONST_BITS-PASS1_BITS);
  961. wsptr[8*4] = (int) RIGHT_SHIFT(tmp14, CONST_BITS-PASS1_BITS);
  962. }
  963. /* Pass 2: process 9 rows from work array, store into output array. */
  964. wsptr = workspace;
  965. for (ctr = 0; ctr < 9; ctr++) {
  966. outptr = output_buf[ctr] + output_col;
  967. /* Even part */
  968. /* Add fudge factor here for final descale. */
  969. tmp0 = (INT32) wsptr[0] + (ONE << (PASS1_BITS+2));
  970. tmp0 <<= CONST_BITS;
  971. z1 = (INT32) wsptr[2];
  972. z2 = (INT32) wsptr[4];
  973. z3 = (INT32) wsptr[6];
  974. tmp3 = MULTIPLY(z3, FIX(0.707106781)); /* c6 */
  975. tmp1 = tmp0 + tmp3;
  976. tmp2 = tmp0 - tmp3 - tmp3;
  977. tmp0 = MULTIPLY(z1 - z2, FIX(0.707106781)); /* c6 */
  978. tmp11 = tmp2 + tmp0;
  979. tmp14 = tmp2 - tmp0 - tmp0;
  980. tmp0 = MULTIPLY(z1 + z2, FIX(1.328926049)); /* c2 */
  981. tmp2 = MULTIPLY(z1, FIX(1.083350441)); /* c4 */
  982. tmp3 = MULTIPLY(z2, FIX(0.245575608)); /* c8 */
  983. tmp10 = tmp1 + tmp0 - tmp3;
  984. tmp12 = tmp1 - tmp0 + tmp2;
  985. tmp13 = tmp1 - tmp2 + tmp3;
  986. /* Odd part */
  987. z1 = (INT32) wsptr[1];
  988. z2 = (INT32) wsptr[3];
  989. z3 = (INT32) wsptr[5];
  990. z4 = (INT32) wsptr[7];
  991. z2 = MULTIPLY(z2, - FIX(1.224744871)); /* -c3 */
  992. tmp2 = MULTIPLY(z1 + z3, FIX(0.909038955)); /* c5 */
  993. tmp3 = MULTIPLY(z1 + z4, FIX(0.483689525)); /* c7 */
  994. tmp0 = tmp2 + tmp3 - z2;
  995. tmp1 = MULTIPLY(z3 - z4, FIX(1.392728481)); /* c1 */
  996. tmp2 += z2 - tmp1;
  997. tmp3 += z2 + tmp1;
  998. tmp1 = MULTIPLY(z1 - z3 - z4, FIX(1.224744871)); /* c3 */
  999. /* Final output stage */
  1000. outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp10 + tmp0,
  1001. CONST_BITS+PASS1_BITS+3)
  1002. & RANGE_MASK];
  1003. outptr[8] = range_limit[(int) RIGHT_SHIFT(tmp10 - tmp0,
  1004. CONST_BITS+PASS1_BITS+3)
  1005. & RANGE_MASK];
  1006. outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp11 + tmp1,
  1007. CONST_BITS+PASS1_BITS+3)
  1008. & RANGE_MASK];
  1009. outptr[7] = range_limit[(int) RIGHT_SHIFT(tmp11 - tmp1,
  1010. CONST_BITS+PASS1_BITS+3)
  1011. & RANGE_MASK];
  1012. outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp12 + tmp2,
  1013. CONST_BITS+PASS1_BITS+3)
  1014. & RANGE_MASK];
  1015. outptr[6] = range_limit[(int) RIGHT_SHIFT(tmp12 - tmp2,
  1016. CONST_BITS+PASS1_BITS+3)
  1017. & RANGE_MASK];
  1018. outptr[3] = range_limit[(int) RIGHT_SHIFT(tmp13 + tmp3,
  1019. CONST_BITS+PASS1_BITS+3)
  1020. & RANGE_MASK];
  1021. outptr[5] = range_limit[(int) RIGHT_SHIFT(tmp13 - tmp3,
  1022. CONST_BITS+PASS1_BITS+3)
  1023. & RANGE_MASK];
  1024. outptr[4] = range_limit[(int) RIGHT_SHIFT(tmp14,
  1025. CONST_BITS+PASS1_BITS+3)
  1026. & RANGE_MASK];
  1027. wsptr += 8; /* advance pointer to next row */
  1028. }
  1029. }
  1030. /*
  1031. * Perform dequantization and inverse DCT on one block of coefficients,
  1032. * producing a 10x10 output block.
  1033. *
  1034. * Optimized algorithm with 12 multiplications in the 1-D kernel.
  1035. * cK represents sqrt(2) * cos(K*pi/20).
  1036. */
  1037. GLOBAL(void)
  1038. jpeg_idct_10x10 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  1039. JCOEFPTR coef_block,
  1040. JSAMPARRAY output_buf, JDIMENSION output_col)
  1041. {
  1042. INT32 tmp10, tmp11, tmp12, tmp13, tmp14;
  1043. INT32 tmp20, tmp21, tmp22, tmp23, tmp24;
  1044. INT32 z1, z2, z3, z4, z5;
  1045. JCOEFPTR inptr;
  1046. ISLOW_MULT_TYPE * quantptr;
  1047. int * wsptr;
  1048. JSAMPROW outptr;
  1049. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  1050. int ctr;
  1051. int workspace[8*10]; /* buffers data between passes */
  1052. SHIFT_TEMPS
  1053. /* Pass 1: process columns from input, store into work array. */
  1054. inptr = coef_block;
  1055. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  1056. wsptr = workspace;
  1057. for (ctr = 0; ctr < 8; ctr++, inptr++, quantptr++, wsptr++) {
  1058. /* Even part */
  1059. z3 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  1060. z3 <<= CONST_BITS;
  1061. /* Add fudge factor here for final descale. */
  1062. z3 += ONE << (CONST_BITS-PASS1_BITS-1);
  1063. z4 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  1064. z1 = MULTIPLY(z4, FIX(1.144122806)); /* c4 */
  1065. z2 = MULTIPLY(z4, FIX(0.437016024)); /* c8 */
  1066. tmp10 = z3 + z1;
  1067. tmp11 = z3 - z2;
  1068. tmp22 = RIGHT_SHIFT(z3 - ((z1 - z2) << 1), /* c0 = (c4-c8)*2 */
  1069. CONST_BITS-PASS1_BITS);
  1070. z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  1071. z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  1072. z1 = MULTIPLY(z2 + z3, FIX(0.831253876)); /* c6 */
  1073. tmp12 = z1 + MULTIPLY(z2, FIX(0.513743148)); /* c2-c6 */
  1074. tmp13 = z1 - MULTIPLY(z3, FIX(2.176250899)); /* c2+c6 */
  1075. tmp20 = tmp10 + tmp12;
  1076. tmp24 = tmp10 - tmp12;
  1077. tmp21 = tmp11 + tmp13;
  1078. tmp23 = tmp11 - tmp13;
  1079. /* Odd part */
  1080. z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  1081. z2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  1082. z3 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  1083. z4 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  1084. tmp11 = z2 + z4;
  1085. tmp13 = z2 - z4;
  1086. tmp12 = MULTIPLY(tmp13, FIX(0.309016994)); /* (c3-c7)/2 */
  1087. z5 = z3 << CONST_BITS;
  1088. z2 = MULTIPLY(tmp11, FIX(0.951056516)); /* (c3+c7)/2 */
  1089. z4 = z5 + tmp12;
  1090. tmp10 = MULTIPLY(z1, FIX(1.396802247)) + z2 + z4; /* c1 */
  1091. tmp14 = MULTIPLY(z1, FIX(0.221231742)) - z2 + z4; /* c9 */
  1092. z2 = MULTIPLY(tmp11, FIX(0.587785252)); /* (c1-c9)/2 */
  1093. z4 = z5 - tmp12 - (tmp13 << (CONST_BITS - 1));
  1094. tmp12 = (z1 - tmp13 - z3) << PASS1_BITS;
  1095. tmp11 = MULTIPLY(z1, FIX(1.260073511)) - z2 - z4; /* c3 */
  1096. tmp13 = MULTIPLY(z1, FIX(0.642039522)) - z2 + z4; /* c7 */
  1097. /* Final output stage */
  1098. wsptr[8*0] = (int) RIGHT_SHIFT(tmp20 + tmp10, CONST_BITS-PASS1_BITS);
  1099. wsptr[8*9] = (int) RIGHT_SHIFT(tmp20 - tmp10, CONST_BITS-PASS1_BITS);
  1100. wsptr[8*1] = (int) RIGHT_SHIFT(tmp21 + tmp11, CONST_BITS-PASS1_BITS);
  1101. wsptr[8*8] = (int) RIGHT_SHIFT(tmp21 - tmp11, CONST_BITS-PASS1_BITS);
  1102. wsptr[8*2] = (int) (tmp22 + tmp12);
  1103. wsptr[8*7] = (int) (tmp22 - tmp12);
  1104. wsptr[8*3] = (int) RIGHT_SHIFT(tmp23 + tmp13, CONST_BITS-PASS1_BITS);
  1105. wsptr[8*6] = (int) RIGHT_SHIFT(tmp23 - tmp13, CONST_BITS-PASS1_BITS);
  1106. wsptr[8*4] = (int) RIGHT_SHIFT(tmp24 + tmp14, CONST_BITS-PASS1_BITS);
  1107. wsptr[8*5] = (int) RIGHT_SHIFT(tmp24 - tmp14, CONST_BITS-PASS1_BITS);
  1108. }
  1109. /* Pass 2: process 10 rows from work array, store into output array. */
  1110. wsptr = workspace;
  1111. for (ctr = 0; ctr < 10; ctr++) {
  1112. outptr = output_buf[ctr] + output_col;
  1113. /* Even part */
  1114. /* Add fudge factor here for final descale. */
  1115. z3 = (INT32) wsptr[0] + (ONE << (PASS1_BITS+2));
  1116. z3 <<= CONST_BITS;
  1117. z4 = (INT32) wsptr[4];
  1118. z1 = MULTIPLY(z4, FIX(1.144122806)); /* c4 */
  1119. z2 = MULTIPLY(z4, FIX(0.437016024)); /* c8 */
  1120. tmp10 = z3 + z1;
  1121. tmp11 = z3 - z2;
  1122. tmp22 = z3 - ((z1 - z2) << 1); /* c0 = (c4-c8)*2 */
  1123. z2 = (INT32) wsptr[2];
  1124. z3 = (INT32) wsptr[6];
  1125. z1 = MULTIPLY(z2 + z3, FIX(0.831253876)); /* c6 */
  1126. tmp12 = z1 + MULTIPLY(z2, FIX(0.513743148)); /* c2-c6 */
  1127. tmp13 = z1 - MULTIPLY(z3, FIX(2.176250899)); /* c2+c6 */
  1128. tmp20 = tmp10 + tmp12;
  1129. tmp24 = tmp10 - tmp12;
  1130. tmp21 = tmp11 + tmp13;
  1131. tmp23 = tmp11 - tmp13;
  1132. /* Odd part */
  1133. z1 = (INT32) wsptr[1];
  1134. z2 = (INT32) wsptr[3];
  1135. z3 = (INT32) wsptr[5];
  1136. z3 <<= CONST_BITS;
  1137. z4 = (INT32) wsptr[7];
  1138. tmp11 = z2 + z4;
  1139. tmp13 = z2 - z4;
  1140. tmp12 = MULTIPLY(tmp13, FIX(0.309016994)); /* (c3-c7)/2 */
  1141. z2 = MULTIPLY(tmp11, FIX(0.951056516)); /* (c3+c7)/2 */
  1142. z4 = z3 + tmp12;
  1143. tmp10 = MULTIPLY(z1, FIX(1.396802247)) + z2 + z4; /* c1 */
  1144. tmp14 = MULTIPLY(z1, FIX(0.221231742)) - z2 + z4; /* c9 */
  1145. z2 = MULTIPLY(tmp11, FIX(0.587785252)); /* (c1-c9)/2 */
  1146. z4 = z3 - tmp12 - (tmp13 << (CONST_BITS - 1));
  1147. tmp12 = ((z1 - tmp13) << CONST_BITS) - z3;
  1148. tmp11 = MULTIPLY(z1, FIX(1.260073511)) - z2 - z4; /* c3 */
  1149. tmp13 = MULTIPLY(z1, FIX(0.642039522)) - z2 + z4; /* c7 */
  1150. /* Final output stage */
  1151. outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp20 + tmp10,
  1152. CONST_BITS+PASS1_BITS+3)
  1153. & RANGE_MASK];
  1154. outptr[9] = range_limit[(int) RIGHT_SHIFT(tmp20 - tmp10,
  1155. CONST_BITS+PASS1_BITS+3)
  1156. & RANGE_MASK];
  1157. outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp21 + tmp11,
  1158. CONST_BITS+PASS1_BITS+3)
  1159. & RANGE_MASK];
  1160. outptr[8] = range_limit[(int) RIGHT_SHIFT(tmp21 - tmp11,
  1161. CONST_BITS+PASS1_BITS+3)
  1162. & RANGE_MASK];
  1163. outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp22 + tmp12,
  1164. CONST_BITS+PASS1_BITS+3)
  1165. & RANGE_MASK];
  1166. outptr[7] = range_limit[(int) RIGHT_SHIFT(tmp22 - tmp12,
  1167. CONST_BITS+PASS1_BITS+3)
  1168. & RANGE_MASK];
  1169. outptr[3] = range_limit[(int) RIGHT_SHIFT(tmp23 + tmp13,
  1170. CONST_BITS+PASS1_BITS+3)
  1171. & RANGE_MASK];
  1172. outptr[6] = range_limit[(int) RIGHT_SHIFT(tmp23 - tmp13,
  1173. CONST_BITS+PASS1_BITS+3)
  1174. & RANGE_MASK];
  1175. outptr[4] = range_limit[(int) RIGHT_SHIFT(tmp24 + tmp14,
  1176. CONST_BITS+PASS1_BITS+3)
  1177. & RANGE_MASK];
  1178. outptr[5] = range_limit[(int) RIGHT_SHIFT(tmp24 - tmp14,
  1179. CONST_BITS+PASS1_BITS+3)
  1180. & RANGE_MASK];
  1181. wsptr += 8; /* advance pointer to next row */
  1182. }
  1183. }
  1184. /*
  1185. * Perform dequantization and inverse DCT on one block of coefficients,
  1186. * producing a 11x11 output block.
  1187. *
  1188. * Optimized algorithm with 24 multiplications in the 1-D kernel.
  1189. * cK represents sqrt(2) * cos(K*pi/22).
  1190. */
  1191. GLOBAL(void)
  1192. jpeg_idct_11x11 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  1193. JCOEFPTR coef_block,
  1194. JSAMPARRAY output_buf, JDIMENSION output_col)
  1195. {
  1196. INT32 tmp10, tmp11, tmp