FFmpeg coverage


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