FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/idctdsp.c
Date: 2022-07-04 00:18:54
Exec Total Coverage
Lines: 133 173 76.9%
Branches: 49 61 80.3%

Line Branch Exec Source
1 /*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include "config.h"
20 #include "config_components.h"
21 #include "libavutil/attributes.h"
22 #include "libavutil/common.h"
23 #include "avcodec.h"
24 #include "dct.h"
25 #include "faanidct.h"
26 #include "idctdsp.h"
27 #include "simple_idct.h"
28 #include "xvididct.h"
29
30 41068 av_cold void ff_init_scantable(const uint8_t *permutation, ScanTable *st,
31 const uint8_t *src_scantable)
32 {
33 int i, end;
34
35 41068 st->scantable = src_scantable;
36
37
2/2
✓ Branch 0 taken 2628352 times.
✓ Branch 1 taken 41068 times.
2669420 for (i = 0; i < 64; i++) {
38 2628352 int j = src_scantable[i];
39 2628352 st->permutated[i] = permutation[j];
40 }
41
42 41068 end = -1;
43
2/2
✓ Branch 0 taken 2628352 times.
✓ Branch 1 taken 41068 times.
2669420 for (i = 0; i < 64; i++) {
44 2628352 int j = st->permutated[i];
45
2/2
✓ Branch 0 taken 555305 times.
✓ Branch 1 taken 2073047 times.
2628352 if (j > end)
46 555305 end = j;
47 2628352 st->raster_end[i] = end;
48 }
49 41068 }
50
51 1890 av_cold void ff_init_scantable_permutation(uint8_t *idct_permutation,
52 enum idct_permutation_type perm_type)
53 {
54 int i;
55
56 #if ARCH_X86
57
2/2
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 1886 times.
1890 if (ff_init_scantable_permutation_x86(idct_permutation,
58 perm_type))
59 4 return;
60 #endif
61
62
3/5
✓ Branch 0 taken 1568 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 314 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1886 switch (perm_type) {
63 1568 case FF_IDCT_PERM_NONE:
64
2/2
✓ Branch 0 taken 100352 times.
✓ Branch 1 taken 1568 times.
101920 for (i = 0; i < 64; i++)
65 100352 idct_permutation[i] = i;
66 1568 break;
67 4 case FF_IDCT_PERM_LIBMPEG2:
68
2/2
✓ Branch 0 taken 256 times.
✓ Branch 1 taken 4 times.
260 for (i = 0; i < 64; i++)
69 256 idct_permutation[i] = (i & 0x38) | ((i & 6) >> 1) | ((i & 1) << 2);
70 4 break;
71 314 case FF_IDCT_PERM_TRANSPOSE:
72
2/2
✓ Branch 0 taken 20096 times.
✓ Branch 1 taken 314 times.
20410 for (i = 0; i < 64; i++)
73 20096 idct_permutation[i] = ((i & 7) << 3) | (i >> 3);
74 314 break;
75 case FF_IDCT_PERM_PARTTRANS:
76 for (i = 0; i < 64; i++)
77 idct_permutation[i] = (i & 0x24) | ((i & 3) << 3) | ((i >> 3) & 3);
78 break;
79 default:
80 av_log(NULL, AV_LOG_ERROR,
81 "Internal error, IDCT permutation not set\n");
82 }
83 }
84
85 141453 void ff_put_pixels_clamped_c(const int16_t *block, uint8_t *av_restrict pixels,
86 ptrdiff_t line_size)
87 {
88 int i;
89
90 /* read the pixels */
91
2/2
✓ Branch 0 taken 1131624 times.
✓ Branch 1 taken 141453 times.
1273077 for (i = 0; i < 8; i++) {
92 1131624 pixels[0] = av_clip_uint8(block[0]);
93 1131624 pixels[1] = av_clip_uint8(block[1]);
94 1131624 pixels[2] = av_clip_uint8(block[2]);
95 1131624 pixels[3] = av_clip_uint8(block[3]);
96 1131624 pixels[4] = av_clip_uint8(block[4]);
97 1131624 pixels[5] = av_clip_uint8(block[5]);
98 1131624 pixels[6] = av_clip_uint8(block[6]);
99 1131624 pixels[7] = av_clip_uint8(block[7]);
100
101 1131624 pixels += line_size;
102 1131624 block += 8;
103 }
104 141453 }
105
106 14262 static void put_pixels_clamped4_c(const int16_t *block, uint8_t *av_restrict pixels,
107 int line_size)
108 {
109 int i;
110
111 /* read the pixels */
112
2/2
✓ Branch 0 taken 57048 times.
✓ Branch 1 taken 14262 times.
71310 for(i=0;i<4;i++) {
113 57048 pixels[0] = av_clip_uint8(block[0]);
114 57048 pixels[1] = av_clip_uint8(block[1]);
115 57048 pixels[2] = av_clip_uint8(block[2]);
116 57048 pixels[3] = av_clip_uint8(block[3]);
117
118 57048 pixels += line_size;
119 57048 block += 8;
120 }
121 14262 }
122
123 static void put_pixels_clamped2_c(const int16_t *block, uint8_t *av_restrict pixels,
124 int line_size)
125 {
126 int i;
127
128 /* read the pixels */
129 for(i=0;i<2;i++) {
130 pixels[0] = av_clip_uint8(block[0]);
131 pixels[1] = av_clip_uint8(block[1]);
132
133 pixels += line_size;
134 block += 8;
135 }
136 }
137
138 1027939 static void put_signed_pixels_clamped_c(const int16_t *block,
139 uint8_t *av_restrict pixels,
140 ptrdiff_t line_size)
141 {
142 int i, j;
143
144
2/2
✓ Branch 0 taken 8223512 times.
✓ Branch 1 taken 1027939 times.
9251451 for (i = 0; i < 8; i++) {
145
2/2
✓ Branch 0 taken 65788096 times.
✓ Branch 1 taken 8223512 times.
74011608 for (j = 0; j < 8; j++) {
146
2/2
✓ Branch 0 taken 129 times.
✓ Branch 1 taken 65787967 times.
65788096 if (*block < -128)
147 129 *pixels = 0;
148
2/2
✓ Branch 0 taken 44010 times.
✓ Branch 1 taken 65743957 times.
65787967 else if (*block > 127)
149 44010 *pixels = 255;
150 else
151 65743957 *pixels = (uint8_t) (*block + 128);
152 65788096 block++;
153 65788096 pixels++;
154 }
155 8223512 pixels += (line_size - 8);
156 }
157 1027939 }
158
159 451712 void ff_add_pixels_clamped_c(const int16_t *block, uint8_t *av_restrict pixels,
160 ptrdiff_t line_size)
161 {
162 int i;
163
164 /* read the pixels */
165
2/2
✓ Branch 0 taken 3613696 times.
✓ Branch 1 taken 451712 times.
4065408 for (i = 0; i < 8; i++) {
166 3613696 pixels[0] = av_clip_uint8(pixels[0] + block[0]);
167 3613696 pixels[1] = av_clip_uint8(pixels[1] + block[1]);
168 3613696 pixels[2] = av_clip_uint8(pixels[2] + block[2]);
169 3613696 pixels[3] = av_clip_uint8(pixels[3] + block[3]);
170 3613696 pixels[4] = av_clip_uint8(pixels[4] + block[4]);
171 3613696 pixels[5] = av_clip_uint8(pixels[5] + block[5]);
172 3613696 pixels[6] = av_clip_uint8(pixels[6] + block[6]);
173 3613696 pixels[7] = av_clip_uint8(pixels[7] + block[7]);
174 3613696 pixels += line_size;
175 3613696 block += 8;
176 }
177 451712 }
178
179 73763 static void add_pixels_clamped4_c(const int16_t *block, uint8_t *av_restrict pixels,
180 int line_size)
181 {
182 int i;
183
184 /* read the pixels */
185
2/2
✓ Branch 0 taken 295052 times.
✓ Branch 1 taken 73763 times.
368815 for(i=0;i<4;i++) {
186 295052 pixels[0] = av_clip_uint8(pixels[0] + block[0]);
187 295052 pixels[1] = av_clip_uint8(pixels[1] + block[1]);
188 295052 pixels[2] = av_clip_uint8(pixels[2] + block[2]);
189 295052 pixels[3] = av_clip_uint8(pixels[3] + block[3]);
190 295052 pixels += line_size;
191 295052 block += 8;
192 }
193 73763 }
194
195 static void add_pixels_clamped2_c(const int16_t *block, uint8_t *av_restrict pixels,
196 int line_size)
197 {
198 int i;
199
200 /* read the pixels */
201 for(i=0;i<2;i++) {
202 pixels[0] = av_clip_uint8(pixels[0] + block[0]);
203 pixels[1] = av_clip_uint8(pixels[1] + block[1]);
204 pixels += line_size;
205 block += 8;
206 }
207 }
208
209 14262 static void ff_jref_idct4_put(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
210 {
211 14262 ff_j_rev_dct4 (block);
212 14262 put_pixels_clamped4_c(block, dest, line_size);
213 14262 }
214 73763 static void ff_jref_idct4_add(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
215 {
216 73763 ff_j_rev_dct4 (block);
217 73763 add_pixels_clamped4_c(block, dest, line_size);
218 73763 }
219
220 static void ff_jref_idct2_put(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
221 {
222 ff_j_rev_dct2 (block);
223 put_pixels_clamped2_c(block, dest, line_size);
224 }
225 static void ff_jref_idct2_add(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
226 {
227 ff_j_rev_dct2 (block);
228 add_pixels_clamped2_c(block, dest, line_size);
229 }
230
231 static void ff_jref_idct1_put(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
232 {
233 dest[0] = av_clip_uint8((block[0] + 4)>>3);
234 }
235 static void ff_jref_idct1_add(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
236 {
237 dest[0] = av_clip_uint8(dest[0] + ((block[0] + 4)>>3));
238 }
239
240 1665 av_cold void ff_idctdsp_init(IDCTDSPContext *c, AVCodecContext *avctx)
241 {
242 1665 av_unused const unsigned high_bit_depth = avctx->bits_per_raw_sample > 8;
243
244
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1664 times.
1665 if (avctx->lowres==1) {
245 1 c->idct_put = ff_jref_idct4_put;
246 1 c->idct_add = ff_jref_idct4_add;
247 1 c->idct = ff_j_rev_dct4;
248 1 c->perm_type = FF_IDCT_PERM_NONE;
249
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1664 times.
1664 } else if (avctx->lowres==2) {
250 c->idct_put = ff_jref_idct2_put;
251 c->idct_add = ff_jref_idct2_add;
252 c->idct = ff_j_rev_dct2;
253 c->perm_type = FF_IDCT_PERM_NONE;
254
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1664 times.
1664 } else if (avctx->lowres==3) {
255 c->idct_put = ff_jref_idct1_put;
256 c->idct_add = ff_jref_idct1_add;
257 c->idct = ff_j_rev_dct1;
258 c->perm_type = FF_IDCT_PERM_NONE;
259 } else {
260
3/4
✓ Branch 0 taken 1639 times.
✓ Branch 1 taken 25 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1639 times.
1664 if (avctx->bits_per_raw_sample == 10 || avctx->bits_per_raw_sample == 9) {
261 /* 10-bit MPEG-4 Simple Studio Profile requires a higher precision IDCT
262 However, it only uses idct_put */
263
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 24 times.
25 if (c->mpeg4_studio_profile) {
264 1 c->idct_put = ff_simple_idct_put_int32_10bit;
265 1 c->idct_add = NULL;
266 1 c->idct = NULL;
267 } else {
268 24 c->idct_put = ff_simple_idct_put_int16_10bit;
269 24 c->idct_add = ff_simple_idct_add_int16_10bit;
270 24 c->idct = ff_simple_idct_int16_10bit;
271 }
272 25 c->perm_type = FF_IDCT_PERM_NONE;
273
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1635 times.
1639 } else if (avctx->bits_per_raw_sample == 12) {
274 4 c->idct_put = ff_simple_idct_put_int16_12bit;
275 4 c->idct_add = ff_simple_idct_add_int16_12bit;
276 4 c->idct = ff_simple_idct_int16_12bit;
277 4 c->perm_type = FF_IDCT_PERM_NONE;
278 } else {
279
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1631 times.
1635 if (avctx->idct_algo == FF_IDCT_INT) {
280 4 c->idct_put = ff_jref_idct_put;
281 4 c->idct_add = ff_jref_idct_add;
282 4 c->idct = ff_j_rev_dct;
283 4 c->perm_type = FF_IDCT_PERM_LIBMPEG2;
284 #if CONFIG_FAANIDCT
285
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1631 times.
1631 } else if (avctx->idct_algo == FF_IDCT_FAAN) {
286 c->idct_put = ff_faanidct_put;
287 c->idct_add = ff_faanidct_add;
288 c->idct = ff_faanidct;
289 c->perm_type = FF_IDCT_PERM_NONE;
290 #endif /* CONFIG_FAANIDCT */
291 } else { // accurate/default
292 1631 c->idct_put = ff_simple_idct_put_int16_8bit;
293 1631 c->idct_add = ff_simple_idct_add_int16_8bit;
294 1631 c->idct = ff_simple_idct_int16_8bit;
295 1631 c->perm_type = FF_IDCT_PERM_NONE;
296 }
297 }
298 }
299
300 1665 c->put_pixels_clamped = ff_put_pixels_clamped_c;
301 1665 c->put_signed_pixels_clamped = put_signed_pixels_clamped_c;
302 1665 c->add_pixels_clamped = ff_add_pixels_clamped_c;
303
304
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1661 times.
1665 if (CONFIG_MPEG4_DECODER && avctx->idct_algo == FF_IDCT_XVID)
305 4 ff_xvid_idct_init(c, avctx);
306
307 #if ARCH_AARCH64
308 ff_idctdsp_init_aarch64(c, avctx, high_bit_depth);
309 #elif ARCH_ALPHA
310 ff_idctdsp_init_alpha(c, avctx, high_bit_depth);
311 #elif ARCH_ARM
312 ff_idctdsp_init_arm(c, avctx, high_bit_depth);
313 #elif ARCH_PPC
314 ff_idctdsp_init_ppc(c, avctx, high_bit_depth);
315 #elif ARCH_X86
316 1665 ff_idctdsp_init_x86(c, avctx, high_bit_depth);
317 #elif ARCH_MIPS
318 ff_idctdsp_init_mips(c, avctx, high_bit_depth);
319 #elif ARCH_LOONGARCH
320 ff_idctdsp_init_loongarch(c, avctx, high_bit_depth);
321 #endif
322
323 1665 ff_init_scantable_permutation(c->idct_permutation,
324 c->perm_type);
325 1665 }
326