FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/simple_idct.c
Date: 2024-11-20 23:03:26
Exec Total Coverage
Lines: 96 102 94.1%
Functions: 8 9 88.9%
Branches: 26 30 86.7%

Line Branch Exec Source
1 /*
2 * Simple IDCT
3 *
4 * Copyright (c) 2001 Michael Niedermayer <michaelni@gmx.at>
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 /**
24 * @file
25 * simpleidct in C.
26 */
27
28 #include "libavutil/intreadwrite.h"
29 #include "mathops.h"
30 #include "simple_idct.h"
31
32 #define IN_IDCT_DEPTH 16
33
34 #define BIT_DEPTH 8
35 #include "simple_idct_template.c"
36 #undef BIT_DEPTH
37
38 #define BIT_DEPTH 10
39 #include "simple_idct_template.c"
40
41 #define EXTRA_SHIFT 2
42 #include "simple_idct_template.c"
43
44 #undef EXTRA_SHIFT
45 #undef BIT_DEPTH
46
47 #define BIT_DEPTH 12
48 #include "simple_idct_template.c"
49 #undef BIT_DEPTH
50 #undef IN_IDCT_DEPTH
51
52 #define IN_IDCT_DEPTH 32
53 #define BIT_DEPTH 10
54 #include "simple_idct_template.c"
55 #undef BIT_DEPTH
56 #undef IN_IDCT_DEPTH
57
58 /* 2x4x8 idct */
59
60 #define CN_SHIFT 12
61 #define C_FIX(x) ((int)((x) * (1 << CN_SHIFT) + 0.5))
62 #define C1 C_FIX(0.6532814824)
63 #define C2 C_FIX(0.2705980501)
64
65 /* row idct is multiple by 16 * sqrt(2.0), col idct4 is normalized,
66 and the butterfly must be multiplied by 0.5 * sqrt(2.0) */
67 #define C_SHIFT (4+1+12)
68
69 441216 static inline void idct4col_put(uint8_t *dest, ptrdiff_t line_size, const int16_t *col)
70 {
71 int c0, c1, c2, c3, a0, a1, a2, a3;
72
73 441216 a0 = col[8*0];
74 441216 a1 = col[8*2];
75 441216 a2 = col[8*4];
76 441216 a3 = col[8*6];
77 441216 c0 = ((a0 + a2) * (1 << CN_SHIFT - 1)) + (1 << (C_SHIFT - 1));
78 441216 c2 = ((a0 - a2) * (1 << CN_SHIFT - 1)) + (1 << (C_SHIFT - 1));
79 441216 c1 = a1 * C1 + a3 * C2;
80 441216 c3 = a1 * C2 - a3 * C1;
81 441216 dest[0] = av_clip_uint8((c0 + c1) >> C_SHIFT);
82 441216 dest += line_size;
83 441216 dest[0] = av_clip_uint8((c2 + c3) >> C_SHIFT);
84 441216 dest += line_size;
85 441216 dest[0] = av_clip_uint8((c2 - c3) >> C_SHIFT);
86 441216 dest += line_size;
87 441216 dest[0] = av_clip_uint8((c0 - c1) >> C_SHIFT);
88 441216 }
89
90 #define BF(k) \
91 {\
92 int a0, a1;\
93 a0 = ptr[k];\
94 a1 = ptr[8 + k];\
95 ptr[k] = a0 + a1;\
96 ptr[8 + k] = a0 - a1;\
97 }
98
99 /* only used by DV codec. The input must be interlaced. 128 is added
100 to the pixels before clamping to avoid systematic error
101 (1024*sqrt(2)) offset would be needed otherwise. */
102 /* XXX: I think a 1.0/sqrt(2) normalization should be needed to
103 compensate the extra butterfly stage - I don't have the full DV
104 specification */
105 27576 void ff_simple_idct248_put(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
106 {
107 int i;
108 int16_t *ptr;
109
110 /* butterfly */
111 27576 ptr = block;
112
2/2
✓ Branch 0 taken 110304 times.
✓ Branch 1 taken 27576 times.
137880 for(i=0;i<4;i++) {
113 110304 BF(0);
114 110304 BF(1);
115 110304 BF(2);
116 110304 BF(3);
117 110304 BF(4);
118 110304 BF(5);
119 110304 BF(6);
120 110304 BF(7);
121 110304 ptr += 2 * 8;
122 }
123
124 /* IDCT8 on each line */
125
2/2
✓ Branch 0 taken 220608 times.
✓ Branch 1 taken 27576 times.
248184 for(i=0; i<8; i++) {
126 220608 idctRowCondDC_int16_8bit(block + i*8, 0);
127 }
128
129 /* IDCT4 and store */
130
2/2
✓ Branch 0 taken 220608 times.
✓ Branch 1 taken 27576 times.
248184 for(i=0;i<8;i++) {
131 220608 idct4col_put(dest + i, 2 * line_size, block + i);
132 220608 idct4col_put(dest + line_size + i, 2 * line_size, block + 8 + i);
133 }
134 27576 }
135
136 /* 8x4 & 4x8 WMV2 IDCT */
137 #undef CN_SHIFT
138 #undef C_SHIFT
139 #undef C_FIX
140 #undef C1
141 #undef C2
142 #define CN_SHIFT 12
143 #define C_FIX(x) ((int)((x) * M_SQRT2 * (1 << CN_SHIFT) + 0.5))
144 #define C1 C_FIX(0.6532814824)
145 #define C2 C_FIX(0.2705980501)
146 #define C3 C_FIX(0.5)
147 #define C_SHIFT (4+1+12)
148 263504 static inline void idct4col_add(uint8_t *dest, ptrdiff_t line_size, const int16_t *col)
149 {
150 int c0, c1, c2, c3, a0, a1, a2, a3;
151
152 263504 a0 = col[8*0];
153 263504 a1 = col[8*1];
154 263504 a2 = col[8*2];
155 263504 a3 = col[8*3];
156 263504 c0 = (a0 + a2)*C3 + (1 << (C_SHIFT - 1));
157 263504 c2 = (a0 - a2)*C3 + (1 << (C_SHIFT - 1));
158 263504 c1 = a1 * C1 + a3 * C2;
159 263504 c3 = a1 * C2 - a3 * C1;
160 263504 dest[0] = av_clip_uint8(dest[0] + ((c0 + c1) >> C_SHIFT));
161 263504 dest += line_size;
162 263504 dest[0] = av_clip_uint8(dest[0] + ((c2 + c3) >> C_SHIFT));
163 263504 dest += line_size;
164 263504 dest[0] = av_clip_uint8(dest[0] + ((c2 - c3) >> C_SHIFT));
165 263504 dest += line_size;
166 263504 dest[0] = av_clip_uint8(dest[0] + ((c0 - c1) >> C_SHIFT));
167 263504 }
168
169 #define RN_SHIFT 15
170 #define R_FIX(x) ((int)((x) * M_SQRT2 * (1 << RN_SHIFT) + 0.5))
171 #define R1 R_FIX(0.6532814824)
172 #define R2 R_FIX(0.2705980501)
173 #define R3 R_FIX(0.5)
174 #define R_SHIFT 11
175 239648 static inline void idct4row(int16_t *row)
176 {
177 unsigned c0, c1, c2, c3;
178 int a0, a1, a2, a3;
179
180 239648 a0 = row[0];
181 239648 a1 = row[1];
182 239648 a2 = row[2];
183 239648 a3 = row[3];
184 239648 c0 = (a0 + a2)*R3 + (1 << (R_SHIFT - 1));
185 239648 c2 = (a0 - a2)*R3 + (1 << (R_SHIFT - 1));
186 239648 c1 = a1 * R1 + a3 * R2;
187 239648 c3 = a1 * R2 - a3 * R1;
188 239648 row[0]= (c0 + c1) >> R_SHIFT;
189 239648 row[1]= (c2 + c3) >> R_SHIFT;
190 239648 row[2]= (c2 - c3) >> R_SHIFT;
191 239648 row[3]= (c0 - c1) >> R_SHIFT;
192 239648 }
193
194 32938 void ff_simple_idct84_add(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
195 {
196 int i;
197
198 /* IDCT8 on each line */
199
2/2
✓ Branch 0 taken 131752 times.
✓ Branch 1 taken 32938 times.
164690 for(i=0; i<4; i++) {
200 131752 idctRowCondDC_int16_8bit(block + i*8, 0);
201 }
202
203 /* IDCT4 and store */
204
2/2
✓ Branch 0 taken 263504 times.
✓ Branch 1 taken 32938 times.
296442 for(i=0;i<8;i++) {
205 263504 idct4col_add(dest + i, line_size, block + i);
206 }
207 32938 }
208
209 29956 void ff_simple_idct48_add(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
210 {
211 int i;
212
213 /* IDCT4 on each line */
214
2/2
✓ Branch 0 taken 239648 times.
✓ Branch 1 taken 29956 times.
269604 for(i=0; i<8; i++) {
215 239648 idct4row(block + i*8);
216 }
217
218 /* IDCT8 and store */
219
2/2
✓ Branch 0 taken 119824 times.
✓ Branch 1 taken 29956 times.
149780 for(i=0; i<4; i++){
220 119824 idctSparseColAdd_int16_8bit(dest + i, line_size, block + i);
221 }
222 29956 }
223
224 void ff_simple_idct44_add(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
225 {
226 int i;
227
228 /* IDCT4 on each line */
229 for(i=0; i<4; i++) {
230 idct4row(block + i*8);
231 }
232
233 /* IDCT4 and store */
234 for(i=0; i<4; i++){
235 idct4col_add(dest + i, line_size, block + i);
236 }
237 }
238
239 2740512 void ff_prores_idct_10(int16_t *block, const int16_t *qmat)
240 {
241 int i;
242
243
2/2
✓ Branch 0 taken 175392768 times.
✓ Branch 1 taken 2740512 times.
178133280 for (i = 0; i < 64; i++)
244 175392768 block[i] *= qmat[i];
245
246
2/2
✓ Branch 0 taken 21924096 times.
✓ Branch 1 taken 2740512 times.
24664608 for (i = 0; i < 8; i++)
247 21924096 idctRowCondDC_extrashift_10(block + i*8, 2);
248
249
2/2
✓ Branch 0 taken 21924096 times.
✓ Branch 1 taken 2740512 times.
24664608 for (i = 0; i < 8; i++) {
250 21924096 block[i] += 8192;
251 21924096 idctSparseCol_extrashift_10(block + i);
252 }
253 2740512 }
254
255 2446164 void ff_prores_idct_12(int16_t *block, const int16_t *qmat)
256 {
257 int i;
258
259
2/2
✓ Branch 0 taken 156554496 times.
✓ Branch 1 taken 2446164 times.
159000660 for (i = 0; i < 64; i++)
260 156554496 block[i] *= qmat[i];
261
262
2/2
✓ Branch 0 taken 19569312 times.
✓ Branch 1 taken 2446164 times.
22015476 for (i = 0; i < 8; i++)
263 19569312 idctRowCondDC_int16_12bit(block + i*8, 0);
264
265
2/2
✓ Branch 0 taken 19569312 times.
✓ Branch 1 taken 2446164 times.
22015476 for (i = 0; i < 8; i++) {
266 19569312 block[i] += 8192;
267 19569312 idctSparseCol_int16_12bit(block + i);
268 }
269 2446164 }
270