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.

1156 lines
43KB

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