FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/jrevdct.c
Date: 2026-04-20 20:24:43
Exec Total Coverage
Lines: 580 594 97.6%
Functions: 4 6 66.7%
Branches: 100 100 100.0%

Line Branch Exec Source
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 /**
61 * @file
62 * Independent JPEG Group's LLM idct.
63 */
64
65 #include <stddef.h>
66 #include <stdint.h>
67
68 #include "libavutil/intreadwrite.h"
69
70 #include "dct.h"
71 #include "idctdsp.h"
72
73 #define EIGHT_BIT_SAMPLES
74
75 #define DCTSIZE 8
76 #define DCTSIZE2 64
77
78 #define GLOBAL
79
80 #define RIGHT_SHIFT(x, n) ((x) >> (n))
81
82 typedef int16_t DCTBLOCK[DCTSIZE2];
83
84 #define CONST_BITS 13
85
86 /*
87 * This routine is specialized to the case DCTSIZE = 8.
88 */
89
90 #if DCTSIZE != 8
91 Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
92 #endif
93
94
95 /*
96 * A 2-D IDCT can be done by 1-D IDCT on each row followed by 1-D IDCT
97 * on each column. Direct algorithms are also available, but they are
98 * much more complex and seem not to be any faster when reduced to code.
99 *
100 * The poop on this scaling stuff is as follows:
101 *
102 * Each 1-D IDCT step produces outputs which are a factor of sqrt(N)
103 * larger than the true IDCT outputs. The final outputs are therefore
104 * a factor of N larger than desired; since N=8 this can be cured by
105 * a simple right shift at the end of the algorithm. The advantage of
106 * this arrangement is that we save two multiplications per 1-D IDCT,
107 * because the y0 and y4 inputs need not be divided by sqrt(N).
108 *
109 * We have to do addition and subtraction of the integer inputs, which
110 * is no problem, and multiplication by fractional constants, which is
111 * a problem to do in integer arithmetic. We multiply all the constants
112 * by CONST_SCALE and convert them to integer constants (thus retaining
113 * CONST_BITS bits of precision in the constants). After doing a
114 * multiplication we have to divide the product by CONST_SCALE, with proper
115 * rounding, to produce the correct output. This division can be done
116 * cheaply as a right shift of CONST_BITS bits. We postpone shifting
117 * as long as possible so that partial sums can be added together with
118 * full fractional precision.
119 *
120 * The outputs of the first pass are scaled up by PASS1_BITS bits so that
121 * they are represented to better-than-integral precision. These outputs
122 * require BITS_IN_JSAMPLE + PASS1_BITS + 3 bits; this fits in a 16-bit word
123 * with the recommended scaling. (To scale up 12-bit sample data further, an
124 * intermediate int32 array would be needed.)
125 *
126 * To avoid overflow of the 32-bit intermediate results in pass 2, we must
127 * have BITS_IN_JSAMPLE + CONST_BITS + PASS1_BITS <= 26. Error analysis
128 * shows that the values given below are the most effective.
129 */
130
131 #ifdef EIGHT_BIT_SAMPLES
132 #define PASS1_BITS 2
133 #else
134 #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
135 #endif
136
137 #define ONE ((int32_t) 1)
138
139 #define CONST_SCALE (ONE << CONST_BITS)
140
141 /* Convert a positive real constant to an integer scaled by CONST_SCALE.
142 * IMPORTANT: if your compiler doesn't do this arithmetic at compile time,
143 * you will pay a significant penalty in run time. In that case, figure
144 * the correct integer constant values and insert them by hand.
145 */
146
147 /* Actually FIX is no longer used, we precomputed them all */
148 #define FIX(x) ((int32_t) ((x) * CONST_SCALE + 0.5))
149
150 /* Descale and correctly round an int32_t value that's scaled by N bits.
151 * We assume RIGHT_SHIFT rounds towards minus infinity, so adding
152 * the fudge factor is correct for either sign of X.
153 */
154
155 #define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n)
156
157 /* Multiply an int32_t variable by an int32_t constant to yield an int32_t result.
158 * For 8-bit samples with the recommended scaling, all the variable
159 * and constant values involved are no more than 16 bits wide, so a
160 * 16x16->32 bit multiply can be used instead of a full 32x32 multiply;
161 * this provides a useful speedup on many machines.
162 * There is no way to specify a 16x16->32 multiply in portable C, but
163 * some C compilers will do the right thing if you provide the correct
164 * combination of casts.
165 * NB: for 12-bit samples, a full 32-bit multiplication will be needed.
166 */
167
168 #ifdef EIGHT_BIT_SAMPLES
169 #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
170 #define MULTIPLY(var,const) (((int16_t) (var)) * ((int16_t) (const)))
171 #endif
172 #ifdef SHORTxLCONST_32 /* known to work with Microsoft C 6.0 */
173 #define MULTIPLY(var,const) (((int16_t) (var)) * ((int32_t) (const)))
174 #endif
175 #endif
176
177 #ifndef MULTIPLY /* default definition */
178 #define MULTIPLY(var,const) ((var) * (const))
179 #endif
180
181
182 /*
183 Unlike our decoder where we approximate the FIXes, we need to use exact
184 ones here or successive P-frames will drift too much with Reference frame coding
185 */
186 #define FIX_0_211164243 1730
187 #define FIX_0_275899380 2260
188 #define FIX_0_298631336 2446
189 #define FIX_0_390180644 3196
190 #define FIX_0_509795579 4176
191 #define FIX_0_541196100 4433
192 #define FIX_0_601344887 4926
193 #define FIX_0_765366865 6270
194 #define FIX_0_785694958 6436
195 #define FIX_0_899976223 7373
196 #define FIX_1_061594337 8697
197 #define FIX_1_111140466 9102
198 #define FIX_1_175875602 9633
199 #define FIX_1_306562965 10703
200 #define FIX_1_387039845 11363
201 #define FIX_1_451774981 11893
202 #define FIX_1_501321110 12299
203 #define FIX_1_662939225 13623
204 #define FIX_1_847759065 15137
205 #define FIX_1_961570560 16069
206 #define FIX_2_053119869 16819
207 #define FIX_2_172734803 17799
208 #define FIX_2_562915447 20995
209 #define FIX_3_072711026 25172
210
211 /*
212 * Perform the inverse DCT on one block of coefficients.
213 */
214
215 256369 void ff_j_rev_dct(DCTBLOCK data)
216 {
217 int32_t tmp0, tmp1, tmp2, tmp3;
218 int32_t tmp10, tmp11, tmp12, tmp13;
219 int32_t z1, z2, z3, z4, z5;
220 int32_t d0, d1, d2, d3, d4, d5, d6, d7;
221 register int16_t *dataptr;
222 int rowctr;
223
224 /* Pass 1: process rows. */
225 /* Note results are scaled up by sqrt(8) compared to a true IDCT; */
226 /* furthermore, we scale the results by 2**PASS1_BITS. */
227
228 256369 dataptr = data;
229
230
2/2
✓ Branch 0 taken 2050952 times.
✓ Branch 1 taken 256369 times.
2307321 for (rowctr = DCTSIZE-1; rowctr >= 0; rowctr--) {
231 /* Due to quantization, we will usually find that many of the input
232 * coefficients are zero, especially the AC terms. We can exploit this
233 * by short-circuiting the IDCT calculation for any row in which all
234 * the AC terms are zero. In that case each output is equal to the
235 * DC coefficient (with scale factor as needed).
236 * With typical images and quantization tables, half or more of the
237 * row DCT calculations can be simplified this way.
238 */
239
240 2050952 register uint8_t *idataptr = (uint8_t*)dataptr;
241
242 /* WARNING: we do the same permutation as MMX idct to simplify the
243 video core */
244 2050952 d0 = dataptr[0];
245 2050952 d2 = dataptr[1];
246 2050952 d4 = dataptr[2];
247 2050952 d6 = dataptr[3];
248 2050952 d1 = dataptr[4];
249 2050952 d3 = dataptr[5];
250 2050952 d5 = dataptr[6];
251 2050952 d7 = dataptr[7];
252
253
2/2
✓ Branch 0 taken 1167976 times.
✓ Branch 1 taken 882976 times.
2050952 if ((d1 | d2 | d3 | d4 | d5 | d6 | d7) == 0) {
254 /* AC terms all zero */
255
2/2
✓ Branch 0 taken 164794 times.
✓ Branch 1 taken 1003182 times.
1167976 if (d0) {
256 /* Compute a 32 bit value to assign. */
257 164794 int16_t dcval = (int16_t) (d0 * (1 << PASS1_BITS));
258 164794 register unsigned v = (dcval & 0xffff) | ((uint32_t)dcval << 16);
259
260 164794 AV_WN32A(&idataptr[ 0], v);
261 164794 AV_WN32A(&idataptr[ 4], v);
262 164794 AV_WN32A(&idataptr[ 8], v);
263 164794 AV_WN32A(&idataptr[12], v);
264 }
265
266 1167976 dataptr += DCTSIZE; /* advance pointer to next row */
267 1167976 continue;
268 }
269
270 /* Even part: reverse the even part of the forward DCT. */
271 /* The rotator is sqrt(2)*c(-6). */
272 {
273
2/2
✓ Branch 0 taken 250104 times.
✓ Branch 1 taken 632872 times.
882976 if (d6) {
274
2/2
✓ Branch 0 taken 189495 times.
✓ Branch 1 taken 60609 times.
250104 if (d2) {
275 /* d0 != 0, d2 != 0, d4 != 0, d6 != 0 */
276 189495 z1 = MULTIPLY(d2 + d6, FIX_0_541196100);
277 189495 tmp2 = z1 + MULTIPLY(-d6, FIX_1_847759065);
278 189495 tmp3 = z1 + MULTIPLY(d2, FIX_0_765366865);
279
280 189495 tmp0 = (d0 + d4) * CONST_SCALE;
281 189495 tmp1 = (d0 - d4) * CONST_SCALE;
282
283 189495 tmp10 = tmp0 + tmp3;
284 189495 tmp13 = tmp0 - tmp3;
285 189495 tmp11 = tmp1 + tmp2;
286 189495 tmp12 = tmp1 - tmp2;
287 } else {
288 /* d0 != 0, d2 == 0, d4 != 0, d6 != 0 */
289 60609 tmp2 = MULTIPLY(-d6, FIX_1_306562965);
290 60609 tmp3 = MULTIPLY(d6, FIX_0_541196100);
291
292 60609 tmp0 = (d0 + d4) * CONST_SCALE;
293 60609 tmp1 = (d0 - d4) * CONST_SCALE;
294
295 60609 tmp10 = tmp0 + tmp3;
296 60609 tmp13 = tmp0 - tmp3;
297 60609 tmp11 = tmp1 + tmp2;
298 60609 tmp12 = tmp1 - tmp2;
299 }
300 } else {
301
2/2
✓ Branch 0 taken 185205 times.
✓ Branch 1 taken 447667 times.
632872 if (d2) {
302 /* d0 != 0, d2 != 0, d4 != 0, d6 == 0 */
303 185205 tmp2 = MULTIPLY(d2, FIX_0_541196100);
304 185205 tmp3 = MULTIPLY(d2, FIX_1_306562965);
305
306 185205 tmp0 = (d0 + d4) * CONST_SCALE;
307 185205 tmp1 = (d0 - d4) * CONST_SCALE;
308
309 185205 tmp10 = tmp0 + tmp3;
310 185205 tmp13 = tmp0 - tmp3;
311 185205 tmp11 = tmp1 + tmp2;
312 185205 tmp12 = tmp1 - tmp2;
313 } else {
314 /* d0 != 0, d2 == 0, d4 != 0, d6 == 0 */
315 447667 tmp10 = tmp13 = (d0 + d4) * CONST_SCALE;
316 447667 tmp11 = tmp12 = (d0 - d4) * CONST_SCALE;
317 }
318 }
319
320 /* Odd part per figure 8; the matrix is unitary and hence its
321 * transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively.
322 */
323
324
2/2
✓ Branch 0 taken 411581 times.
✓ Branch 1 taken 471395 times.
882976 if (d7) {
325
2/2
✓ Branch 0 taken 190559 times.
✓ Branch 1 taken 221022 times.
411581 if (d5) {
326
2/2
✓ Branch 0 taken 172886 times.
✓ Branch 1 taken 17673 times.
190559 if (d3) {
327
2/2
✓ Branch 0 taken 167370 times.
✓ Branch 1 taken 5516 times.
172886 if (d1) {
328 /* d1 != 0, d3 != 0, d5 != 0, d7 != 0 */
329 167370 z1 = d7 + d1;
330 167370 z2 = d5 + d3;
331 167370 z3 = d7 + d3;
332 167370 z4 = d5 + d1;
333 167370 z5 = MULTIPLY(z3 + z4, FIX_1_175875602);
334
335 167370 tmp0 = MULTIPLY(d7, FIX_0_298631336);
336 167370 tmp1 = MULTIPLY(d5, FIX_2_053119869);
337 167370 tmp2 = MULTIPLY(d3, FIX_3_072711026);
338 167370 tmp3 = MULTIPLY(d1, FIX_1_501321110);
339 167370 z1 = MULTIPLY(-z1, FIX_0_899976223);
340 167370 z2 = MULTIPLY(-z2, FIX_2_562915447);
341 167370 z3 = MULTIPLY(-z3, FIX_1_961570560);
342 167370 z4 = MULTIPLY(-z4, FIX_0_390180644);
343
344 167370 z3 += z5;
345 167370 z4 += z5;
346
347 167370 tmp0 += z1 + z3;
348 167370 tmp1 += z2 + z4;
349 167370 tmp2 += z2 + z3;
350 167370 tmp3 += z1 + z4;
351 } else {
352 /* d1 == 0, d3 != 0, d5 != 0, d7 != 0 */
353 5516 z2 = d5 + d3;
354 5516 z3 = d7 + d3;
355 5516 z5 = MULTIPLY(z3 + d5, FIX_1_175875602);
356
357 5516 tmp0 = MULTIPLY(d7, FIX_0_298631336);
358 5516 tmp1 = MULTIPLY(d5, FIX_2_053119869);
359 5516 tmp2 = MULTIPLY(d3, FIX_3_072711026);
360 5516 z1 = MULTIPLY(-d7, FIX_0_899976223);
361 5516 z2 = MULTIPLY(-z2, FIX_2_562915447);
362 5516 z3 = MULTIPLY(-z3, FIX_1_961570560);
363 5516 z4 = MULTIPLY(-d5, FIX_0_390180644);
364
365 5516 z3 += z5;
366 5516 z4 += z5;
367
368 5516 tmp0 += z1 + z3;
369 5516 tmp1 += z2 + z4;
370 5516 tmp2 += z2 + z3;
371 5516 tmp3 = z1 + z4;
372 }
373 } else {
374
2/2
✓ Branch 0 taken 5758 times.
✓ Branch 1 taken 11915 times.
17673 if (d1) {
375 /* d1 != 0, d3 == 0, d5 != 0, d7 != 0 */
376 5758 z1 = d7 + d1;
377 5758 z4 = d5 + d1;
378 5758 z5 = MULTIPLY(d7 + z4, FIX_1_175875602);
379
380 5758 tmp0 = MULTIPLY(d7, FIX_0_298631336);
381 5758 tmp1 = MULTIPLY(d5, FIX_2_053119869);
382 5758 tmp3 = MULTIPLY(d1, FIX_1_501321110);
383 5758 z1 = MULTIPLY(-z1, FIX_0_899976223);
384 5758 z2 = MULTIPLY(-d5, FIX_2_562915447);
385 5758 z3 = MULTIPLY(-d7, FIX_1_961570560);
386 5758 z4 = MULTIPLY(-z4, FIX_0_390180644);
387
388 5758 z3 += z5;
389 5758 z4 += z5;
390
391 5758 tmp0 += z1 + z3;
392 5758 tmp1 += z2 + z4;
393 5758 tmp2 = z2 + z3;
394 5758 tmp3 += z1 + z4;
395 } else {
396 /* d1 == 0, d3 == 0, d5 != 0, d7 != 0 */
397 11915 tmp0 = MULTIPLY(-d7, FIX_0_601344887);
398 11915 z1 = MULTIPLY(-d7, FIX_0_899976223);
399 11915 z3 = MULTIPLY(-d7, FIX_1_961570560);
400 11915 tmp1 = MULTIPLY(-d5, FIX_0_509795579);
401 11915 z2 = MULTIPLY(-d5, FIX_2_562915447);
402 11915 z4 = MULTIPLY(-d5, FIX_0_390180644);
403 11915 z5 = MULTIPLY(d5 + d7, FIX_1_175875602);
404
405 11915 z3 += z5;
406 11915 z4 += z5;
407
408 11915 tmp0 += z3;
409 11915 tmp1 += z4;
410 11915 tmp2 = z2 + z3;
411 11915 tmp3 = z1 + z4;
412 }
413 }
414 } else {
415
2/2
✓ Branch 0 taken 14745 times.
✓ Branch 1 taken 206277 times.
221022 if (d3) {
416
2/2
✓ Branch 0 taken 7521 times.
✓ Branch 1 taken 7224 times.
14745 if (d1) {
417 /* d1 != 0, d3 != 0, d5 == 0, d7 != 0 */
418 7521 z1 = d7 + d1;
419 7521 z3 = d7 + d3;
420 7521 z5 = MULTIPLY(z3 + d1, FIX_1_175875602);
421
422 7521 tmp0 = MULTIPLY(d7, FIX_0_298631336);
423 7521 tmp2 = MULTIPLY(d3, FIX_3_072711026);
424 7521 tmp3 = MULTIPLY(d1, FIX_1_501321110);
425 7521 z1 = MULTIPLY(-z1, FIX_0_899976223);
426 7521 z2 = MULTIPLY(-d3, FIX_2_562915447);
427 7521 z3 = MULTIPLY(-z3, FIX_1_961570560);
428 7521 z4 = MULTIPLY(-d1, FIX_0_390180644);
429
430 7521 z3 += z5;
431 7521 z4 += z5;
432
433 7521 tmp0 += z1 + z3;
434 7521 tmp1 = z2 + z4;
435 7521 tmp2 += z2 + z3;
436 7521 tmp3 += z1 + z4;
437 } else {
438 /* d1 == 0, d3 != 0, d5 == 0, d7 != 0 */
439 7224 z3 = d7 + d3;
440
441 7224 tmp0 = MULTIPLY(-d7, FIX_0_601344887);
442 7224 z1 = MULTIPLY(-d7, FIX_0_899976223);
443 7224 tmp2 = MULTIPLY(d3, FIX_0_509795579);
444 7224 z2 = MULTIPLY(-d3, FIX_2_562915447);
445 7224 z5 = MULTIPLY(z3, FIX_1_175875602);
446 7224 z3 = MULTIPLY(-z3, FIX_0_785694958);
447
448 7224 tmp0 += z3;
449 7224 tmp1 = z2 + z5;
450 7224 tmp2 += z3;
451 7224 tmp3 = z1 + z5;
452 }
453 } else {
454
2/2
✓ Branch 0 taken 9350 times.
✓ Branch 1 taken 196927 times.
206277 if (d1) {
455 /* d1 != 0, d3 == 0, d5 == 0, d7 != 0 */
456 9350 z1 = d7 + d1;
457 9350 z5 = MULTIPLY(z1, FIX_1_175875602);
458
459 9350 z1 = MULTIPLY(z1, FIX_0_275899380);
460 9350 z3 = MULTIPLY(-d7, FIX_1_961570560);
461 9350 tmp0 = MULTIPLY(-d7, FIX_1_662939225);
462 9350 z4 = MULTIPLY(-d1, FIX_0_390180644);
463 9350 tmp3 = MULTIPLY(d1, FIX_1_111140466);
464
465 9350 tmp0 += z1;
466 9350 tmp1 = z4 + z5;
467 9350 tmp2 = z3 + z5;
468 9350 tmp3 += z1;
469 } else {
470 /* d1 == 0, d3 == 0, d5 == 0, d7 != 0 */
471 196927 tmp0 = MULTIPLY(-d7, FIX_1_387039845);
472 196927 tmp1 = MULTIPLY(d7, FIX_1_175875602);
473 196927 tmp2 = MULTIPLY(-d7, FIX_0_785694958);
474 196927 tmp3 = MULTIPLY(d7, FIX_0_275899380);
475 }
476 }
477 }
478 } else {
479
2/2
✓ Branch 0 taken 79643 times.
✓ Branch 1 taken 391752 times.
471395 if (d5) {
480
2/2
✓ Branch 0 taken 26283 times.
✓ Branch 1 taken 53360 times.
79643 if (d3) {
481
2/2
✓ Branch 0 taken 15235 times.
✓ Branch 1 taken 11048 times.
26283 if (d1) {
482 /* d1 != 0, d3 != 0, d5 != 0, d7 == 0 */
483 15235 z2 = d5 + d3;
484 15235 z4 = d5 + d1;
485 15235 z5 = MULTIPLY(d3 + z4, FIX_1_175875602);
486
487 15235 tmp1 = MULTIPLY(d5, FIX_2_053119869);
488 15235 tmp2 = MULTIPLY(d3, FIX_3_072711026);
489 15235 tmp3 = MULTIPLY(d1, FIX_1_501321110);
490 15235 z1 = MULTIPLY(-d1, FIX_0_899976223);
491 15235 z2 = MULTIPLY(-z2, FIX_2_562915447);
492 15235 z3 = MULTIPLY(-d3, FIX_1_961570560);
493 15235 z4 = MULTIPLY(-z4, FIX_0_390180644);
494
495 15235 z3 += z5;
496 15235 z4 += z5;
497
498 15235 tmp0 = z1 + z3;
499 15235 tmp1 += z2 + z4;
500 15235 tmp2 += z2 + z3;
501 15235 tmp3 += z1 + z4;
502 } else {
503 /* d1 == 0, d3 != 0, d5 != 0, d7 == 0 */
504 11048 z2 = d5 + d3;
505
506 11048 z5 = MULTIPLY(z2, FIX_1_175875602);
507 11048 tmp1 = MULTIPLY(d5, FIX_1_662939225);
508 11048 z4 = MULTIPLY(-d5, FIX_0_390180644);
509 11048 z2 = MULTIPLY(-z2, FIX_1_387039845);
510 11048 tmp2 = MULTIPLY(d3, FIX_1_111140466);
511 11048 z3 = MULTIPLY(-d3, FIX_1_961570560);
512
513 11048 tmp0 = z3 + z5;
514 11048 tmp1 += z2;
515 11048 tmp2 += z2;
516 11048 tmp3 = z4 + z5;
517 }
518 } else {
519
2/2
✓ Branch 0 taken 11786 times.
✓ Branch 1 taken 41574 times.
53360 if (d1) {
520 /* d1 != 0, d3 == 0, d5 != 0, d7 == 0 */
521 11786 z4 = d5 + d1;
522
523 11786 z5 = MULTIPLY(z4, FIX_1_175875602);
524 11786 z1 = MULTIPLY(-d1, FIX_0_899976223);
525 11786 tmp3 = MULTIPLY(d1, FIX_0_601344887);
526 11786 tmp1 = MULTIPLY(-d5, FIX_0_509795579);
527 11786 z2 = MULTIPLY(-d5, FIX_2_562915447);
528 11786 z4 = MULTIPLY(z4, FIX_0_785694958);
529
530 11786 tmp0 = z1 + z5;
531 11786 tmp1 += z4;
532 11786 tmp2 = z2 + z5;
533 11786 tmp3 += z4;
534 } else {
535 /* d1 == 0, d3 == 0, d5 != 0, d7 == 0 */
536 41574 tmp0 = MULTIPLY(d5, FIX_1_175875602);
537 41574 tmp1 = MULTIPLY(d5, FIX_0_275899380);
538 41574 tmp2 = MULTIPLY(-d5, FIX_1_387039845);
539 41574 tmp3 = MULTIPLY(d5, FIX_0_785694958);
540 }
541 }
542 } else {
543
2/2
✓ Branch 0 taken 120034 times.
✓ Branch 1 taken 271718 times.
391752 if (d3) {
544
2/2
✓ Branch 0 taken 54120 times.
✓ Branch 1 taken 65914 times.
120034 if (d1) {
545 /* d1 != 0, d3 != 0, d5 == 0, d7 == 0 */
546 54120 z5 = d1 + d3;
547 54120 tmp3 = MULTIPLY(d1, FIX_0_211164243);
548 54120 tmp2 = MULTIPLY(-d3, FIX_1_451774981);
549 54120 z1 = MULTIPLY(d1, FIX_1_061594337);
550 54120 z2 = MULTIPLY(-d3, FIX_2_172734803);
551 54120 z4 = MULTIPLY(z5, FIX_0_785694958);
552 54120 z5 = MULTIPLY(z5, FIX_1_175875602);
553
554 54120 tmp0 = z1 - z4;
555 54120 tmp1 = z2 + z4;
556 54120 tmp2 += z5;
557 54120 tmp3 += z5;
558 } else {
559 /* d1 == 0, d3 != 0, d5 == 0, d7 == 0 */
560 65914 tmp0 = MULTIPLY(-d3, FIX_0_785694958);
561 65914 tmp1 = MULTIPLY(-d3, FIX_1_387039845);
562 65914 tmp2 = MULTIPLY(-d3, FIX_0_275899380);
563 65914 tmp3 = MULTIPLY(d3, FIX_1_175875602);
564 }
565 } else {
566
2/2
✓ Branch 0 taken 156627 times.
✓ Branch 1 taken 115091 times.
271718 if (d1) {
567 /* d1 != 0, d3 == 0, d5 == 0, d7 == 0 */
568 156627 tmp0 = MULTIPLY(d1, FIX_0_275899380);
569 156627 tmp1 = MULTIPLY(d1, FIX_0_785694958);
570 156627 tmp2 = MULTIPLY(d1, FIX_1_175875602);
571 156627 tmp3 = MULTIPLY(d1, FIX_1_387039845);
572 } else {
573 /* d1 == 0, d3 == 0, d5 == 0, d7 == 0 */
574 115091 tmp0 = tmp1 = tmp2 = tmp3 = 0;
575 }
576 }
577 }
578 }
579 }
580 /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
581
582 882976 dataptr[0] = (int16_t) DESCALE(tmp10 + tmp3, CONST_BITS-PASS1_BITS);
583 882976 dataptr[7] = (int16_t) DESCALE(tmp10 - tmp3, CONST_BITS-PASS1_BITS);
584 882976 dataptr[1] = (int16_t) DESCALE(tmp11 + tmp2, CONST_BITS-PASS1_BITS);
585 882976 dataptr[6] = (int16_t) DESCALE(tmp11 - tmp2, CONST_BITS-PASS1_BITS);
586 882976 dataptr[2] = (int16_t) DESCALE(tmp12 + tmp1, CONST_BITS-PASS1_BITS);
587 882976 dataptr[5] = (int16_t) DESCALE(tmp12 - tmp1, CONST_BITS-PASS1_BITS);
588 882976 dataptr[3] = (int16_t) DESCALE(tmp13 + tmp0, CONST_BITS-PASS1_BITS);
589 882976 dataptr[4] = (int16_t) DESCALE(tmp13 - tmp0, CONST_BITS-PASS1_BITS);
590
591 882976 dataptr += DCTSIZE; /* advance pointer to next row */
592 }
593
594 /* Pass 2: process columns. */
595 /* Note that we must descale the results by a factor of 8 == 2**3, */
596 /* and also undo the PASS1_BITS scaling. */
597
598 256369 dataptr = data;
599
2/2
✓ Branch 0 taken 2050952 times.
✓ Branch 1 taken 256369 times.
2307321 for (rowctr = DCTSIZE-1; rowctr >= 0; rowctr--) {
600 /* Columns of zeroes can be exploited in the same way as we did with rows.
601 * However, the row calculation has created many nonzero AC terms, so the
602 * simplification applies less often (typically 5% to 10% of the time).
603 * On machines with very fast multiplication, it's possible that the
604 * test takes more time than it's worth. In that case this section
605 * may be commented out.
606 */
607
608 2050952 d0 = dataptr[DCTSIZE*0];
609 2050952 d1 = dataptr[DCTSIZE*1];
610 2050952 d2 = dataptr[DCTSIZE*2];
611 2050952 d3 = dataptr[DCTSIZE*3];
612 2050952 d4 = dataptr[DCTSIZE*4];
613 2050952 d5 = dataptr[DCTSIZE*5];
614 2050952 d6 = dataptr[DCTSIZE*6];
615 2050952 d7 = dataptr[DCTSIZE*7];
616
617 /* Even part: reverse the even part of the forward DCT. */
618 /* The rotator is sqrt(2)*c(-6). */
619
2/2
✓ Branch 0 taken 589999 times.
✓ Branch 1 taken 1460953 times.
2050952 if (d6) {
620
2/2
✓ Branch 0 taken 468553 times.
✓ Branch 1 taken 121446 times.
589999 if (d2) {
621 /* d0 != 0, d2 != 0, d4 != 0, d6 != 0 */
622 468553 z1 = MULTIPLY(d2 + d6, FIX_0_541196100);
623 468553 tmp2 = z1 + MULTIPLY(-d6, FIX_1_847759065);
624 468553 tmp3 = z1 + MULTIPLY(d2, FIX_0_765366865);
625
626 468553 tmp0 = (d0 + d4) * CONST_SCALE;
627 468553 tmp1 = (d0 - d4) * CONST_SCALE;
628
629 468553 tmp10 = tmp0 + tmp3;
630 468553 tmp13 = tmp0 - tmp3;
631 468553 tmp11 = tmp1 + tmp2;
632 468553 tmp12 = tmp1 - tmp2;
633 } else {
634 /* d0 != 0, d2 == 0, d4 != 0, d6 != 0 */
635 121446 tmp2 = MULTIPLY(-d6, FIX_1_306562965);
636 121446 tmp3 = MULTIPLY(d6, FIX_0_541196100);
637
638 121446 tmp0 = (d0 + d4) * CONST_SCALE;
639 121446 tmp1 = (d0 - d4) * CONST_SCALE;
640
641 121446 tmp10 = tmp0 + tmp3;
642 121446 tmp13 = tmp0 - tmp3;
643 121446 tmp11 = tmp1 + tmp2;
644 121446 tmp12 = tmp1 - tmp2;
645 }
646 } else {
647
2/2
✓ Branch 0 taken 521497 times.
✓ Branch 1 taken 939456 times.
1460953 if (d2) {
648 /* d0 != 0, d2 != 0, d4 != 0, d6 == 0 */
649 521497 tmp2 = MULTIPLY(d2, FIX_0_541196100);
650 521497 tmp3 = MULTIPLY(d2, FIX_1_306562965);
651
652 521497 tmp0 = (d0 + d4) * CONST_SCALE;
653 521497 tmp1 = (d0 - d4) * CONST_SCALE;
654
655 521497 tmp10 = tmp0 + tmp3;
656 521497 tmp13 = tmp0 - tmp3;
657 521497 tmp11 = tmp1 + tmp2;
658 521497 tmp12 = tmp1 - tmp2;
659 } else {
660 /* d0 != 0, d2 == 0, d4 != 0, d6 == 0 */
661 939456 tmp10 = tmp13 = (d0 + d4) * CONST_SCALE;
662 939456 tmp11 = tmp12 = (d0 - d4) * CONST_SCALE;
663 }
664 }
665
666 /* Odd part per figure 8; the matrix is unitary and hence its
667 * transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively.
668 */
669
2/2
✓ Branch 0 taken 1768320 times.
✓ Branch 1 taken 282632 times.
2050952 if (d7) {
670
2/2
✓ Branch 0 taken 617078 times.
✓ Branch 1 taken 1151242 times.
1768320 if (d5) {
671
2/2
✓ Branch 0 taken 500254 times.
✓ Branch 1 taken 116824 times.
617078 if (d3) {
672
2/2
✓ Branch 0 taken 435172 times.
✓ Branch 1 taken 65082 times.
500254 if (d1) {
673 /* d1 != 0, d3 != 0, d5 != 0, d7 != 0 */
674 435172 z1 = d7 + d1;
675 435172 z2 = d5 + d3;
676 435172 z3 = d7 + d3;
677 435172 z4 = d5 + d1;
678 435172 z5 = MULTIPLY(z3 + z4, FIX_1_175875602);
679
680 435172 tmp0 = MULTIPLY(d7, FIX_0_298631336);
681 435172 tmp1 = MULTIPLY(d5, FIX_2_053119869);
682 435172 tmp2 = MULTIPLY(d3, FIX_3_072711026);
683 435172 tmp3 = MULTIPLY(d1, FIX_1_501321110);
684 435172 z1 = MULTIPLY(-z1, FIX_0_899976223);
685 435172 z2 = MULTIPLY(-z2, FIX_2_562915447);
686 435172 z3 = MULTIPLY(-z3, FIX_1_961570560);
687 435172 z4 = MULTIPLY(-z4, FIX_0_390180644);
688
689 435172 z3 += z5;
690 435172 z4 += z5;
691
692 435172 tmp0 += z1 + z3;
693 435172 tmp1 += z2 + z4;
694 435172 tmp2 += z2 + z3;
695 435172 tmp3 += z1 + z4;
696 } else {
697 /* d1 == 0, d3 != 0, d5 != 0, d7 != 0 */
698 65082 z2 = d5 + d3;
699 65082 z3 = d7 + d3;
700 65082 z5 = MULTIPLY(z3 + d5, FIX_1_175875602);
701
702 65082 tmp0 = MULTIPLY(d7, FIX_0_298631336);
703 65082 tmp1 = MULTIPLY(d5, FIX_2_053119869);
704 65082 tmp2 = MULTIPLY(d3, FIX_3_072711026);
705 65082 z1 = MULTIPLY(-d7, FIX_0_899976223);
706 65082 z2 = MULTIPLY(-z2, FIX_2_562915447);
707 65082 z3 = MULTIPLY(-z3, FIX_1_961570560);
708 65082 z4 = MULTIPLY(-d5, FIX_0_390180644);
709
710 65082 z3 += z5;
711 65082 z4 += z5;
712
713 65082 tmp0 += z1 + z3;
714 65082 tmp1 += z2 + z4;
715 65082 tmp2 += z2 + z3;
716 65082 tmp3 = z1 + z4;
717 }
718 } else {
719
2/2
✓ Branch 0 taken 48317 times.
✓ Branch 1 taken 68507 times.
116824 if (d1) {
720 /* d1 != 0, d3 == 0, d5 != 0, d7 != 0 */
721 48317 z1 = d7 + d1;
722 48317 z3 = d7;
723 48317 z4 = d5 + d1;
724 48317 z5 = MULTIPLY(z3 + z4, FIX_1_175875602);
725
726 48317 tmp0 = MULTIPLY(d7, FIX_0_298631336);
727 48317 tmp1 = MULTIPLY(d5, FIX_2_053119869);
728 48317 tmp3 = MULTIPLY(d1, FIX_1_501321110);
729 48317 z1 = MULTIPLY(-z1, FIX_0_899976223);
730 48317 z2 = MULTIPLY(-d5, FIX_2_562915447);
731 48317 z3 = MULTIPLY(-d7, FIX_1_961570560);
732 48317 z4 = MULTIPLY(-z4, FIX_0_390180644);
733
734 48317 z3 += z5;
735 48317 z4 += z5;
736
737 48317 tmp0 += z1 + z3;
738 48317 tmp1 += z2 + z4;
739 48317 tmp2 = z2 + z3;
740 48317 tmp3 += z1 + z4;
741 } else {
742 /* d1 == 0, d3 == 0, d5 != 0, d7 != 0 */
743 68507 tmp0 = MULTIPLY(-d7, FIX_0_601344887);
744 68507 z1 = MULTIPLY(-d7, FIX_0_899976223);
745 68507 z3 = MULTIPLY(-d7, FIX_1_961570560);
746 68507 tmp1 = MULTIPLY(-d5, FIX_0_509795579);
747 68507 z2 = MULTIPLY(-d5, FIX_2_562915447);
748 68507 z4 = MULTIPLY(-d5, FIX_0_390180644);
749 68507 z5 = MULTIPLY(d5 + d7, FIX_1_175875602);
750
751 68507 z3 += z5;
752 68507 z4 += z5;
753
754 68507 tmp0 += z3;
755 68507 tmp1 += z4;
756 68507 tmp2 = z2 + z3;
757 68507 tmp3 = z1 + z4;
758 }
759 }
760 } else {
761
2/2
✓ Branch 0 taken 286145 times.
✓ Branch 1 taken 865097 times.
1151242 if (d3) {
762
2/2
✓ Branch 0 taken 178231 times.
✓ Branch 1 taken 107914 times.
286145 if (d1) {
763 /* d1 != 0, d3 != 0, d5 == 0, d7 != 0 */
764 178231 z1 = d7 + d1;
765 178231 z3 = d7 + d3;
766 178231 z5 = MULTIPLY(z3 + d1, FIX_1_175875602);
767
768 178231 tmp0 = MULTIPLY(d7, FIX_0_298631336);
769 178231 tmp2 = MULTIPLY(d3, FIX_3_072711026);
770 178231 tmp3 = MULTIPLY(d1, FIX_1_501321110);
771 178231 z1 = MULTIPLY(-z1, FIX_0_899976223);
772 178231 z2 = MULTIPLY(-d3, FIX_2_562915447);
773 178231 z3 = MULTIPLY(-z3, FIX_1_961570560);
774 178231 z4 = MULTIPLY(-d1, FIX_0_390180644);
775
776 178231 z3 += z5;
777 178231 z4 += z5;
778
779 178231 tmp0 += z1 + z3;
780 178231 tmp1 = z2 + z4;
781 178231 tmp2 += z2 + z3;
782 178231 tmp3 += z1 + z4;
783 } else {
784 /* d1 == 0, d3 != 0, d5 == 0, d7 != 0 */
785 107914 z3 = d7 + d3;
786
787 107914 tmp0 = MULTIPLY(-d7, FIX_0_601344887);
788 107914 z1 = MULTIPLY(-d7, FIX_0_899976223);
789 107914 tmp2 = MULTIPLY(d3, FIX_0_509795579);
790 107914 z2 = MULTIPLY(-d3, FIX_2_562915447);
791 107914 z5 = MULTIPLY(z3, FIX_1_175875602);
792 107914 z3 = MULTIPLY(-z3, FIX_0_785694958);
793
794 107914 tmp0 += z3;
795 107914 tmp1 = z2 + z5;
796 107914 tmp2 += z3;
797 107914 tmp3 = z1 + z5;
798 }
799 } else {
800
2/2
✓ Branch 0 taken 318049 times.
✓ Branch 1 taken 547048 times.
865097 if (d1) {
801 /* d1 != 0, d3 == 0, d5 == 0, d7 != 0 */
802 318049 z1 = d7 + d1;
803 318049 z5 = MULTIPLY(z1, FIX_1_175875602);
804
805 318049 z1 = MULTIPLY(z1, FIX_0_275899380);
806 318049 z3 = MULTIPLY(-d7, FIX_1_961570560);
807 318049 tmp0 = MULTIPLY(-d7, FIX_1_662939225);
808 318049 z4 = MULTIPLY(-d1, FIX_0_390180644);
809 318049 tmp3 = MULTIPLY(d1, FIX_1_111140466);
810
811 318049 tmp0 += z1;
812 318049 tmp1 = z4 + z5;
813 318049 tmp2 = z3 + z5;
814 318049 tmp3 += z1;
815 } else {
816 /* d1 == 0, d3 == 0, d5 == 0, d7 != 0 */
817 547048 tmp0 = MULTIPLY(-d7, FIX_1_387039845);
818 547048 tmp1 = MULTIPLY(d7, FIX_1_175875602);
819 547048 tmp2 = MULTIPLY(-d7, FIX_0_785694958);
820 547048 tmp3 = MULTIPLY(d7, FIX_0_275899380);
821 }
822 }
823 }
824 } else {
825
2/2
✓ Branch 0 taken 60109 times.
✓ Branch 1 taken 222523 times.
282632 if (d5) {
826
2/2
✓ Branch 0 taken 38480 times.
✓ Branch 1 taken 21629 times.
60109 if (d3) {
827
2/2
✓ Branch 0 taken 29431 times.
✓ Branch 1 taken 9049 times.
38480 if (d1) {
828 /* d1 != 0, d3 != 0, d5 != 0, d7 == 0 */
829 29431 z2 = d5 + d3;
830 29431 z4 = d5 + d1;
831 29431 z5 = MULTIPLY(d3 + z4, FIX_1_175875602);
832
833 29431 tmp1 = MULTIPLY(d5, FIX_2_053119869);
834 29431 tmp2 = MULTIPLY(d3, FIX_3_072711026);
835 29431 tmp3 = MULTIPLY(d1, FIX_1_501321110);
836 29431 z1 = MULTIPLY(-d1, FIX_0_899976223);
837 29431 z2 = MULTIPLY(-z2, FIX_2_562915447);
838 29431 z3 = MULTIPLY(-d3, FIX_1_961570560);
839 29431 z4 = MULTIPLY(-z4, FIX_0_390180644);
840
841 29431 z3 += z5;
842 29431 z4 += z5;
843
844 29431 tmp0 = z1 + z3;
845 29431 tmp1 += z2 + z4;
846 29431 tmp2 += z2 + z3;
847 29431 tmp3 += z1 + z4;
848 } else {
849 /* d1 == 0, d3 != 0, d5 != 0, d7 == 0 */
850 9049 z2 = d5 + d3;
851
852 9049 z5 = MULTIPLY(z2, FIX_1_175875602);
853 9049 tmp1 = MULTIPLY(d5, FIX_1_662939225);
854 9049 z4 = MULTIPLY(-d5, FIX_0_390180644);
855 9049 z2 = MULTIPLY(-z2, FIX_1_387039845);
856 9049 tmp2 = MULTIPLY(d3, FIX_1_111140466);
857 9049 z3 = MULTIPLY(-d3, FIX_1_961570560);
858
859 9049 tmp0 = z3 + z5;
860 9049 tmp1 += z2;
861 9049 tmp2 += z2;
862 9049 tmp3 = z4 + z5;
863 }
864 } else {
865
2/2
✓ Branch 0 taken 9952 times.
✓ Branch 1 taken 11677 times.
21629 if (d1) {
866 /* d1 != 0, d3 == 0, d5 != 0, d7 == 0 */
867 9952 z4 = d5 + d1;
868
869 9952 z5 = MULTIPLY(z4, FIX_1_175875602);
870 9952 z1 = MULTIPLY(-d1, FIX_0_899976223);
871 9952 tmp3 = MULTIPLY(d1, FIX_0_601344887);
872 9952 tmp1 = MULTIPLY(-d5, FIX_0_509795579);
873 9952 z2 = MULTIPLY(-d5, FIX_2_562915447);
874 9952 z4 = MULTIPLY(z4, FIX_0_785694958);
875
876 9952 tmp0 = z1 + z5;
877 9952 tmp1 += z4;
878 9952 tmp2 = z2 + z5;
879 9952 tmp3 += z4;
880 } else {
881 /* d1 == 0, d3 == 0, d5 != 0, d7 == 0 */
882 11677 tmp0 = MULTIPLY(d5, FIX_1_175875602);
883 11677 tmp1 = MULTIPLY(d5, FIX_0_275899380);
884 11677 tmp2 = MULTIPLY(-d5, FIX_1_387039845);
885 11677 tmp3 = MULTIPLY(d5, FIX_0_785694958);
886 }
887 }
888 } else {
889
2/2
✓ Branch 0 taken 62081 times.
✓ Branch 1 taken 160442 times.
222523 if (d3) {
890
2/2
✓ Branch 0 taken 49179 times.
✓ Branch 1 taken 12902 times.
62081 if (d1) {
891 /* d1 != 0, d3 != 0, d5 == 0, d7 == 0 */
892 49179 z5 = d1 + d3;
893 49179 tmp3 = MULTIPLY(d1, FIX_0_211164243);
894 49179 tmp2 = MULTIPLY(-d3, FIX_1_451774981);
895 49179 z1 = MULTIPLY(d1, FIX_1_061594337);
896 49179 z2 = MULTIPLY(-d3, FIX_2_172734803);
897 49179 z4 = MULTIPLY(z5, FIX_0_785694958);
898 49179 z5 = MULTIPLY(z5, FIX_1_175875602);
899
900 49179 tmp0 = z1 - z4;
901 49179 tmp1 = z2 + z4;
902 49179 tmp2 += z5;
903 49179 tmp3 += z5;
904 } else {
905 /* d1 == 0, d3 != 0, d5 == 0, d7 == 0 */
906 12902 tmp0 = MULTIPLY(-d3, FIX_0_785694958);
907 12902 tmp1 = MULTIPLY(-d3, FIX_1_387039845);
908 12902 tmp2 = MULTIPLY(-d3, FIX_0_275899380);
909 12902 tmp3 = MULTIPLY(d3, FIX_1_175875602);
910 }
911 } else {
912
2/2
✓ Branch 0 taken 53235 times.
✓ Branch 1 taken 107207 times.
160442 if (d1) {
913 /* d1 != 0, d3 == 0, d5 == 0, d7 == 0 */
914 53235 tmp0 = MULTIPLY(d1, FIX_0_275899380);
915 53235 tmp1 = MULTIPLY(d1, FIX_0_785694958);
916 53235 tmp2 = MULTIPLY(d1, FIX_1_175875602);
917 53235 tmp3 = MULTIPLY(d1, FIX_1_387039845);
918 } else {
919 /* d1 == 0, d3 == 0, d5 == 0, d7 == 0 */
920 107207 tmp0 = tmp1 = tmp2 = tmp3 = 0;
921 }
922 }
923 }
924 }
925
926 /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
927
928 2050952 dataptr[DCTSIZE*0] = (int16_t) DESCALE(tmp10 + tmp3,
929 CONST_BITS+PASS1_BITS+3);
930 2050952 dataptr[DCTSIZE*7] = (int16_t) DESCALE(tmp10 - tmp3,
931 CONST_BITS+PASS1_BITS+3);
932 2050952 dataptr[DCTSIZE*1] = (int16_t) DESCALE(tmp11 + tmp2,
933 CONST_BITS+PASS1_BITS+3);
934 2050952 dataptr[DCTSIZE*6] = (int16_t) DESCALE(tmp11 - tmp2,
935 CONST_BITS+PASS1_BITS+3);
936 2050952 dataptr[DCTSIZE*2] = (int16_t) DESCALE(tmp12 + tmp1,
937 CONST_BITS+PASS1_BITS+3);
938 2050952 dataptr[DCTSIZE*5] = (int16_t) DESCALE(tmp12 - tmp1,
939 CONST_BITS+PASS1_BITS+3);
940 2050952 dataptr[DCTSIZE*3] = (int16_t) DESCALE(tmp13 + tmp0,
941 CONST_BITS+PASS1_BITS+3);
942 2050952 dataptr[DCTSIZE*4] = (int16_t) DESCALE(tmp13 - tmp0,
943 CONST_BITS+PASS1_BITS+3);
944
945 2050952 dataptr++; /* advance pointer to next column */
946 }
947 256369 }
948
949 #undef DCTSIZE
950 #define DCTSIZE 4
951 #define DCTSTRIDE 8
952
953 88025 void ff_j_rev_dct4(DCTBLOCK data)
954 {
955 int32_t tmp0, tmp1, tmp2, tmp3;
956 int32_t tmp10, tmp11, tmp12, tmp13;
957 int32_t z1;
958 int32_t d0, d2, d4, d6;
959 register int16_t *dataptr;
960 int rowctr;
961
962 /* Pass 1: process rows. */
963 /* Note results are scaled up by sqrt(8) compared to a true IDCT; */
964 /* furthermore, we scale the results by 2**PASS1_BITS. */
965
966 88025 data[0] += 4;
967
968 88025 dataptr = data;
969
970
2/2
✓ Branch 0 taken 352100 times.
✓ Branch 1 taken 88025 times.
440125 for (rowctr = DCTSIZE-1; rowctr >= 0; rowctr--) {
971 /* Due to quantization, we will usually find that many of the input
972 * coefficients are zero, especially the AC terms. We can exploit this
973 * by short-circuiting the IDCT calculation for any row in which all
974 * the AC terms are zero. In that case each output is equal to the
975 * DC coefficient (with scale factor as needed).
976 * With typical images and quantization tables, half or more of the
977 * row DCT calculations can be simplified this way.
978 */
979
980 352100 register uint8_t *idataptr = (uint8_t*)dataptr;
981
982 352100 d0 = dataptr[0];
983 352100 d2 = dataptr[1];
984 352100 d4 = dataptr[2];
985 352100 d6 = dataptr[3];
986
987
2/2
✓ Branch 0 taken 152603 times.
✓ Branch 1 taken 199497 times.
352100 if ((d2 | d4 | d6) == 0) {
988 /* AC terms all zero */
989
2/2
✓ Branch 0 taken 47562 times.
✓ Branch 1 taken 105041 times.
152603 if (d0) {
990 /* Compute a 32 bit value to assign. */
991 47562 int16_t dcval = (int16_t) (d0 * (1 << PASS1_BITS));
992 47562 register unsigned v = (dcval & 0xffff) | ((uint32_t)dcval << 16);
993
994 47562 AV_WN32A(&idataptr[0], v);
995 47562 AV_WN32A(&idataptr[4], v);
996 }
997
998 152603 dataptr += DCTSTRIDE; /* advance pointer to next row */
999 152603 continue;
1000 }
1001
1002 /* Even part: reverse the even part of the forward DCT. */
1003 /* The rotator is sqrt(2)*c(-6). */
1004
2/2
✓ Branch 0 taken 99787 times.
✓ Branch 1 taken 99710 times.
199497 if (d6) {
1005
2/2
✓ Branch 0 taken 70211 times.
✓ Branch 1 taken 29576 times.
99787 if (d2) {
1006 /* d0 != 0, d2 != 0, d4 != 0, d6 != 0 */
1007 70211 z1 = MULTIPLY(d2 + d6, FIX_0_541196100);
1008 70211 tmp2 = z1 + MULTIPLY(-d6, FIX_1_847759065);
1009 70211 tmp3 = z1 + MULTIPLY(d2, FIX_0_765366865);
1010
1011 70211 tmp0 = (d0 + d4) * (1 << CONST_BITS);
1012 70211 tmp1 = (d0 - d4) * (1 << CONST_BITS);
1013
1014 70211 tmp10 = tmp0 + tmp3;
1015 70211 tmp13 = tmp0 - tmp3;
1016 70211 tmp11 = tmp1 + tmp2;
1017 70211 tmp12 = tmp1 - tmp2;
1018 } else {
1019 /* d0 != 0, d2 == 0, d4 != 0, d6 != 0 */
1020 29576 tmp2 = MULTIPLY(-d6, FIX_1_306562965);
1021 29576 tmp3 = MULTIPLY(d6, FIX_0_541196100);
1022
1023 29576 tmp0 = (d0 + d4) * (1 << CONST_BITS);
1024 29576 tmp1 = (d0 - d4) * (1 << CONST_BITS);
1025
1026 29576 tmp10 = tmp0 + tmp3;
1027 29576 tmp13 = tmp0 - tmp3;
1028 29576 tmp11 = tmp1 + tmp2;
1029 29576 tmp12 = tmp1 - tmp2;
1030 }
1031 } else {
1032
2/2
✓ Branch 0 taken 75107 times.
✓ Branch 1 taken 24603 times.
99710 if (d2) {
1033 /* d0 != 0, d2 != 0, d4 != 0, d6 == 0 */
1034 75107 tmp2 = MULTIPLY(d2, FIX_0_541196100);
1035 75107 tmp3 = MULTIPLY(d2, FIX_1_306562965);
1036
1037 75107 tmp0 = (d0 + d4) * (1 << CONST_BITS);
1038 75107 tmp1 = (d0 - d4) * (1 << CONST_BITS);
1039
1040 75107 tmp10 = tmp0 + tmp3;
1041 75107 tmp13 = tmp0 - tmp3;
1042 75107 tmp11 = tmp1 + tmp2;
1043 75107 tmp12 = tmp1 - tmp2;
1044 } else {
1045 /* d0 != 0, d2 == 0, d4 != 0, d6 == 0 */
1046 24603 tmp10 = tmp13 = (d0 + d4) * (1 << CONST_BITS);
1047 24603 tmp11 = tmp12 = (d0 - d4) * (1 << CONST_BITS);
1048 }
1049 }
1050
1051 /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
1052
1053 199497 dataptr[0] = (int16_t) DESCALE(tmp10, CONST_BITS-PASS1_BITS);
1054 199497 dataptr[1] = (int16_t) DESCALE(tmp11, CONST_BITS-PASS1_BITS);
1055 199497 dataptr[2] = (int16_t) DESCALE(tmp12, CONST_BITS-PASS1_BITS);
1056 199497 dataptr[3] = (int16_t) DESCALE(tmp13, CONST_BITS-PASS1_BITS);
1057
1058 199497 dataptr += DCTSTRIDE; /* advance pointer to next row */
1059 }
1060
1061 /* Pass 2: process columns. */
1062 /* Note that we must descale the results by a factor of 8 == 2**3, */
1063 /* and also undo the PASS1_BITS scaling. */
1064
1065 88025 dataptr = data;
1066
2/2
✓ Branch 0 taken 352100 times.
✓ Branch 1 taken 88025 times.
440125 for (rowctr = DCTSIZE-1; rowctr >= 0; rowctr--) {
1067 /* Columns of zeroes can be exploited in the same way as we did with rows.
1068 * However, the row calculation has created many nonzero AC terms, so the
1069 * simplification applies less often (typically 5% to 10% of the time).
1070 * On machines with very fast multiplication, it's possible that the
1071 * test takes more time than it's worth. In that case this section
1072 * may be commented out.
1073 */
1074
1075 352100 d0 = dataptr[DCTSTRIDE*0];
1076 352100 d2 = dataptr[DCTSTRIDE*1];
1077 352100 d4 = dataptr[DCTSTRIDE*2];
1078 352100 d6 = dataptr[DCTSTRIDE*3];
1079
1080 /* Even part: reverse the even part of the forward DCT. */
1081 /* The rotator is sqrt(2)*c(-6). */
1082
2/2
✓ Branch 0 taken 171607 times.
✓ Branch 1 taken 180493 times.
352100 if (d6) {
1083
2/2
✓ Branch 0 taken 159810 times.
✓ Branch 1 taken 11797 times.
171607 if (d2) {
1084 /* d0 != 0, d2 != 0, d4 != 0, d6 != 0 */
1085 159810 z1 = MULTIPLY(d2 + d6, FIX_0_541196100);
1086 159810 tmp2 = z1 + MULTIPLY(-d6, FIX_1_847759065);
1087 159810 tmp3 = z1 + MULTIPLY(d2, FIX_0_765366865);
1088
1089 159810 tmp0 = (d0 + d4) * (1 << CONST_BITS);
1090 159810 tmp1 = (d0 - d4) * (1 << CONST_BITS);
1091
1092 159810 tmp10 = tmp0 + tmp3;
1093 159810 tmp13 = tmp0 - tmp3;
1094 159810 tmp11 = tmp1 + tmp2;
1095 159810 tmp12 = tmp1 - tmp2;
1096 } else {
1097 /* d0 != 0, d2 == 0, d4 != 0, d6 != 0 */
1098 11797 tmp2 = MULTIPLY(-d6, FIX_1_306562965);
1099 11797 tmp3 = MULTIPLY(d6, FIX_0_541196100);
1100
1101 11797 tmp0 = (d0 + d4) * (1 << CONST_BITS);
1102 11797 tmp1 = (d0 - d4) * (1 << CONST_BITS);
1103
1104 11797 tmp10 = tmp0 + tmp3;
1105 11797 tmp13 = tmp0 - tmp3;
1106 11797 tmp11 = tmp1 + tmp2;
1107 11797 tmp12 = tmp1 - tmp2;
1108 }
1109 } else {
1110
2/2
✓ Branch 0 taken 84921 times.
✓ Branch 1 taken 95572 times.
180493 if (d2) {
1111 /* d0 != 0, d2 != 0, d4 != 0, d6 == 0 */
1112 84921 tmp2 = MULTIPLY(d2, FIX_0_541196100);
1113 84921 tmp3 = MULTIPLY(d2, FIX_1_306562965);
1114
1115 84921 tmp0 = (d0 + d4) * (1 << CONST_BITS);
1116 84921 tmp1 = (d0 - d4) * (1 << CONST_BITS);
1117
1118 84921 tmp10 = tmp0 + tmp3;
1119 84921 tmp13 = tmp0 - tmp3;
1120 84921 tmp11 = tmp1 + tmp2;
1121 84921 tmp12 = tmp1 - tmp2;
1122 } else {
1123 /* d0 != 0, d2 == 0, d4 != 0, d6 == 0 */
1124 95572 tmp10 = tmp13 = (d0 + d4) * (1 << CONST_BITS);
1125 95572 tmp11 = tmp12 = (d0 - d4) * (1 << CONST_BITS);
1126 }
1127 }
1128
1129 /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
1130
1131 352100 dataptr[DCTSTRIDE*0] = tmp10 >> (CONST_BITS+PASS1_BITS+3);
1132 352100 dataptr[DCTSTRIDE*1] = tmp11 >> (CONST_BITS+PASS1_BITS+3);
1133 352100 dataptr[DCTSTRIDE*2] = tmp12 >> (CONST_BITS+PASS1_BITS+3);
1134 352100 dataptr[DCTSTRIDE*3] = tmp13 >> (CONST_BITS+PASS1_BITS+3);
1135
1136 352100 dataptr++; /* advance pointer to next column */
1137 }
1138 88025 }
1139
1140 void ff_j_rev_dct2(DCTBLOCK data){
1141 int d00, d01, d10, d11;
1142
1143 data[0] += 4;
1144 d00 = data[0+0*DCTSTRIDE] + data[1+0*DCTSTRIDE];
1145 d01 = data[0+0*DCTSTRIDE] - data[1+0*DCTSTRIDE];
1146 d10 = data[0+1*DCTSTRIDE] + data[1+1*DCTSTRIDE];
1147 d11 = data[0+1*DCTSTRIDE] - data[1+1*DCTSTRIDE];
1148
1149 data[0+0*DCTSTRIDE]= (d00 + d10)>>3;
1150 data[1+0*DCTSTRIDE]= (d01 + d11)>>3;
1151 data[0+1*DCTSTRIDE]= (d00 - d10)>>3;
1152 data[1+1*DCTSTRIDE]= (d01 - d11)>>3;
1153 }
1154
1155 void ff_j_rev_dct1(DCTBLOCK data){
1156 data[0] = (data[0] + 4)>>3;
1157 }
1158
1159 #undef FIX
1160 #undef CONST_BITS
1161
1162 48432 void ff_jref_idct_put(uint8_t *dest, ptrdiff_t line_size, int16_t block[64])
1163 {
1164 48432 ff_j_rev_dct(block);
1165 48432 ff_put_pixels_clamped_c(block, dest, line_size);
1166 48432 }
1167
1168 147937 void ff_jref_idct_add(uint8_t *dest, ptrdiff_t line_size, int16_t block[64])
1169 {
1170 147937 ff_j_rev_dct(block);
1171 147937 ff_add_pixels_clamped_c(block, dest, line_size);
1172 147937 }
1173