FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/jrevdct.c
Date: 2026-10-02 13:12:02
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 259299 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 259299 dataptr = data;
229
230
2/2
✓ Branch 0 taken 2074392 times.
✓ Branch 1 taken 259299 times.
2333691 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 2074392 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 2074392 d0 = dataptr[0];
245 2074392 d2 = dataptr[1];
246 2074392 d4 = dataptr[2];
247 2074392 d6 = dataptr[3];
248 2074392 d1 = dataptr[4];
249 2074392 d3 = dataptr[5];
250 2074392 d5 = dataptr[6];
251 2074392 d7 = dataptr[7];
252
253
2/2
✓ Branch 0 taken 1179655 times.
✓ Branch 1 taken 894737 times.
2074392 if ((d1 | d2 | d3 | d4 | d5 | d6 | d7) == 0) {
254 /* AC terms all zero */
255
2/2
✓ Branch 0 taken 167699 times.
✓ Branch 1 taken 1011956 times.
1179655 if (d0) {
256 /* Compute a 32 bit value to assign. */
257 167699 int16_t dcval = (int16_t) (d0 * (1 << PASS1_BITS));
258 167699 register unsigned v = (dcval & 0xffff) | ((uint32_t)dcval << 16);
259
260 167699 AV_WN32A(&idataptr[ 0], v);
261 167699 AV_WN32A(&idataptr[ 4], v);
262 167699 AV_WN32A(&idataptr[ 8], v);
263 167699 AV_WN32A(&idataptr[12], v);
264 }
265
266 1179655 dataptr += DCTSIZE; /* advance pointer to next row */
267 1179655 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 252941 times.
✓ Branch 1 taken 641796 times.
894737 if (d6) {
274
2/2
✓ Branch 0 taken 195292 times.
✓ Branch 1 taken 57649 times.
252941 if (d2) {
275 /* d0 != 0, d2 != 0, d4 != 0, d6 != 0 */
276 195292 z1 = MULTIPLY(d2 + d6, FIX_0_541196100);
277 195292 tmp2 = z1 + MULTIPLY(-d6, FIX_1_847759065);
278 195292 tmp3 = z1 + MULTIPLY(d2, FIX_0_765366865);
279
280 195292 tmp0 = (d0 + d4) * CONST_SCALE;
281 195292 tmp1 = (d0 - d4) * CONST_SCALE;
282
283 195292 tmp10 = tmp0 + tmp3;
284 195292 tmp13 = tmp0 - tmp3;
285 195292 tmp11 = tmp1 + tmp2;
286 195292 tmp12 = tmp1 - tmp2;
287 } else {
288 /* d0 != 0, d2 == 0, d4 != 0, d6 != 0 */
289 57649 tmp2 = MULTIPLY(-d6, FIX_1_306562965);
290 57649 tmp3 = MULTIPLY(d6, FIX_0_541196100);
291
292 57649 tmp0 = (d0 + d4) * CONST_SCALE;
293 57649 tmp1 = (d0 - d4) * CONST_SCALE;
294
295 57649 tmp10 = tmp0 + tmp3;
296 57649 tmp13 = tmp0 - tmp3;
297 57649 tmp11 = tmp1 + tmp2;
298 57649 tmp12 = tmp1 - tmp2;
299 }
300 } else {
301
2/2
✓ Branch 0 taken 191547 times.
✓ Branch 1 taken 450249 times.
641796 if (d2) {
302 /* d0 != 0, d2 != 0, d4 != 0, d6 == 0 */
303 191547 tmp2 = MULTIPLY(d2, FIX_0_541196100);
304 191547 tmp3 = MULTIPLY(d2, FIX_1_306562965);
305
306 191547 tmp0 = (d0 + d4) * CONST_SCALE;
307 191547 tmp1 = (d0 - d4) * CONST_SCALE;
308
309 191547 tmp10 = tmp0 + tmp3;
310 191547 tmp13 = tmp0 - tmp3;
311 191547 tmp11 = tmp1 + tmp2;
312 191547 tmp12 = tmp1 - tmp2;
313 } else {
314 /* d0 != 0, d2 == 0, d4 != 0, d6 == 0 */
315 450249 tmp10 = tmp13 = (d0 + d4) * CONST_SCALE;
316 450249 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 417750 times.
✓ Branch 1 taken 476987 times.
894737 if (d7) {
325
2/2
✓ Branch 0 taken 195485 times.
✓ Branch 1 taken 222265 times.
417750 if (d5) {
326
2/2
✓ Branch 0 taken 177710 times.
✓ Branch 1 taken 17775 times.
195485 if (d3) {
327
2/2
✓ Branch 0 taken 172135 times.
✓ Branch 1 taken 5575 times.
177710 if (d1) {
328 /* d1 != 0, d3 != 0, d5 != 0, d7 != 0 */
329 172135 z1 = d7 + d1;
330 172135 z2 = d5 + d3;
331 172135 z3 = d7 + d3;
332 172135 z4 = d5 + d1;
333 172135 z5 = MULTIPLY(z3 + z4, FIX_1_175875602);
334
335 172135 tmp0 = MULTIPLY(d7, FIX_0_298631336);
336 172135 tmp1 = MULTIPLY(d5, FIX_2_053119869);
337 172135 tmp2 = MULTIPLY(d3, FIX_3_072711026);
338 172135 tmp3 = MULTIPLY(d1, FIX_1_501321110);
339 172135 z1 = MULTIPLY(-z1, FIX_0_899976223);
340 172135 z2 = MULTIPLY(-z2, FIX_2_562915447);
341 172135 z3 = MULTIPLY(-z3, FIX_1_961570560);
342 172135 z4 = MULTIPLY(-z4, FIX_0_390180644);
343
344 172135 z3 += z5;
345 172135 z4 += z5;
346
347 172135 tmp0 += z1 + z3;
348 172135 tmp1 += z2 + z4;
349 172135 tmp2 += z2 + z3;
350 172135 tmp3 += z1 + z4;
351 } else {
352 /* d1 == 0, d3 != 0, d5 != 0, d7 != 0 */
353 5575 z2 = d5 + d3;
354 5575 z3 = d7 + d3;
355 5575 z5 = MULTIPLY(z3 + d5, FIX_1_175875602);
356
357 5575 tmp0 = MULTIPLY(d7, FIX_0_298631336);
358 5575 tmp1 = MULTIPLY(d5, FIX_2_053119869);
359 5575 tmp2 = MULTIPLY(d3, FIX_3_072711026);
360 5575 z1 = MULTIPLY(-d7, FIX_0_899976223);
361 5575 z2 = MULTIPLY(-z2, FIX_2_562915447);
362 5575 z3 = MULTIPLY(-z3, FIX_1_961570560);
363 5575 z4 = MULTIPLY(-d5, FIX_0_390180644);
364
365 5575 z3 += z5;
366 5575 z4 += z5;
367
368 5575 tmp0 += z1 + z3;
369 5575 tmp1 += z2 + z4;
370 5575 tmp2 += z2 + z3;
371 5575 tmp3 = z1 + z4;
372 }
373 } else {
374
2/2
✓ Branch 0 taken 6109 times.
✓ Branch 1 taken 11666 times.
17775 if (d1) {
375 /* d1 != 0, d3 == 0, d5 != 0, d7 != 0 */
376 6109 z1 = d7 + d1;
377 6109 z4 = d5 + d1;
378 6109 z5 = MULTIPLY(d7 + z4, FIX_1_175875602);
379
380 6109 tmp0 = MULTIPLY(d7, FIX_0_298631336);
381 6109 tmp1 = MULTIPLY(d5, FIX_2_053119869);
382 6109 tmp3 = MULTIPLY(d1, FIX_1_501321110);
383 6109 z1 = MULTIPLY(-z1, FIX_0_899976223);
384 6109 z2 = MULTIPLY(-d5, FIX_2_562915447);
385 6109 z3 = MULTIPLY(-d7, FIX_1_961570560);
386 6109 z4 = MULTIPLY(-z4, FIX_0_390180644);
387
388 6109 z3 += z5;
389 6109 z4 += z5;
390
391 6109 tmp0 += z1 + z3;
392 6109 tmp1 += z2 + z4;
393 6109 tmp2 = z2 + z3;
394 6109 tmp3 += z1 + z4;
395 } else {
396 /* d1 == 0, d3 == 0, d5 != 0, d7 != 0 */
397 11666 tmp0 = MULTIPLY(-d7, FIX_0_601344887);
398 11666 z1 = MULTIPLY(-d7, FIX_0_899976223);
399 11666 z3 = MULTIPLY(-d7, FIX_1_961570560);
400 11666 tmp1 = MULTIPLY(-d5, FIX_0_509795579);
401 11666 z2 = MULTIPLY(-d5, FIX_2_562915447);
402 11666 z4 = MULTIPLY(-d5, FIX_0_390180644);
403 11666 z5 = MULTIPLY(d5 + d7, FIX_1_175875602);
404
405 11666 z3 += z5;
406 11666 z4 += z5;
407
408 11666 tmp0 += z3;
409 11666 tmp1 += z4;
410 11666 tmp2 = z2 + z3;
411 11666 tmp3 = z1 + z4;
412 }
413 }
414 } else {
415
2/2
✓ Branch 0 taken 15459 times.
✓ Branch 1 taken 206806 times.
222265 if (d3) {
416
2/2
✓ Branch 0 taken 8303 times.
✓ Branch 1 taken 7156 times.
15459 if (d1) {
417 /* d1 != 0, d3 != 0, d5 == 0, d7 != 0 */
418 8303 z1 = d7 + d1;
419 8303 z3 = d7 + d3;
420 8303 z5 = MULTIPLY(z3 + d1, FIX_1_175875602);
421
422 8303 tmp0 = MULTIPLY(d7, FIX_0_298631336);
423 8303 tmp2 = MULTIPLY(d3, FIX_3_072711026);
424 8303 tmp3 = MULTIPLY(d1, FIX_1_501321110);
425 8303 z1 = MULTIPLY(-z1, FIX_0_899976223);
426 8303 z2 = MULTIPLY(-d3, FIX_2_562915447);
427 8303 z3 = MULTIPLY(-z3, FIX_1_961570560);
428 8303 z4 = MULTIPLY(-d1, FIX_0_390180644);
429
430 8303 z3 += z5;
431 8303 z4 += z5;
432
433 8303 tmp0 += z1 + z3;
434 8303 tmp1 = z2 + z4;
435 8303 tmp2 += z2 + z3;
436 8303 tmp3 += z1 + z4;
437 } else {
438 /* d1 == 0, d3 != 0, d5 == 0, d7 != 0 */
439 7156 z3 = d7 + d3;
440
441 7156 tmp0 = MULTIPLY(-d7, FIX_0_601344887);
442 7156 z1 = MULTIPLY(-d7, FIX_0_899976223);
443 7156 tmp2 = MULTIPLY(d3, FIX_0_509795579);
444 7156 z2 = MULTIPLY(-d3, FIX_2_562915447);
445 7156 z5 = MULTIPLY(z3, FIX_1_175875602);
446 7156 z3 = MULTIPLY(-z3, FIX_0_785694958);
447
448 7156 tmp0 += z3;
449 7156 tmp1 = z2 + z5;
450 7156 tmp2 += z3;
451 7156 tmp3 = z1 + z5;
452 }
453 } else {
454
2/2
✓ Branch 0 taken 9598 times.
✓ Branch 1 taken 197208 times.
206806 if (d1) {
455 /* d1 != 0, d3 == 0, d5 == 0, d7 != 0 */
456 9598 z1 = d7 + d1;
457 9598 z5 = MULTIPLY(z1, FIX_1_175875602);
458
459 9598 z1 = MULTIPLY(z1, FIX_0_275899380);
460 9598 z3 = MULTIPLY(-d7, FIX_1_961570560);
461 9598 tmp0 = MULTIPLY(-d7, FIX_1_662939225);
462 9598 z4 = MULTIPLY(-d1, FIX_0_390180644);
463 9598 tmp3 = MULTIPLY(d1, FIX_1_111140466);
464
465 9598 tmp0 += z1;
466 9598 tmp1 = z4 + z5;
467 9598 tmp2 = z3 + z5;
468 9598 tmp3 += z1;
469 } else {
470 /* d1 == 0, d3 == 0, d5 == 0, d7 != 0 */
471 197208 tmp0 = MULTIPLY(-d7, FIX_1_387039845);
472 197208 tmp1 = MULTIPLY(d7, FIX_1_175875602);
473 197208 tmp2 = MULTIPLY(-d7, FIX_0_785694958);
474 197208 tmp3 = MULTIPLY(d7, FIX_0_275899380);
475 }
476 }
477 }
478 } else {
479
2/2
✓ Branch 0 taken 79486 times.
✓ Branch 1 taken 397501 times.
476987 if (d5) {
480
2/2
✓ Branch 0 taken 28539 times.
✓ Branch 1 taken 50947 times.
79486 if (d3) {
481
2/2
✓ Branch 0 taken 17324 times.
✓ Branch 1 taken 11215 times.
28539 if (d1) {
482 /* d1 != 0, d3 != 0, d5 != 0, d7 == 0 */
483 17324 z2 = d5 + d3;
484 17324 z4 = d5 + d1;
485 17324 z5 = MULTIPLY(d3 + z4, FIX_1_175875602);
486
487 17324 tmp1 = MULTIPLY(d5, FIX_2_053119869);
488 17324 tmp2 = MULTIPLY(d3, FIX_3_072711026);
489 17324 tmp3 = MULTIPLY(d1, FIX_1_501321110);
490 17324 z1 = MULTIPLY(-d1, FIX_0_899976223);
491 17324 z2 = MULTIPLY(-z2, FIX_2_562915447);
492 17324 z3 = MULTIPLY(-d3, FIX_1_961570560);
493 17324 z4 = MULTIPLY(-z4, FIX_0_390180644);
494
495 17324 z3 += z5;
496 17324 z4 += z5;
497
498 17324 tmp0 = z1 + z3;
499 17324 tmp1 += z2 + z4;
500 17324 tmp2 += z2 + z3;
501 17324 tmp3 += z1 + z4;
502 } else {
503 /* d1 == 0, d3 != 0, d5 != 0, d7 == 0 */
504 11215 z2 = d5 + d3;
505
506 11215 z5 = MULTIPLY(z2, FIX_1_175875602);
507 11215 tmp1 = MULTIPLY(d5, FIX_1_662939225);
508 11215 z4 = MULTIPLY(-d5, FIX_0_390180644);
509 11215 z2 = MULTIPLY(-z2, FIX_1_387039845);
510 11215 tmp2 = MULTIPLY(d3, FIX_1_111140466);
511 11215 z3 = MULTIPLY(-d3, FIX_1_961570560);
512
513 11215 tmp0 = z3 + z5;
514 11215 tmp1 += z2;
515 11215 tmp2 += z2;
516 11215 tmp3 = z4 + z5;
517 }
518 } else {
519
2/2
✓ Branch 0 taken 11946 times.
✓ Branch 1 taken 39001 times.
50947 if (d1) {
520 /* d1 != 0, d3 == 0, d5 != 0, d7 == 0 */
521 11946 z4 = d5 + d1;
522
523 11946 z5 = MULTIPLY(z4, FIX_1_175875602);
524 11946 z1 = MULTIPLY(-d1, FIX_0_899976223);
525 11946 tmp3 = MULTIPLY(d1, FIX_0_601344887);
526 11946 tmp1 = MULTIPLY(-d5, FIX_0_509795579);
527 11946 z2 = MULTIPLY(-d5, FIX_2_562915447);
528 11946 z4 = MULTIPLY(z4, FIX_0_785694958);
529
530 11946 tmp0 = z1 + z5;
531 11946 tmp1 += z4;
532 11946 tmp2 = z2 + z5;
533 11946 tmp3 += z4;
534 } else {
535 /* d1 == 0, d3 == 0, d5 != 0, d7 == 0 */
536 39001 tmp0 = MULTIPLY(d5, FIX_1_175875602);
537 39001 tmp1 = MULTIPLY(d5, FIX_0_275899380);
538 39001 tmp2 = MULTIPLY(-d5, FIX_1_387039845);
539 39001 tmp3 = MULTIPLY(d5, FIX_0_785694958);
540 }
541 }
542 } else {
543
2/2
✓ Branch 0 taken 123055 times.
✓ Branch 1 taken 274446 times.
397501 if (d3) {
544
2/2
✓ Branch 0 taken 56569 times.
✓ Branch 1 taken 66486 times.
123055 if (d1) {
545 /* d1 != 0, d3 != 0, d5 == 0, d7 == 0 */
546 56569 z5 = d1 + d3;
547 56569 tmp3 = MULTIPLY(d1, FIX_0_211164243);
548 56569 tmp2 = MULTIPLY(-d3, FIX_1_451774981);
549 56569 z1 = MULTIPLY(d1, FIX_1_061594337);
550 56569 z2 = MULTIPLY(-d3, FIX_2_172734803);
551 56569 z4 = MULTIPLY(z5, FIX_0_785694958);
552 56569 z5 = MULTIPLY(z5, FIX_1_175875602);
553
554 56569 tmp0 = z1 - z4;
555 56569 tmp1 = z2 + z4;
556 56569 tmp2 += z5;
557 56569 tmp3 += z5;
558 } else {
559 /* d1 == 0, d3 != 0, d5 == 0, d7 == 0 */
560 66486 tmp0 = MULTIPLY(-d3, FIX_0_785694958);
561 66486 tmp1 = MULTIPLY(-d3, FIX_1_387039845);
562 66486 tmp2 = MULTIPLY(-d3, FIX_0_275899380);
563 66486 tmp3 = MULTIPLY(d3, FIX_1_175875602);
564 }
565 } else {
566
2/2
✓ Branch 0 taken 160122 times.
✓ Branch 1 taken 114324 times.
274446 if (d1) {
567 /* d1 != 0, d3 == 0, d5 == 0, d7 == 0 */
568 160122 tmp0 = MULTIPLY(d1, FIX_0_275899380);
569 160122 tmp1 = MULTIPLY(d1, FIX_0_785694958);
570 160122 tmp2 = MULTIPLY(d1, FIX_1_175875602);
571 160122 tmp3 = MULTIPLY(d1, FIX_1_387039845);
572 } else {
573 /* d1 == 0, d3 == 0, d5 == 0, d7 == 0 */
574 114324 tmp0 = tmp1 = tmp2 = tmp3 = 0;
575 }
576 }
577 }
578 }
579 }
580 /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
581
582 894737 dataptr[0] = (int16_t) DESCALE(tmp10 + tmp3, CONST_BITS-PASS1_BITS);
583 894737 dataptr[7] = (int16_t) DESCALE(tmp10 - tmp3, CONST_BITS-PASS1_BITS);
584 894737 dataptr[1] = (int16_t) DESCALE(tmp11 + tmp2, CONST_BITS-PASS1_BITS);
585 894737 dataptr[6] = (int16_t) DESCALE(tmp11 - tmp2, CONST_BITS-PASS1_BITS);
586 894737 dataptr[2] = (int16_t) DESCALE(tmp12 + tmp1, CONST_BITS-PASS1_BITS);
587 894737 dataptr[5] = (int16_t) DESCALE(tmp12 - tmp1, CONST_BITS-PASS1_BITS);
588 894737 dataptr[3] = (int16_t) DESCALE(tmp13 + tmp0, CONST_BITS-PASS1_BITS);
589 894737 dataptr[4] = (int16_t) DESCALE(tmp13 - tmp0, CONST_BITS-PASS1_BITS);
590
591 894737 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 259299 dataptr = data;
599
2/2
✓ Branch 0 taken 2074392 times.
✓ Branch 1 taken 259299 times.
2333691 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 2074392 d0 = dataptr[DCTSIZE*0];
609 2074392 d1 = dataptr[DCTSIZE*1];
610 2074392 d2 = dataptr[DCTSIZE*2];
611 2074392 d3 = dataptr[DCTSIZE*3];
612 2074392 d4 = dataptr[DCTSIZE*4];
613 2074392 d5 = dataptr[DCTSIZE*5];
614 2074392 d6 = dataptr[DCTSIZE*6];
615 2074392 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 591122 times.
✓ Branch 1 taken 1483270 times.
2074392 if (d6) {
620
2/2
✓ Branch 0 taken 476085 times.
✓ Branch 1 taken 115037 times.
591122 if (d2) {
621 /* d0 != 0, d2 != 0, d4 != 0, d6 != 0 */
622 476085 z1 = MULTIPLY(d2 + d6, FIX_0_541196100);
623 476085 tmp2 = z1 + MULTIPLY(-d6, FIX_1_847759065);
624 476085 tmp3 = z1 + MULTIPLY(d2, FIX_0_765366865);
625
626 476085 tmp0 = (d0 + d4) * CONST_SCALE;
627 476085 tmp1 = (d0 - d4) * CONST_SCALE;
628
629 476085 tmp10 = tmp0 + tmp3;
630 476085 tmp13 = tmp0 - tmp3;
631 476085 tmp11 = tmp1 + tmp2;
632 476085 tmp12 = tmp1 - tmp2;
633 } else {
634 /* d0 != 0, d2 == 0, d4 != 0, d6 != 0 */
635 115037 tmp2 = MULTIPLY(-d6, FIX_1_306562965);
636 115037 tmp3 = MULTIPLY(d6, FIX_0_541196100);
637
638 115037 tmp0 = (d0 + d4) * CONST_SCALE;
639 115037 tmp1 = (d0 - d4) * CONST_SCALE;
640
641 115037 tmp10 = tmp0 + tmp3;
642 115037 tmp13 = tmp0 - tmp3;
643 115037 tmp11 = tmp1 + tmp2;
644 115037 tmp12 = tmp1 - tmp2;
645 }
646 } else {
647
2/2
✓ Branch 0 taken 530858 times.
✓ Branch 1 taken 952412 times.
1483270 if (d2) {
648 /* d0 != 0, d2 != 0, d4 != 0, d6 == 0 */
649 530858 tmp2 = MULTIPLY(d2, FIX_0_541196100);
650 530858 tmp3 = MULTIPLY(d2, FIX_1_306562965);
651
652 530858 tmp0 = (d0 + d4) * CONST_SCALE;
653 530858 tmp1 = (d0 - d4) * CONST_SCALE;
654
655 530858 tmp10 = tmp0 + tmp3;
656 530858 tmp13 = tmp0 - tmp3;
657 530858 tmp11 = tmp1 + tmp2;
658 530858 tmp12 = tmp1 - tmp2;
659 } else {
660 /* d0 != 0, d2 == 0, d4 != 0, d6 == 0 */
661 952412 tmp10 = tmp13 = (d0 + d4) * CONST_SCALE;
662 952412 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 1789641 times.
✓ Branch 1 taken 284751 times.
2074392 if (d7) {
670
2/2
✓ Branch 0 taken 621628 times.
✓ Branch 1 taken 1168013 times.
1789641 if (d5) {
671
2/2
✓ Branch 0 taken 510118 times.
✓ Branch 1 taken 111510 times.
621628 if (d3) {
672
2/2
✓ Branch 0 taken 447800 times.
✓ Branch 1 taken 62318 times.
510118 if (d1) {
673 /* d1 != 0, d3 != 0, d5 != 0, d7 != 0 */
674 447800 z1 = d7 + d1;
675 447800 z2 = d5 + d3;
676 447800 z3 = d7 + d3;
677 447800 z4 = d5 + d1;
678 447800 z5 = MULTIPLY(z3 + z4, FIX_1_175875602);
679
680 447800 tmp0 = MULTIPLY(d7, FIX_0_298631336);
681 447800 tmp1 = MULTIPLY(d5, FIX_2_053119869);
682 447800 tmp2 = MULTIPLY(d3, FIX_3_072711026);
683 447800 tmp3 = MULTIPLY(d1, FIX_1_501321110);
684 447800 z1 = MULTIPLY(-z1, FIX_0_899976223);
685 447800 z2 = MULTIPLY(-z2, FIX_2_562915447);
686 447800 z3 = MULTIPLY(-z3, FIX_1_961570560);
687 447800 z4 = MULTIPLY(-z4, FIX_0_390180644);
688
689 447800 z3 += z5;
690 447800 z4 += z5;
691
692 447800 tmp0 += z1 + z3;
693 447800 tmp1 += z2 + z4;
694 447800 tmp2 += z2 + z3;
695 447800 tmp3 += z1 + z4;
696 } else {
697 /* d1 == 0, d3 != 0, d5 != 0, d7 != 0 */
698 62318 z2 = d5 + d3;
699 62318 z3 = d7 + d3;
700 62318 z5 = MULTIPLY(z3 + d5, FIX_1_175875602);
701
702 62318 tmp0 = MULTIPLY(d7, FIX_0_298631336);
703 62318 tmp1 = MULTIPLY(d5, FIX_2_053119869);
704 62318 tmp2 = MULTIPLY(d3, FIX_3_072711026);
705 62318 z1 = MULTIPLY(-d7, FIX_0_899976223);
706 62318 z2 = MULTIPLY(-z2, FIX_2_562915447);
707 62318 z3 = MULTIPLY(-z3, FIX_1_961570560);
708 62318 z4 = MULTIPLY(-d5, FIX_0_390180644);
709
710 62318 z3 += z5;
711 62318 z4 += z5;
712
713 62318 tmp0 += z1 + z3;
714 62318 tmp1 += z2 + z4;
715 62318 tmp2 += z2 + z3;
716 62318 tmp3 = z1 + z4;
717 }
718 } else {
719
2/2
✓ Branch 0 taken 47537 times.
✓ Branch 1 taken 63973 times.
111510 if (d1) {
720 /* d1 != 0, d3 == 0, d5 != 0, d7 != 0 */
721 47537 z1 = d7 + d1;
722 47537 z3 = d7;
723 47537 z4 = d5 + d1;
724 47537 z5 = MULTIPLY(z3 + z4, FIX_1_175875602);
725
726 47537 tmp0 = MULTIPLY(d7, FIX_0_298631336);
727 47537 tmp1 = MULTIPLY(d5, FIX_2_053119869);
728 47537 tmp3 = MULTIPLY(d1, FIX_1_501321110);
729 47537 z1 = MULTIPLY(-z1, FIX_0_899976223);
730 47537 z2 = MULTIPLY(-d5, FIX_2_562915447);
731 47537 z3 = MULTIPLY(-d7, FIX_1_961570560);
732 47537 z4 = MULTIPLY(-z4, FIX_0_390180644);
733
734 47537 z3 += z5;
735 47537 z4 += z5;
736
737 47537 tmp0 += z1 + z3;
738 47537 tmp1 += z2 + z4;
739 47537 tmp2 = z2 + z3;
740 47537 tmp3 += z1 + z4;
741 } else {
742 /* d1 == 0, d3 == 0, d5 != 0, d7 != 0 */
743 63973 tmp0 = MULTIPLY(-d7, FIX_0_601344887);
744 63973 z1 = MULTIPLY(-d7, FIX_0_899976223);
745 63973 z3 = MULTIPLY(-d7, FIX_1_961570560);
746 63973 tmp1 = MULTIPLY(-d5, FIX_0_509795579);
747 63973 z2 = MULTIPLY(-d5, FIX_2_562915447);
748 63973 z4 = MULTIPLY(-d5, FIX_0_390180644);
749 63973 z5 = MULTIPLY(d5 + d7, FIX_1_175875602);
750
751 63973 z3 += z5;
752 63973 z4 += z5;
753
754 63973 tmp0 += z3;
755 63973 tmp1 += z4;
756 63973 tmp2 = z2 + z3;
757 63973 tmp3 = z1 + z4;
758 }
759 }
760 } else {
761
2/2
✓ Branch 0 taken 295008 times.
✓ Branch 1 taken 873005 times.
1168013 if (d3) {
762
2/2
✓ Branch 0 taken 183645 times.
✓ Branch 1 taken 111363 times.
295008 if (d1) {
763 /* d1 != 0, d3 != 0, d5 == 0, d7 != 0 */
764 183645 z1 = d7 + d1;
765 183645 z3 = d7 + d3;
766 183645 z5 = MULTIPLY(z3 + d1, FIX_1_175875602);
767
768 183645 tmp0 = MULTIPLY(d7, FIX_0_298631336);
769 183645 tmp2 = MULTIPLY(d3, FIX_3_072711026);
770 183645 tmp3 = MULTIPLY(d1, FIX_1_501321110);
771 183645 z1 = MULTIPLY(-z1, FIX_0_899976223);
772 183645 z2 = MULTIPLY(-d3, FIX_2_562915447);
773 183645 z3 = MULTIPLY(-z3, FIX_1_961570560);
774 183645 z4 = MULTIPLY(-d1, FIX_0_390180644);
775
776 183645 z3 += z5;
777 183645 z4 += z5;
778
779 183645 tmp0 += z1 + z3;
780 183645 tmp1 = z2 + z4;
781 183645 tmp2 += z2 + z3;
782 183645 tmp3 += z1 + z4;
783 } else {
784 /* d1 == 0, d3 != 0, d5 == 0, d7 != 0 */
785 111363 z3 = d7 + d3;
786
787 111363 tmp0 = MULTIPLY(-d7, FIX_0_601344887);
788 111363 z1 = MULTIPLY(-d7, FIX_0_899976223);
789 111363 tmp2 = MULTIPLY(d3, FIX_0_509795579);
790 111363 z2 = MULTIPLY(-d3, FIX_2_562915447);
791 111363 z5 = MULTIPLY(z3, FIX_1_175875602);
792 111363 z3 = MULTIPLY(-z3, FIX_0_785694958);
793
794 111363 tmp0 += z3;
795 111363 tmp1 = z2 + z5;
796 111363 tmp2 += z3;
797 111363 tmp3 = z1 + z5;
798 }
799 } else {
800
2/2
✓ Branch 0 taken 319056 times.
✓ Branch 1 taken 553949 times.
873005 if (d1) {
801 /* d1 != 0, d3 == 0, d5 == 0, d7 != 0 */
802 319056 z1 = d7 + d1;
803 319056 z5 = MULTIPLY(z1, FIX_1_175875602);
804
805 319056 z1 = MULTIPLY(z1, FIX_0_275899380);
806 319056 z3 = MULTIPLY(-d7, FIX_1_961570560);
807 319056 tmp0 = MULTIPLY(-d7, FIX_1_662939225);
808 319056 z4 = MULTIPLY(-d1, FIX_0_390180644);
809 319056 tmp3 = MULTIPLY(d1, FIX_1_111140466);
810
811 319056 tmp0 += z1;
812 319056 tmp1 = z4 + z5;
813 319056 tmp2 = z3 + z5;
814 319056 tmp3 += z1;
815 } else {
816 /* d1 == 0, d3 == 0, d5 == 0, d7 != 0 */
817 553949 tmp0 = MULTIPLY(-d7, FIX_1_387039845);
818 553949 tmp1 = MULTIPLY(d7, FIX_1_175875602);
819 553949 tmp2 = MULTIPLY(-d7, FIX_0_785694958);
820 553949 tmp3 = MULTIPLY(d7, FIX_0_275899380);
821 }
822 }
823 }
824 } else {
825
2/2
✓ Branch 0 taken 60205 times.
✓ Branch 1 taken 224546 times.
284751 if (d5) {
826
2/2
✓ Branch 0 taken 38457 times.
✓ Branch 1 taken 21748 times.
60205 if (d3) {
827
2/2
✓ Branch 0 taken 29398 times.
✓ Branch 1 taken 9059 times.
38457 if (d1) {
828 /* d1 != 0, d3 != 0, d5 != 0, d7 == 0 */
829 29398 z2 = d5 + d3;
830 29398 z4 = d5 + d1;
831 29398 z5 = MULTIPLY(d3 + z4, FIX_1_175875602);
832
833 29398 tmp1 = MULTIPLY(d5, FIX_2_053119869);
834 29398 tmp2 = MULTIPLY(d3, FIX_3_072711026);
835 29398 tmp3 = MULTIPLY(d1, FIX_1_501321110);
836 29398 z1 = MULTIPLY(-d1, FIX_0_899976223);
837 29398 z2 = MULTIPLY(-z2, FIX_2_562915447);
838 29398 z3 = MULTIPLY(-d3, FIX_1_961570560);
839 29398 z4 = MULTIPLY(-z4, FIX_0_390180644);
840
841 29398 z3 += z5;
842 29398 z4 += z5;
843
844 29398 tmp0 = z1 + z3;
845 29398 tmp1 += z2 + z4;
846 29398 tmp2 += z2 + z3;
847 29398 tmp3 += z1 + z4;
848 } else {
849 /* d1 == 0, d3 != 0, d5 != 0, d7 == 0 */
850 9059 z2 = d5 + d3;
851
852 9059 z5 = MULTIPLY(z2, FIX_1_175875602);
853 9059 tmp1 = MULTIPLY(d5, FIX_1_662939225);
854 9059 z4 = MULTIPLY(-d5, FIX_0_390180644);
855 9059 z2 = MULTIPLY(-z2, FIX_1_387039845);
856 9059 tmp2 = MULTIPLY(d3, FIX_1_111140466);
857 9059 z3 = MULTIPLY(-d3, FIX_1_961570560);
858
859 9059 tmp0 = z3 + z5;
860 9059 tmp1 += z2;
861 9059 tmp2 += z2;
862 9059 tmp3 = z4 + z5;
863 }
864 } else {
865
2/2
✓ Branch 0 taken 10015 times.
✓ Branch 1 taken 11733 times.
21748 if (d1) {
866 /* d1 != 0, d3 == 0, d5 != 0, d7 == 0 */
867 10015 z4 = d5 + d1;
868
869 10015 z5 = MULTIPLY(z4, FIX_1_175875602);
870 10015 z1 = MULTIPLY(-d1, FIX_0_899976223);
871 10015 tmp3 = MULTIPLY(d1, FIX_0_601344887);
872 10015 tmp1 = MULTIPLY(-d5, FIX_0_509795579);
873 10015 z2 = MULTIPLY(-d5, FIX_2_562915447);
874 10015 z4 = MULTIPLY(z4, FIX_0_785694958);
875
876 10015 tmp0 = z1 + z5;
877 10015 tmp1 += z4;
878 10015 tmp2 = z2 + z5;
879 10015 tmp3 += z4;
880 } else {
881 /* d1 == 0, d3 == 0, d5 != 0, d7 == 0 */
882 11733 tmp0 = MULTIPLY(d5, FIX_1_175875602);
883 11733 tmp1 = MULTIPLY(d5, FIX_0_275899380);
884 11733 tmp2 = MULTIPLY(-d5, FIX_1_387039845);
885 11733 tmp3 = MULTIPLY(d5, FIX_0_785694958);
886 }
887 }
888 } else {
889
2/2
✓ Branch 0 taken 62580 times.
✓ Branch 1 taken 161966 times.
224546 if (d3) {
890
2/2
✓ Branch 0 taken 49476 times.
✓ Branch 1 taken 13104 times.
62580 if (d1) {
891 /* d1 != 0, d3 != 0, d5 == 0, d7 == 0 */
892 49476 z5 = d1 + d3;
893 49476 tmp3 = MULTIPLY(d1, FIX_0_211164243);
894 49476 tmp2 = MULTIPLY(-d3, FIX_1_451774981);
895 49476 z1 = MULTIPLY(d1, FIX_1_061594337);
896 49476 z2 = MULTIPLY(-d3, FIX_2_172734803);
897 49476 z4 = MULTIPLY(z5, FIX_0_785694958);
898 49476 z5 = MULTIPLY(z5, FIX_1_175875602);
899
900 49476 tmp0 = z1 - z4;
901 49476 tmp1 = z2 + z4;
902 49476 tmp2 += z5;
903 49476 tmp3 += z5;
904 } else {
905 /* d1 == 0, d3 != 0, d5 == 0, d7 == 0 */
906 13104 tmp0 = MULTIPLY(-d3, FIX_0_785694958);
907 13104 tmp1 = MULTIPLY(-d3, FIX_1_387039845);
908 13104 tmp2 = MULTIPLY(-d3, FIX_0_275899380);
909 13104 tmp3 = MULTIPLY(d3, FIX_1_175875602);
910 }
911 } else {
912
2/2
✓ Branch 0 taken 53575 times.
✓ Branch 1 taken 108391 times.
161966 if (d1) {
913 /* d1 != 0, d3 == 0, d5 == 0, d7 == 0 */
914 53575 tmp0 = MULTIPLY(d1, FIX_0_275899380);
915 53575 tmp1 = MULTIPLY(d1, FIX_0_785694958);
916 53575 tmp2 = MULTIPLY(d1, FIX_1_175875602);
917 53575 tmp3 = MULTIPLY(d1, FIX_1_387039845);
918 } else {
919 /* d1 == 0, d3 == 0, d5 == 0, d7 == 0 */
920 108391 tmp0 = tmp1 = tmp2 = tmp3 = 0;
921 }
922 }
923 }
924 }
925
926 /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
927
928 2074392 dataptr[DCTSIZE*0] = (int16_t) DESCALE(tmp10 + tmp3,
929 CONST_BITS+PASS1_BITS+3);
930 2074392 dataptr[DCTSIZE*7] = (int16_t) DESCALE(tmp10 - tmp3,
931 CONST_BITS+PASS1_BITS+3);
932 2074392 dataptr[DCTSIZE*1] = (int16_t) DESCALE(tmp11 + tmp2,
933 CONST_BITS+PASS1_BITS+3);
934 2074392 dataptr[DCTSIZE*6] = (int16_t) DESCALE(tmp11 - tmp2,
935 CONST_BITS+PASS1_BITS+3);
936 2074392 dataptr[DCTSIZE*2] = (int16_t) DESCALE(tmp12 + tmp1,
937 CONST_BITS+PASS1_BITS+3);
938 2074392 dataptr[DCTSIZE*5] = (int16_t) DESCALE(tmp12 - tmp1,
939 CONST_BITS+PASS1_BITS+3);
940 2074392 dataptr[DCTSIZE*3] = (int16_t) DESCALE(tmp13 + tmp0,
941 CONST_BITS+PASS1_BITS+3);
942 2074392 dataptr[DCTSIZE*4] = (int16_t) DESCALE(tmp13 - tmp0,
943 CONST_BITS+PASS1_BITS+3);
944
945 2074392 dataptr++; /* advance pointer to next column */
946 }
947 259299 }
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 49866 void ff_jref_idct_put(uint8_t *dest, ptrdiff_t line_size, int16_t block[64])
1163 {
1164 49866 ff_j_rev_dct(block);
1165 49866 ff_put_pixels_clamped_c(block, dest, line_size);
1166 49866 }
1167
1168 149433 void ff_jref_idct_add(uint8_t *dest, ptrdiff_t line_size, int16_t block[64])
1169 {
1170 149433 ff_j_rev_dct(block);
1171 149433 ff_add_pixels_clamped_c(block, dest, line_size);
1172 149433 }
1173