You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1158 lines
43KB

  1. /*
  2. * jrevdct.c
  3. *
  4. * This file is part of the Independent JPEG Group's software.
  5. *
  6. * The authors make NO WARRANTY or representation, either express or implied,
  7. * with respect to this software, its quality, accuracy, merchantability, or
  8. * fitness for a particular purpose. This software is provided "AS IS", and
  9. * you, its user, assume the entire risk as to its quality and accuracy.
  10. *
  11. * This software is copyright (C) 1991, 1992, Thomas G. Lane.
  12. * All Rights Reserved except as specified below.
  13. *
  14. * Permission is hereby granted to use, copy, modify, and distribute this
  15. * software (or portions thereof) for any purpose, without fee, subject to
  16. * these conditions:
  17. * (1) If any part of the source code for this software is distributed, then
  18. * this README file must be included, with this copyright and no-warranty
  19. * notice unaltered; and any additions, deletions, or changes to the original
  20. * files must be clearly indicated in accompanying documentation.
  21. * (2) If only executable code is distributed, then the accompanying
  22. * documentation must state that "this software is based in part on the work
  23. * of the Independent JPEG Group".
  24. * (3) Permission for use of this software is granted only if the user accepts
  25. * full responsibility for any undesirable consequences; the authors accept
  26. * NO LIABILITY for damages of any kind.
  27. *
  28. * These conditions apply to any software derived from or based on the IJG
  29. * code, not just to the unmodified library. If you use our work, you ought
  30. * to acknowledge us.
  31. *
  32. * Permission is NOT granted for the use of any IJG author's name or company
  33. * name in advertising or publicity relating to this software or products
  34. * derived from it. This software may be referred to only as "the Independent
  35. * JPEG Group's software".
  36. *
  37. * We specifically permit and encourage the use of this software as the basis
  38. * of commercial products, provided that all warranty or liability claims are
  39. * assumed by the product vendor.
  40. *
  41. * This file contains the basic inverse-DCT transformation subroutine.
  42. *
  43. * This implementation is based on an algorithm described in
  44. * C. Loeffler, A. Ligtenberg and G. Moschytz, "Practical Fast 1-D DCT
  45. * Algorithms with 11 Multiplications", Proc. Int'l. Conf. on Acoustics,
  46. * Speech, and Signal Processing 1989 (ICASSP '89), pp. 988-991.
  47. * The primary algorithm described there uses 11 multiplies and 29 adds.
  48. * We use their alternate method with 12 multiplies and 32 adds.
  49. * The advantage of this method is that no data path contains more than one
  50. * multiplication; this allows a very simple and accurate implementation in
  51. * scaled fixed-point arithmetic, with a minimal number of shifts.
  52. *
  53. * I've made lots of modifications to attempt to take advantage of the
  54. * sparse nature of the DCT matrices we're getting. Although the logic
  55. * is cumbersome, it's straightforward and the resulting code is much
  56. * faster.
  57. *
  58. * A better way to do this would be to pass in the DCT block as a sparse
  59. * matrix, perhaps with the difference cases encoded.
  60. */
  61. /**
  62. * @file libavcodec/jrevdct.c
  63. * Independent JPEG Group's LLM idct.
  64. */
  65. #include "libavutil/common.h"
  66. #include "dsputil.h"
  67. #define EIGHT_BIT_SAMPLES
  68. #define DCTSIZE 8
  69. #define DCTSIZE2 64
  70. #define GLOBAL
  71. #define RIGHT_SHIFT(x, n) ((x) >> (n))
  72. typedef DCTELEM DCTBLOCK[DCTSIZE2];
  73. #define CONST_BITS 13
  74. /*
  75. * This routine is specialized to the case DCTSIZE = 8.
  76. */
  77. #if DCTSIZE != 8
  78. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  79. #endif
  80. /*
  81. * A 2-D IDCT can be done by 1-D IDCT on each row followed by 1-D IDCT
  82. * on each column. Direct algorithms are also available, but they are
  83. * much more complex and seem not to be any faster when reduced to code.
  84. *
  85. * The poop on this scaling stuff is as follows:
  86. *
  87. * Each 1-D IDCT step produces outputs which are a factor of sqrt(N)
  88. * larger than the true IDCT outputs. The final outputs are therefore
  89. * a factor of N larger than desired; since N=8 this can be cured by
  90. * a simple right shift at the end of the algorithm. The advantage of
  91. * this arrangement is that we save two multiplications per 1-D IDCT,
  92. * because the y0 and y4 inputs need not be divided by sqrt(N).
  93. *
  94. * We have to do addition and subtraction of the integer inputs, which
  95. * is no problem, and multiplication by fractional constants, which is
  96. * a problem to do in integer arithmetic. We multiply all the constants
  97. * by CONST_SCALE and convert them to integer constants (thus retaining
  98. * CONST_BITS bits of precision in the constants). After doing a
  99. * multiplication we have to divide the product by CONST_SCALE, with proper
  100. * rounding, to produce the correct output. This division can be done
  101. * cheaply as a right shift of CONST_BITS bits. We postpone shifting
  102. * as long as possible so that partial sums can be added together with
  103. * full fractional precision.
  104. *
  105. * The outputs of the first pass are scaled up by PASS1_BITS bits so that
  106. * they are represented to better-than-integral precision. These outputs
  107. * require BITS_IN_JSAMPLE + PASS1_BITS + 3 bits; this fits in a 16-bit word
  108. * with the recommended scaling. (To scale up 12-bit sample data further, an
  109. * intermediate int32 array would be needed.)
  110. *
  111. * To avoid overflow of the 32-bit intermediate results in pass 2, we must
  112. * have BITS_IN_JSAMPLE + CONST_BITS + PASS1_BITS <= 26. Error analysis
  113. * shows that the values given below are the most effective.
  114. */
  115. #ifdef EIGHT_BIT_SAMPLES
  116. #define PASS1_BITS 2
  117. #else
  118. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  119. #endif
  120. #define ONE ((int32_t) 1)
  121. #define CONST_SCALE (ONE << CONST_BITS)
  122. /* Convert a positive real constant to an integer scaled by CONST_SCALE.
  123. * IMPORTANT: if your compiler doesn't do this arithmetic at compile time,
  124. * you will pay a significant penalty in run time. In that case, figure
  125. * the correct integer constant values and insert them by hand.
  126. */
  127. /* Actually FIX is no longer used, we precomputed them all */
  128. #define FIX(x) ((int32_t) ((x) * CONST_SCALE + 0.5))
  129. /* Descale and correctly round an int32_t value that's scaled by N bits.
  130. * We assume RIGHT_SHIFT rounds towards minus infinity, so adding
  131. * the fudge factor is correct for either sign of X.
  132. */
  133. #define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n)
  134. /* Multiply an int32_t variable by an int32_t constant to yield an int32_t result.
  135. * For 8-bit samples with the recommended scaling, all the variable
  136. * and constant values involved are no more than 16 bits wide, so a
  137. * 16x16->32 bit multiply can be used instead of a full 32x32 multiply;
  138. * this provides a useful speedup on many machines.
  139. * There is no way to specify a 16x16->32 multiply in portable C, but
  140. * some C compilers will do the right thing if you provide the correct
  141. * combination of casts.
  142. * NB: for 12-bit samples, a full 32-bit multiplication will be needed.
  143. */
  144. #ifdef EIGHT_BIT_SAMPLES
  145. #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
  146. #define MULTIPLY(var,const) (((int16_t) (var)) * ((int16_t) (const)))
  147. #endif
  148. #ifdef SHORTxLCONST_32 /* known to work with Microsoft C 6.0 */
  149. #define MULTIPLY(var,const) (((int16_t) (var)) * ((int32_t) (const)))
  150. #endif
  151. #endif
  152. #ifndef MULTIPLY /* default definition */
  153. #define MULTIPLY(var,const) ((var) * (const))
  154. #endif
  155. /*
  156. Unlike our decoder where we approximate the FIXes, we need to use exact
  157. ones here or successive P-frames will drift too much with Reference frame coding
  158. */
  159. #define FIX_0_211164243 1730
  160. #define FIX_0_275899380 2260
  161. #define FIX_0_298631336 2446
  162. #define FIX_0_390180644 3196
  163. #define FIX_0_509795579 4176
  164. #define FIX_0_541196100 4433
  165. #define FIX_0_601344887 4926
  166. #define FIX_0_765366865 6270
  167. #define FIX_0_785694958 6436
  168. #define FIX_0_899976223 7373
  169. #define FIX_1_061594337 8697
  170. #define FIX_1_111140466 9102
  171. #define FIX_1_175875602 9633
  172. #define FIX_1_306562965 10703
  173. #define FIX_1_387039845 11363
  174. #define FIX_1_451774981 11893
  175. #define FIX_1_501321110 12299
  176. #define FIX_1_662939225 13623
  177. #define FIX_1_847759065 15137
  178. #define FIX_1_961570560 16069
  179. #define FIX_2_053119869 16819
  180. #define FIX_2_172734803 17799
  181. #define FIX_2_562915447 20995
  182. #define FIX_3_072711026 25172
  183. /*
  184. * Perform the inverse DCT on one block of coefficients.
  185. */
  186. void j_rev_dct(DCTBLOCK data)
  187. {
  188. int32_t tmp0, tmp1, tmp2, tmp3;
  189. int32_t tmp10, tmp11, tmp12, tmp13;
  190. int32_t z1, z2, z3, z4, z5;
  191. int32_t d0, d1, d2, d3, d4, d5, d6, d7;
  192. register DCTELEM *dataptr;
  193. int rowctr;
  194. /* Pass 1: process rows. */
  195. /* Note results are scaled up by sqrt(8) compared to a true IDCT; */
  196. /* furthermore, we scale the results by 2**PASS1_BITS. */
  197. dataptr = data;
  198. for (rowctr = DCTSIZE-1; rowctr >= 0; rowctr--) {
  199. /* Due to quantization, we will usually find that many of the input
  200. * coefficients are zero, especially the AC terms. We can exploit this
  201. * by short-circuiting the IDCT calculation for any row in which all
  202. * the AC terms are zero. In that case each output is equal to the
  203. * DC coefficient (with scale factor as needed).
  204. * With typical images and quantization tables, half or more of the
  205. * row DCT calculations can be simplified this way.
  206. */
  207. register int *idataptr = (int*)dataptr;
  208. /* WARNING: we do the same permutation as MMX idct to simplify the
  209. video core */
  210. d0 = dataptr[0];
  211. d2 = dataptr[1];
  212. d4 = dataptr[2];
  213. d6 = dataptr[3];
  214. d1 = dataptr[4];
  215. d3 = dataptr[5];
  216. d5 = dataptr[6];
  217. d7 = dataptr[7];
  218. if ((d1 | d2 | d3 | d4 | d5 | d6 | d7) == 0) {
  219. /* AC terms all zero */
  220. if (d0) {
  221. /* Compute a 32 bit value to assign. */
  222. DCTELEM dcval = (DCTELEM) (d0 << PASS1_BITS);
  223. register int v = (dcval & 0xffff) | ((dcval << 16) & 0xffff0000);
  224. idataptr[0] = v;
  225. idataptr[1] = v;
  226. idataptr[2] = v;
  227. idataptr[3] = v;
  228. }
  229. dataptr += DCTSIZE; /* advance pointer to next row */
  230. continue;
  231. }
  232. /* Even part: reverse the even part of the forward DCT. */
  233. /* The rotator is sqrt(2)*c(-6). */
  234. {
  235. if (d6) {
  236. if (d2) {
  237. /* d0 != 0, d2 != 0, d4 != 0, d6 != 0 */
  238. z1 = MULTIPLY(d2 + d6, FIX_0_541196100);
  239. tmp2 = z1 + MULTIPLY(-d6, FIX_1_847759065);
  240. tmp3 = z1 + MULTIPLY(d2, FIX_0_765366865);
  241. tmp0 = (d0 + d4) << CONST_BITS;
  242. tmp1 = (d0 - d4) << CONST_BITS;
  243. tmp10 = tmp0 + tmp3;
  244. tmp13 = tmp0 - tmp3;
  245. tmp11 = tmp1 + tmp2;
  246. tmp12 = tmp1 - tmp2;
  247. } else {
  248. /* d0 != 0, d2 == 0, d4 != 0, d6 != 0 */
  249. tmp2 = MULTIPLY(-d6, FIX_1_306562965);
  250. tmp3 = MULTIPLY(d6, FIX_0_541196100);
  251. tmp0 = (d0 + d4) << CONST_BITS;
  252. tmp1 = (d0 - d4) << CONST_BITS;
  253. tmp10 = tmp0 + tmp3;
  254. tmp13 = tmp0 - tmp3;
  255. tmp11 = tmp1 + tmp2;
  256. tmp12 = tmp1 - tmp2;
  257. }
  258. } else {
  259. if (d2) {
  260. /* d0 != 0, d2 != 0, d4 != 0, d6 == 0 */
  261. tmp2 = MULTIPLY(d2, FIX_0_541196100);
  262. tmp3 = MULTIPLY(d2, FIX_1_306562965);
  263. tmp0 = (d0 + d4) << CONST_BITS;
  264. tmp1 = (d0 - d4) << CONST_BITS;
  265. tmp10 = tmp0 + tmp3;
  266. tmp13 = tmp0 - tmp3;
  267. tmp11 = tmp1 + tmp2;
  268. tmp12 = tmp1 - tmp2;
  269. } else {
  270. /* d0 != 0, d2 == 0, d4 != 0, d6 == 0 */
  271. tmp10 = tmp13 = (d0 + d4) << CONST_BITS;
  272. tmp11 = tmp12 = (d0 - d4) << CONST_BITS;
  273. }
  274. }
  275. /* Odd part per figure 8; the matrix is unitary and hence its
  276. * transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively.
  277. */
  278. if (d7) {
  279. if (d5) {
  280. if (d3) {
  281. if (d1) {
  282. /* d1 != 0, d3 != 0, d5 != 0, d7 != 0 */
  283. z1 = d7 + d1;
  284. z2 = d5 + d3;
  285. z3 = d7 + d3;
  286. z4 = d5 + d1;
  287. z5 = MULTIPLY(z3 + z4, FIX_1_175875602);
  288. tmp0 = MULTIPLY(d7, FIX_0_298631336);
  289. tmp1 = MULTIPLY(d5, FIX_2_053119869);
  290. tmp2 = MULTIPLY(d3, FIX_3_072711026);
  291. tmp3 = MULTIPLY(d1, FIX_1_501321110);
  292. z1 = MULTIPLY(-z1, FIX_0_899976223);
  293. z2 = MULTIPLY(-z2, FIX_2_562915447);
  294. z3 = MULTIPLY(-z3, FIX_1_961570560);
  295. z4 = MULTIPLY(-z4, FIX_0_390180644);
  296. z3 += z5;
  297. z4 += z5;
  298. tmp0 += z1 + z3;
  299. tmp1 += z2 + z4;
  300. tmp2 += z2 + z3;
  301. tmp3 += z1 + z4;
  302. } else {
  303. /* d1 == 0, d3 != 0, d5 != 0, d7 != 0 */
  304. z2 = d5 + d3;
  305. z3 = d7 + d3;
  306. z5 = MULTIPLY(z3 + d5, FIX_1_175875602);
  307. tmp0 = MULTIPLY(d7, FIX_0_298631336);
  308. tmp1 = MULTIPLY(d5, FIX_2_053119869);
  309. tmp2 = MULTIPLY(d3, FIX_3_072711026);
  310. z1 = MULTIPLY(-d7, FIX_0_899976223);
  311. z2 = MULTIPLY(-z2, FIX_2_562915447);
  312. z3 = MULTIPLY(-z3, FIX_1_961570560);
  313. z4 = MULTIPLY(-d5, FIX_0_390180644);
  314. z3 += z5;
  315. z4 += z5;
  316. tmp0 += z1 + z3;
  317. tmp1 += z2 + z4;
  318. tmp2 += z2 + z3;
  319. tmp3 = z1 + z4;
  320. }
  321. } else {
  322. if (d1) {
  323. /* d1 != 0, d3 == 0, d5 != 0, d7 != 0 */
  324. z1 = d7 + d1;
  325. z4 = d5 + d1;
  326. z5 = MULTIPLY(d7 + z4, FIX_1_175875602);
  327. tmp0 = MULTIPLY(d7, FIX_0_298631336);
  328. tmp1 = MULTIPLY(d5, FIX_2_053119869);
  329. tmp3 = MULTIPLY(d1, FIX_1_501321110);
  330. z1 = MULTIPLY(-z1, FIX_0_899976223);
  331. z2 = MULTIPLY(-d5, FIX_2_562915447);
  332. z3 = MULTIPLY(-d7, FIX_1_961570560);
  333. z4 = MULTIPLY(-z4, FIX_0_390180644);
  334. z3 += z5;
  335. z4 += z5;
  336. tmp0 += z1 + z3;
  337. tmp1 += z2 + z4;
  338. tmp2 = z2 + z3;
  339. tmp3 += z1 + z4;
  340. } else {
  341. /* d1 == 0, d3 == 0, d5 != 0, d7 != 0 */
  342. tmp0 = MULTIPLY(-d7, FIX_0_601344887);
  343. z1 = MULTIPLY(-d7, FIX_0_899976223);
  344. z3 = MULTIPLY(-d7, FIX_1_961570560);
  345. tmp1 = MULTIPLY(-d5, FIX_0_509795579);
  346. z2 = MULTIPLY(-d5, FIX_2_562915447);
  347. z4 = MULTIPLY(-d5, FIX_0_390180644);
  348. z5 = MULTIPLY(d5 + d7, FIX_1_175875602);
  349. z3 += z5;
  350. z4 += z5;
  351. tmp0 += z3;
  352. tmp1 += z4;
  353. tmp2 = z2 + z3;
  354. tmp3 = z1 + z4;
  355. }
  356. }
  357. } else {
  358. if (d3) {
  359. if (d1) {
  360. /* d1 != 0, d3 != 0, d5 == 0, d7 != 0 */
  361. z1 = d7 + d1;
  362. z3 = d7 + d3;
  363. z5 = MULTIPLY(z3 + d1, FIX_1_175875602);
  364. tmp0 = MULTIPLY(d7, FIX_0_298631336);
  365. tmp2 = MULTIPLY(d3, FIX_3_072711026);
  366. tmp3 = MULTIPLY(d1, FIX_1_501321110);
  367. z1 = MULTIPLY(-z1, FIX_0_899976223);
  368. z2 = MULTIPLY(-d3, FIX_2_562915447);
  369. z3 = MULTIPLY(-z3, FIX_1_961570560);
  370. z4 = MULTIPLY(-d1, FIX_0_390180644);
  371. z3 += z5;
  372. z4 += z5;
  373. tmp0 += z1 + z3;
  374. tmp1 = z2 + z4;
  375. tmp2 += z2 + z3;
  376. tmp3 += z1 + z4;
  377. } else {
  378. /* d1 == 0, d3 != 0, d5 == 0, d7 != 0 */
  379. z3 = d7 + d3;
  380. tmp0 = MULTIPLY(-d7, FIX_0_601344887);
  381. z1 = MULTIPLY(-d7, FIX_0_899976223);
  382. tmp2 = MULTIPLY(d3, FIX_0_509795579);
  383. z2 = MULTIPLY(-d3, FIX_2_562915447);
  384. z5 = MULTIPLY(z3, FIX_1_175875602);
  385. z3 = MULTIPLY(-z3, FIX_0_785694958);
  386. tmp0 += z3;
  387. tmp1 = z2 + z5;
  388. tmp2 += z3;
  389. tmp3 = z1 + z5;
  390. }
  391. } else {
  392. if (d1) {
  393. /* d1 != 0, d3 == 0, d5 == 0, d7 != 0 */
  394. z1 = d7 + d1;
  395. z5 = MULTIPLY(z1, FIX_1_175875602);
  396. z1 = MULTIPLY(z1, FIX_0_275899380);
  397. z3 = MULTIPLY(-d7, FIX_1_961570560);
  398. tmp0 = MULTIPLY(-d7, FIX_1_662939225);
  399. z4 = MULTIPLY(-d1, FIX_0_390180644);
  400. tmp3 = MULTIPLY(d1, FIX_1_111140466);
  401. tmp0 += z1;
  402. tmp1 = z4 + z5;
  403. tmp2 = z3 + z5;
  404. tmp3 += z1;
  405. } else {
  406. /* d1 == 0, d3 == 0, d5 == 0, d7 != 0 */
  407. tmp0 = MULTIPLY(-d7, FIX_1_387039845);
  408. tmp1 = MULTIPLY(d7, FIX_1_175875602);
  409. tmp2 = MULTIPLY(-d7, FIX_0_785694958);
  410. tmp3 = MULTIPLY(d7, FIX_0_275899380);
  411. }
  412. }
  413. }
  414. } else {
  415. if (d5) {
  416. if (d3) {
  417. if (d1) {
  418. /* d1 != 0, d3 != 0, d5 != 0, d7 == 0 */
  419. z2 = d5 + d3;
  420. z4 = d5 + d1;
  421. z5 = MULTIPLY(d3 + z4, FIX_1_175875602);
  422. tmp1 = MULTIPLY(d5, FIX_2_053119869);
  423. tmp2 = MULTIPLY(d3, FIX_3_072711026);
  424. tmp3 = MULTIPLY(d1, FIX_1_501321110);
  425. z1 = MULTIPLY(-d1, FIX_0_899976223);
  426. z2 = MULTIPLY(-z2, FIX_2_562915447);
  427. z3 = MULTIPLY(-d3, FIX_1_961570560);
  428. z4 = MULTIPLY(-z4, FIX_0_390180644);
  429. z3 += z5;
  430. z4 += z5;
  431. tmp0 = z1 + z3;
  432. tmp1 += z2 + z4;
  433. tmp2 += z2 + z3;
  434. tmp3 += z1 + z4;
  435. } else {
  436. /* d1 == 0, d3 != 0, d5 != 0, d7 == 0 */
  437. z2 = d5 + d3;
  438. z5 = MULTIPLY(z2, FIX_1_175875602);
  439. tmp1 = MULTIPLY(d5, FIX_1_662939225);
  440. z4 = MULTIPLY(-d5, FIX_0_390180644);
  441. z2 = MULTIPLY(-z2, FIX_1_387039845);
  442. tmp2 = MULTIPLY(d3, FIX_1_111140466);
  443. z3 = MULTIPLY(-d3, FIX_1_961570560);
  444. tmp0 = z3 + z5;
  445. tmp1 += z2;
  446. tmp2 += z2;
  447. tmp3 = z4 + z5;
  448. }
  449. } else {
  450. if (d1) {
  451. /* d1 != 0, d3 == 0, d5 != 0, d7 == 0 */
  452. z4 = d5 + d1;
  453. z5 = MULTIPLY(z4, FIX_1_175875602);
  454. z1 = MULTIPLY(-d1, FIX_0_899976223);
  455. tmp3 = MULTIPLY(d1, FIX_0_601344887);
  456. tmp1 = MULTIPLY(-d5, FIX_0_509795579);
  457. z2 = MULTIPLY(-d5, FIX_2_562915447);
  458. z4 = MULTIPLY(z4, FIX_0_785694958);
  459. tmp0 = z1 + z5;
  460. tmp1 += z4;
  461. tmp2 = z2 + z5;
  462. tmp3 += z4;
  463. } else {
  464. /* d1 == 0, d3 == 0, d5 != 0, d7 == 0 */
  465. tmp0 = MULTIPLY(d5, FIX_1_175875602);
  466. tmp1 = MULTIPLY(d5, FIX_0_275899380);
  467. tmp2 = MULTIPLY(-d5, FIX_1_387039845);
  468. tmp3 = MULTIPLY(d5, FIX_0_785694958);
  469. }
  470. }
  471. } else {
  472. if (d3) {
  473. if (d1) {
  474. /* d1 != 0, d3 != 0, d5 == 0, d7 == 0 */
  475. z5 = d1 + d3;
  476. tmp3 = MULTIPLY(d1, FIX_0_211164243);
  477. tmp2 = MULTIPLY(-d3, FIX_1_451774981);
  478. z1 = MULTIPLY(d1, FIX_1_061594337);
  479. z2 = MULTIPLY(-d3, FIX_2_172734803);
  480. z4 = MULTIPLY(z5, FIX_0_785694958);
  481. z5 = MULTIPLY(z5, FIX_1_175875602);
  482. tmp0 = z1 - z4;
  483. tmp1 = z2 + z4;
  484. tmp2 += z5;
  485. tmp3 += z5;
  486. } else {
  487. /* d1 == 0, d3 != 0, d5 == 0, d7 == 0 */
  488. tmp0 = MULTIPLY(-d3, FIX_0_785694958);
  489. tmp1 = MULTIPLY(-d3, FIX_1_387039845);
  490. tmp2 = MULTIPLY(-d3, FIX_0_275899380);
  491. tmp3 = MULTIPLY(d3, FIX_1_175875602);
  492. }
  493. } else {
  494. if (d1) {
  495. /* d1 != 0, d3 == 0, d5 == 0, d7 == 0 */
  496. tmp0 = MULTIPLY(d1, FIX_0_275899380);
  497. tmp1 = MULTIPLY(d1, FIX_0_785694958);
  498. tmp2 = MULTIPLY(d1, FIX_1_175875602);
  499. tmp3 = MULTIPLY(d1, FIX_1_387039845);
  500. } else {
  501. /* d1 == 0, d3 == 0, d5 == 0, d7 == 0 */
  502. tmp0 = tmp1 = tmp2 = tmp3 = 0;
  503. }
  504. }
  505. }
  506. }
  507. }
  508. /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
  509. dataptr[0] = (DCTELEM) DESCALE(tmp10 + tmp3, CONST_BITS-PASS1_BITS);
  510. dataptr[7] = (DCTELEM) DESCALE(tmp10 - tmp3, CONST_BITS-PASS1_BITS);
  511. dataptr[1] = (DCTELEM) DESCALE(tmp11 + tmp2, CONST_BITS-PASS1_BITS);
  512. dataptr[6] = (DCTELEM) DESCALE(tmp11 - tmp2, CONST_BITS-PASS1_BITS);
  513. dataptr[2] = (DCTELEM) DESCALE(tmp12 + tmp1, CONST_BITS-PASS1_BITS);
  514. dataptr[5] = (DCTELEM) DESCALE(tmp12 - tmp1, CONST_BITS-PASS1_BITS);
  515. dataptr[3] = (DCTELEM) DESCALE(tmp13 + tmp0, CONST_BITS-PASS1_BITS);
  516. dataptr[4] = (DCTELEM) DESCALE(tmp13 - tmp0, CONST_BITS-PASS1_BITS);
  517. dataptr += DCTSIZE; /* advance pointer to next row */
  518. }
  519. /* Pass 2: process columns. */
  520. /* Note that we must descale the results by a factor of 8 == 2**3, */
  521. /* and also undo the PASS1_BITS scaling. */
  522. dataptr = data;
  523. for (rowctr = DCTSIZE-1; rowctr >= 0; rowctr--) {
  524. /* Columns of zeroes can be exploited in the same way as we did with rows.
  525. * However, the row calculation has created many nonzero AC terms, so the
  526. * simplification applies less often (typically 5% to 10% of the time).
  527. * On machines with very fast multiplication, it's possible that the
  528. * test takes more time than it's worth. In that case this section
  529. * may be commented out.
  530. */
  531. d0 = dataptr[DCTSIZE*0];
  532. d1 = dataptr[DCTSIZE*1];
  533. d2 = dataptr[DCTSIZE*2];
  534. d3 = dataptr[DCTSIZE*3];
  535. d4 = dataptr[DCTSIZE*4];
  536. d5 = dataptr[DCTSIZE*5];
  537. d6 = dataptr[DCTSIZE*6];
  538. d7 = dataptr[DCTSIZE*7];
  539. /* Even part: reverse the even part of the forward DCT. */
  540. /* The rotator is sqrt(2)*c(-6). */
  541. if (d6) {
  542. if (d2) {
  543. /* d0 != 0, d2 != 0, d4 != 0, d6 != 0 */
  544. z1 = MULTIPLY(d2 + d6, FIX_0_541196100);
  545. tmp2 = z1 + MULTIPLY(-d6, FIX_1_847759065);
  546. tmp3 = z1 + MULTIPLY(d2, FIX_0_765366865);
  547. tmp0 = (d0 + d4) << CONST_BITS;
  548. tmp1 = (d0 - d4) << CONST_BITS;
  549. tmp10 = tmp0 + tmp3;
  550. tmp13 = tmp0 - tmp3;
  551. tmp11 = tmp1 + tmp2;
  552. tmp12 = tmp1 - tmp2;
  553. } else {
  554. /* d0 != 0, d2 == 0, d4 != 0, d6 != 0 */
  555. tmp2 = MULTIPLY(-d6, FIX_1_306562965);
  556. tmp3 = MULTIPLY(d6, FIX_0_541196100);
  557. tmp0 = (d0 + d4) << CONST_BITS;
  558. tmp1 = (d0 - d4) << CONST_BITS;
  559. tmp10 = tmp0 + tmp3;
  560. tmp13 = tmp0 - tmp3;
  561. tmp11 = tmp1 + tmp2;
  562. tmp12 = tmp1 - tmp2;
  563. }
  564. } else {
  565. if (d2) {
  566. /* d0 != 0, d2 != 0, d4 != 0, d6 == 0 */
  567. tmp2 = MULTIPLY(d2, FIX_0_541196100);
  568. tmp3 = MULTIPLY(d2, FIX_1_306562965);
  569. tmp0 = (d0 + d4) << CONST_BITS;
  570. tmp1 = (d0 - d4) << CONST_BITS;
  571. tmp10 = tmp0 + tmp3;
  572. tmp13 = tmp0 - tmp3;
  573. tmp11 = tmp1 + tmp2;
  574. tmp12 = tmp1 - tmp2;
  575. } else {
  576. /* d0 != 0, d2 == 0, d4 != 0, d6 == 0 */
  577. tmp10 = tmp13 = (d0 + d4) << CONST_BITS;
  578. tmp11 = tmp12 = (d0 - d4) << CONST_BITS;
  579. }
  580. }
  581. /* Odd part per figure 8; the matrix is unitary and hence its
  582. * transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively.
  583. */
  584. if (d7) {
  585. if (d5) {
  586. if (d3) {
  587. if (d1) {
  588. /* d1 != 0, d3 != 0, d5 != 0, d7 != 0 */
  589. z1 = d7 + d1;
  590. z2 = d5 + d3;
  591. z3 = d7 + d3;
  592. z4 = d5 + d1;
  593. z5 = MULTIPLY(z3 + z4, FIX_1_175875602);
  594. tmp0 = MULTIPLY(d7, FIX_0_298631336);
  595. tmp1 = MULTIPLY(d5, FIX_2_053119869);
  596. tmp2 = MULTIPLY(d3, FIX_3_072711026);
  597. tmp3 = MULTIPLY(d1, FIX_1_501321110);
  598. z1 = MULTIPLY(-z1, FIX_0_899976223);
  599. z2 = MULTIPLY(-z2, FIX_2_562915447);
  600. z3 = MULTIPLY(-z3, FIX_1_961570560);
  601. z4 = MULTIPLY(-z4, FIX_0_390180644);
  602. z3 += z5;
  603. z4 += z5;
  604. tmp0 += z1 + z3;
  605. tmp1 += z2 + z4;
  606. tmp2 += z2 + z3;
  607. tmp3 += z1 + z4;
  608. } else {
  609. /* d1 == 0, d3 != 0, d5 != 0, d7 != 0 */
  610. z2 = d5 + d3;
  611. z3 = d7 + d3;
  612. z5 = MULTIPLY(z3 + d5, FIX_1_175875602);
  613. tmp0 = MULTIPLY(d7, FIX_0_298631336);
  614. tmp1 = MULTIPLY(d5, FIX_2_053119869);
  615. tmp2 = MULTIPLY(d3, FIX_3_072711026);
  616. z1 = MULTIPLY(-d7, FIX_0_899976223);
  617. z2 = MULTIPLY(-z2, FIX_2_562915447);
  618. z3 = MULTIPLY(-z3, FIX_1_961570560);
  619. z4 = MULTIPLY(-d5, FIX_0_390180644);
  620. z3 += z5;
  621. z4 += z5;
  622. tmp0 += z1 + z3;
  623. tmp1 += z2 + z4;
  624. tmp2 += z2 + z3;
  625. tmp3 = z1 + z4;
  626. }
  627. } else {
  628. if (d1) {
  629. /* d1 != 0, d3 == 0, d5 != 0, d7 != 0 */
  630. z1 = d7 + d1;
  631. z3 = d7;
  632. z4 = d5 + d1;
  633. z5 = MULTIPLY(z3 + z4, FIX_1_175875602);
  634. tmp0 = MULTIPLY(d7, FIX_0_298631336);
  635. tmp1 = MULTIPLY(d5, FIX_2_053119869);
  636. tmp3 = MULTIPLY(d1, FIX_1_501321110);
  637. z1 = MULTIPLY(-z1, FIX_0_899976223);
  638. z2 = MULTIPLY(-d5, FIX_2_562915447);
  639. z3 = MULTIPLY(-d7, FIX_1_961570560);
  640. z4 = MULTIPLY(-z4, FIX_0_390180644);
  641. z3 += z5;
  642. z4 += z5;
  643. tmp0 += z1 + z3;
  644. tmp1 += z2 + z4;
  645. tmp2 = z2 + z3;
  646. tmp3 += z1 + z4;
  647. } else {
  648. /* d1 == 0, d3 == 0, d5 != 0, d7 != 0 */
  649. tmp0 = MULTIPLY(-d7, FIX_0_601344887);
  650. z1 = MULTIPLY(-d7, FIX_0_899976223);
  651. z3 = MULTIPLY(-d7, FIX_1_961570560);
  652. tmp1 = MULTIPLY(-d5, FIX_0_509795579);
  653. z2 = MULTIPLY(-d5, FIX_2_562915447);
  654. z4 = MULTIPLY(-d5, FIX_0_390180644);
  655. z5 = MULTIPLY(d5 + d7, FIX_1_175875602);
  656. z3 += z5;
  657. z4 += z5;
  658. tmp0 += z3;
  659. tmp1 += z4;
  660. tmp2 = z2 + z3;
  661. tmp3 = z1 + z4;
  662. }
  663. }
  664. } else {
  665. if (d3) {
  666. if (d1) {
  667. /* d1 != 0, d3 != 0, d5 == 0, d7 != 0 */
  668. z1 = d7 + d1;
  669. z3 = d7 + d3;
  670. z5 = MULTIPLY(z3 + d1, FIX_1_175875602);
  671. tmp0 = MULTIPLY(d7, FIX_0_298631336);
  672. tmp2 = MULTIPLY(d3, FIX_3_072711026);
  673. tmp3 = MULTIPLY(d1, FIX_1_501321110);
  674. z1 = MULTIPLY(-z1, FIX_0_899976223);
  675. z2 = MULTIPLY(-d3, FIX_2_562915447);
  676. z3 = MULTIPLY(-z3, FIX_1_961570560);
  677. z4 = MULTIPLY(-d1, FIX_0_390180644);
  678. z3 += z5;
  679. z4 += z5;
  680. tmp0 += z1 + z3;
  681. tmp1 = z2 + z4;
  682. tmp2 += z2 + z3;
  683. tmp3 += z1 + z4;
  684. } else {
  685. /* d1 == 0, d3 != 0, d5 == 0, d7 != 0 */
  686. z3 = d7 + d3;
  687. tmp0 = MULTIPLY(-d7, FIX_0_601344887);
  688. z1 = MULTIPLY(-d7, FIX_0_899976223);
  689. tmp2 = MULTIPLY(d3, FIX_0_509795579);
  690. z2 = MULTIPLY(-d3, FIX_2_562915447);
  691. z5 = MULTIPLY(z3, FIX_1_175875602);
  692. z3 = MULTIPLY(-z3, FIX_0_785694958);
  693. tmp0 += z3;
  694. tmp1 = z2 + z5;
  695. tmp2 += z3;
  696. tmp3 = z1 + z5;
  697. }
  698. } else {
  699. if (d1) {
  700. /* d1 != 0, d3 == 0, d5 == 0, d7 != 0 */
  701. z1 = d7 + d1;
  702. z5 = MULTIPLY(z1, FIX_1_175875602);
  703. z1 = MULTIPLY(z1, FIX_0_275899380);
  704. z3 = MULTIPLY(-d7, FIX_1_961570560);
  705. tmp0 = MULTIPLY(-d7, FIX_1_662939225);
  706. z4 = MULTIPLY(-d1, FIX_0_390180644);
  707. tmp3 = MULTIPLY(d1, FIX_1_111140466);
  708. tmp0 += z1;
  709. tmp1 = z4 + z5;
  710. tmp2 = z3 + z5;
  711. tmp3 += z1;
  712. } else {
  713. /* d1 == 0, d3 == 0, d5 == 0, d7 != 0 */
  714. tmp0 = MULTIPLY(-d7, FIX_1_387039845);
  715. tmp1 = MULTIPLY(d7, FIX_1_175875602);
  716. tmp2 = MULTIPLY(-d7, FIX_0_785694958);
  717. tmp3 = MULTIPLY(d7, FIX_0_275899380);
  718. }
  719. }
  720. }
  721. } else {
  722. if (d5) {
  723. if (d3) {
  724. if (d1) {
  725. /* d1 != 0, d3 != 0, d5 != 0, d7 == 0 */
  726. z2 = d5 + d3;
  727. z4 = d5 + d1;
  728. z5 = MULTIPLY(d3 + z4, FIX_1_175875602);
  729. tmp1 = MULTIPLY(d5, FIX_2_053119869);
  730. tmp2 = MULTIPLY(d3, FIX_3_072711026);
  731. tmp3 = MULTIPLY(d1, FIX_1_501321110);
  732. z1 = MULTIPLY(-d1, FIX_0_899976223);
  733. z2 = MULTIPLY(-z2, FIX_2_562915447);
  734. z3 = MULTIPLY(-d3, FIX_1_961570560);
  735. z4 = MULTIPLY(-z4, FIX_0_390180644);
  736. z3 += z5;
  737. z4 += z5;
  738. tmp0 = z1 + z3;
  739. tmp1 += z2 + z4;
  740. tmp2 += z2 + z3;
  741. tmp3 += z1 + z4;
  742. } else {
  743. /* d1 == 0, d3 != 0, d5 != 0, d7 == 0 */
  744. z2 = d5 + d3;
  745. z5 = MULTIPLY(z2, FIX_1_175875602);
  746. tmp1 = MULTIPLY(d5, FIX_1_662939225);
  747. z4 = MULTIPLY(-d5, FIX_0_390180644);
  748. z2 = MULTIPLY(-z2, FIX_1_387039845);
  749. tmp2 = MULTIPLY(d3, FIX_1_111140466);
  750. z3 = MULTIPLY(-d3, FIX_1_961570560);
  751. tmp0 = z3 + z5;
  752. tmp1 += z2;
  753. tmp2 += z2;
  754. tmp3 = z4 + z5;
  755. }
  756. } else {
  757. if (d1) {
  758. /* d1 != 0, d3 == 0, d5 != 0, d7 == 0 */
  759. z4 = d5 + d1;
  760. z5 = MULTIPLY(z4, FIX_1_175875602);
  761. z1 = MULTIPLY(-d1, FIX_0_899976223);
  762. tmp3 = MULTIPLY(d1, FIX_0_601344887);
  763. tmp1 = MULTIPLY(-d5, FIX_0_509795579);
  764. z2 = MULTIPLY(-d5, FIX_2_562915447);
  765. z4 = MULTIPLY(z4, FIX_0_785694958);
  766. tmp0 = z1 + z5;
  767. tmp1 += z4;
  768. tmp2 = z2 + z5;
  769. tmp3 += z4;
  770. } else {
  771. /* d1 == 0, d3 == 0, d5 != 0, d7 == 0 */
  772. tmp0 = MULTIPLY(d5, FIX_1_175875602);
  773. tmp1 = MULTIPLY(d5, FIX_0_275899380);
  774. tmp2 = MULTIPLY(-d5, FIX_1_387039845);
  775. tmp3 = MULTIPLY(d5, FIX_0_785694958);
  776. }
  777. }
  778. } else {
  779. if (d3) {
  780. if (d1) {
  781. /* d1 != 0, d3 != 0, d5 == 0, d7 == 0 */
  782. z5 = d1 + d3;
  783. tmp3 = MULTIPLY(d1, FIX_0_211164243);
  784. tmp2 = MULTIPLY(-d3, FIX_1_451774981);
  785. z1 = MULTIPLY(d1, FIX_1_061594337);
  786. z2 = MULTIPLY(-d3, FIX_2_172734803);
  787. z4 = MULTIPLY(z5, FIX_0_785694958);
  788. z5 = MULTIPLY(z5, FIX_1_175875602);
  789. tmp0 = z1 - z4;
  790. tmp1 = z2 + z4;
  791. tmp2 += z5;
  792. tmp3 += z5;
  793. } else {
  794. /* d1 == 0, d3 != 0, d5 == 0, d7 == 0 */
  795. tmp0 = MULTIPLY(-d3, FIX_0_785694958);
  796. tmp1 = MULTIPLY(-d3, FIX_1_387039845);
  797. tmp2 = MULTIPLY(-d3, FIX_0_275899380);
  798. tmp3 = MULTIPLY(d3, FIX_1_175875602);
  799. }
  800. } else {
  801. if (d1) {
  802. /* d1 != 0, d3 == 0, d5 == 0, d7 == 0 */
  803. tmp0 = MULTIPLY(d1, FIX_0_275899380);
  804. tmp1 = MULTIPLY(d1, FIX_0_785694958);
  805. tmp2 = MULTIPLY(d1, FIX_1_175875602);
  806. tmp3 = MULTIPLY(d1, FIX_1_387039845);
  807. } else {
  808. /* d1 == 0, d3 == 0, d5 == 0, d7 == 0 */
  809. tmp0 = tmp1 = tmp2 = tmp3 = 0;
  810. }
  811. }
  812. }
  813. }
  814. /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
  815. dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp3,
  816. CONST_BITS+PASS1_BITS+3);
  817. dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp10 - tmp3,
  818. CONST_BITS+PASS1_BITS+3);
  819. dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp11 + tmp2,
  820. CONST_BITS+PASS1_BITS+3);
  821. dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(tmp11 - tmp2,
  822. CONST_BITS+PASS1_BITS+3);
  823. dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(tmp12 + tmp1,
  824. CONST_BITS+PASS1_BITS+3);
  825. dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp12 - tmp1,
  826. CONST_BITS+PASS1_BITS+3);
  827. dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp13 + tmp0,
  828. CONST_BITS+PASS1_BITS+3);
  829. dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp13 - tmp0,
  830. CONST_BITS+PASS1_BITS+3);
  831. dataptr++; /* advance pointer to next column */
  832. }
  833. }
  834. #undef DCTSIZE
  835. #define DCTSIZE 4
  836. #define DCTSTRIDE 8
  837. void j_rev_dct4(DCTBLOCK data)
  838. {
  839. int32_t tmp0, tmp1, tmp2, tmp3;
  840. int32_t tmp10, tmp11, tmp12, tmp13;
  841. int32_t z1;
  842. int32_t d0, d2, d4, d6;
  843. register DCTELEM *dataptr;
  844. int rowctr;
  845. /* Pass 1: process rows. */
  846. /* Note results are scaled up by sqrt(8) compared to a true IDCT; */
  847. /* furthermore, we scale the results by 2**PASS1_BITS. */
  848. data[0] += 4;
  849. dataptr = data;
  850. for (rowctr = DCTSIZE-1; rowctr >= 0; rowctr--) {
  851. /* Due to quantization, we will usually find that many of the input
  852. * coefficients are zero, especially the AC terms. We can exploit this
  853. * by short-circuiting the IDCT calculation for any row in which all
  854. * the AC terms are zero. In that case each output is equal to the
  855. * DC coefficient (with scale factor as needed).
  856. * With typical images and quantization tables, half or more of the
  857. * row DCT calculations can be simplified this way.
  858. */
  859. register int *idataptr = (int*)dataptr;
  860. d0 = dataptr[0];
  861. d2 = dataptr[1];
  862. d4 = dataptr[2];
  863. d6 = dataptr[3];
  864. if ((d2 | d4 | d6) == 0) {
  865. /* AC terms all zero */
  866. if (d0) {
  867. /* Compute a 32 bit value to assign. */
  868. DCTELEM dcval = (DCTELEM) (d0 << PASS1_BITS);
  869. register int v = (dcval & 0xffff) | ((dcval << 16) & 0xffff0000);
  870. idataptr[0] = v;
  871. idataptr[1] = v;
  872. }
  873. dataptr += DCTSTRIDE; /* advance pointer to next row */
  874. continue;
  875. }
  876. /* Even part: reverse the even part of the forward DCT. */
  877. /* The rotator is sqrt(2)*c(-6). */
  878. if (d6) {
  879. if (d2) {
  880. /* d0 != 0, d2 != 0, d4 != 0, d6 != 0 */
  881. z1 = MULTIPLY(d2 + d6, FIX_0_541196100);
  882. tmp2 = z1 + MULTIPLY(-d6, FIX_1_847759065);
  883. tmp3 = z1 + MULTIPLY(d2, FIX_0_765366865);
  884. tmp0 = (d0 + d4) << CONST_BITS;
  885. tmp1 = (d0 - d4) << CONST_BITS;
  886. tmp10 = tmp0 + tmp3;
  887. tmp13 = tmp0 - tmp3;
  888. tmp11 = tmp1 + tmp2;
  889. tmp12 = tmp1 - tmp2;
  890. } else {
  891. /* d0 != 0, d2 == 0, d4 != 0, d6 != 0 */
  892. tmp2 = MULTIPLY(-d6, FIX_1_306562965);
  893. tmp3 = MULTIPLY(d6, FIX_0_541196100);
  894. tmp0 = (d0 + d4) << CONST_BITS;
  895. tmp1 = (d0 - d4) << CONST_BITS;
  896. tmp10 = tmp0 + tmp3;
  897. tmp13 = tmp0 - tmp3;
  898. tmp11 = tmp1 + tmp2;
  899. tmp12 = tmp1 - tmp2;
  900. }
  901. } else {
  902. if (d2) {
  903. /* d0 != 0, d2 != 0, d4 != 0, d6 == 0 */
  904. tmp2 = MULTIPLY(d2, FIX_0_541196100);
  905. tmp3 = MULTIPLY(d2, FIX_1_306562965);
  906. tmp0 = (d0 + d4) << CONST_BITS;
  907. tmp1 = (d0 - d4) << CONST_BITS;
  908. tmp10 = tmp0 + tmp3;
  909. tmp13 = tmp0 - tmp3;
  910. tmp11 = tmp1 + tmp2;
  911. tmp12 = tmp1 - tmp2;
  912. } else {
  913. /* d0 != 0, d2 == 0, d4 != 0, d6 == 0 */
  914. tmp10 = tmp13 = (d0 + d4) << CONST_BITS;
  915. tmp11 = tmp12 = (d0 - d4) << CONST_BITS;
  916. }
  917. }
  918. /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
  919. dataptr[0] = (DCTELEM) DESCALE(tmp10, CONST_BITS-PASS1_BITS);
  920. dataptr[1] = (DCTELEM) DESCALE(tmp11, CONST_BITS-PASS1_BITS);
  921. dataptr[2] = (DCTELEM) DESCALE(tmp12, CONST_BITS-PASS1_BITS);
  922. dataptr[3] = (DCTELEM) DESCALE(tmp13, CONST_BITS-PASS1_BITS);
  923. dataptr += DCTSTRIDE; /* advance pointer to next row */
  924. }
  925. /* Pass 2: process columns. */
  926. /* Note that we must descale the results by a factor of 8 == 2**3, */
  927. /* and also undo the PASS1_BITS scaling. */
  928. dataptr = data;
  929. for (rowctr = DCTSIZE-1; rowctr >= 0; rowctr--) {
  930. /* Columns of zeroes can be exploited in the same way as we did with rows.
  931. * However, the row calculation has created many nonzero AC terms, so the
  932. * simplification applies less often (typically 5% to 10% of the time).
  933. * On machines with very fast multiplication, it's possible that the
  934. * test takes more time than it's worth. In that case this section
  935. * may be commented out.
  936. */
  937. d0 = dataptr[DCTSTRIDE*0];
  938. d2 = dataptr[DCTSTRIDE*1];
  939. d4 = dataptr[DCTSTRIDE*2];
  940. d6 = dataptr[DCTSTRIDE*3];
  941. /* Even part: reverse the even part of the forward DCT. */
  942. /* The rotator is sqrt(2)*c(-6). */
  943. if (d6) {
  944. if (d2) {
  945. /* d0 != 0, d2 != 0, d4 != 0, d6 != 0 */
  946. z1 = MULTIPLY(d2 + d6, FIX_0_541196100);
  947. tmp2 = z1 + MULTIPLY(-d6, FIX_1_847759065);
  948. tmp3 = z1 + MULTIPLY(d2, FIX_0_765366865);
  949. tmp0 = (d0 + d4) << CONST_BITS;
  950. tmp1 = (d0 - d4) << CONST_BITS;
  951. tmp10 = tmp0 + tmp3;
  952. tmp13 = tmp0 - tmp3;
  953. tmp11 = tmp1 + tmp2;
  954. tmp12 = tmp1 - tmp2;
  955. } else {
  956. /* d0 != 0, d2 == 0, d4 != 0, d6 != 0 */
  957. tmp2 = MULTIPLY(-d6, FIX_1_306562965);
  958. tmp3 = MULTIPLY(d6, FIX_0_541196100);
  959. tmp0 = (d0 + d4) << CONST_BITS;
  960. tmp1 = (d0 - d4) << CONST_BITS;
  961. tmp10 = tmp0 + tmp3;
  962. tmp13 = tmp0 - tmp3;
  963. tmp11 = tmp1 + tmp2;
  964. tmp12 = tmp1 - tmp2;
  965. }
  966. } else {
  967. if (d2) {
  968. /* d0 != 0, d2 != 0, d4 != 0, d6 == 0 */
  969. tmp2 = MULTIPLY(d2, FIX_0_541196100);
  970. tmp3 = MULTIPLY(d2, FIX_1_306562965);
  971. tmp0 = (d0 + d4) << CONST_BITS;
  972. tmp1 = (d0 - d4) << CONST_BITS;
  973. tmp10 = tmp0 + tmp3;
  974. tmp13 = tmp0 - tmp3;
  975. tmp11 = tmp1 + tmp2;
  976. tmp12 = tmp1 - tmp2;
  977. } else {
  978. /* d0 != 0, d2 == 0, d4 != 0, d6 == 0 */
  979. tmp10 = tmp13 = (d0 + d4) << CONST_BITS;
  980. tmp11 = tmp12 = (d0 - d4) << CONST_BITS;
  981. }
  982. }
  983. /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
  984. dataptr[DCTSTRIDE*0] = tmp10 >> (CONST_BITS+PASS1_BITS+3);
  985. dataptr[DCTSTRIDE*1] = tmp11 >> (CONST_BITS+PASS1_BITS+3);
  986. dataptr[DCTSTRIDE*2] = tmp12 >> (CONST_BITS+PASS1_BITS+3);
  987. dataptr[DCTSTRIDE*3] = tmp13 >> (CONST_BITS+PASS1_BITS+3);
  988. dataptr++; /* advance pointer to next column */
  989. }
  990. }
  991. void j_rev_dct2(DCTBLOCK data){
  992. int d00, d01, d10, d11;
  993. data[0] += 4;
  994. d00 = data[0+0*DCTSTRIDE] + data[1+0*DCTSTRIDE];
  995. d01 = data[0+0*DCTSTRIDE] - data[1+0*DCTSTRIDE];
  996. d10 = data[0+1*DCTSTRIDE] + data[1+1*DCTSTRIDE];
  997. d11 = data[0+1*DCTSTRIDE] - data[1+1*DCTSTRIDE];
  998. data[0+0*DCTSTRIDE]= (d00 + d10)>>3;
  999. data[1+0*DCTSTRIDE]= (d01 + d11)>>3;
  1000. data[0+1*DCTSTRIDE]= (d00 - d10)>>3;
  1001. data[1+1*DCTSTRIDE]= (d01 - d11)>>3;
  1002. }
  1003. void j_rev_dct1(DCTBLOCK data){
  1004. data[0] = (data[0] + 4)>>3;
  1005. }
  1006. #undef FIX
  1007. #undef CONST_BITS