FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/idctdsp.c
Date: 2024-04-19 07:31:02
Exec Total Coverage
Lines: 126 172 73.3%
Functions: 10 16 62.5%
Branches: 45 57 78.9%

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 18922 av_cold void ff_permute_scantable(uint8_t dst[64], const uint8_t src[64],
31 const uint8_t permutation[64])
32 {
33
2/2
✓ Branch 0 taken 1211008 times.
✓ Branch 1 taken 18922 times.
1229930 for (int i = 0; i < 64; i++) {
34 1211008 int j = src[i];
35 1211008 dst[i] = permutation[j];
36 }
37 18922 }
38
39 1729 av_cold void ff_init_scantable_permutation(uint8_t *idct_permutation,
40 enum idct_permutation_type perm_type)
41 {
42 int i;
43
44 #if ARCH_X86
45
2/2
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 1725 times.
1729 if (ff_init_scantable_permutation_x86(idct_permutation,
46 perm_type))
47 4 return;
48 #endif
49
50
3/5
✓ Branch 0 taken 1473 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 248 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1725 switch (perm_type) {
51 1473 case FF_IDCT_PERM_NONE:
52
2/2
✓ Branch 0 taken 94272 times.
✓ Branch 1 taken 1473 times.
95745 for (i = 0; i < 64; i++)
53 94272 idct_permutation[i] = i;
54 1473 break;
55 4 case FF_IDCT_PERM_LIBMPEG2:
56
2/2
✓ Branch 0 taken 256 times.
✓ Branch 1 taken 4 times.
260 for (i = 0; i < 64; i++)
57 256 idct_permutation[i] = (i & 0x38) | ((i & 6) >> 1) | ((i & 1) << 2);
58 4 break;
59 248 case FF_IDCT_PERM_TRANSPOSE:
60
2/2
✓ Branch 0 taken 15872 times.
✓ Branch 1 taken 248 times.
16120 for (i = 0; i < 64; i++)
61 15872 idct_permutation[i] = ((i & 7) << 3) | (i >> 3);
62 248 break;
63 case FF_IDCT_PERM_PARTTRANS:
64 for (i = 0; i < 64; i++)
65 idct_permutation[i] = (i & 0x24) | ((i & 3) << 3) | ((i >> 3) & 3);
66 break;
67 default:
68 av_log(NULL, AV_LOG_ERROR,
69 "Internal error, IDCT permutation not set\n");
70 }
71 }
72
73 163353 void ff_put_pixels_clamped_c(const int16_t *block, uint8_t *restrict pixels,
74 ptrdiff_t line_size)
75 {
76 int i;
77
78 /* read the pixels */
79
2/2
✓ Branch 0 taken 1306824 times.
✓ Branch 1 taken 163353 times.
1470177 for (i = 0; i < 8; i++) {
80 1306824 pixels[0] = av_clip_uint8(block[0]);
81 1306824 pixels[1] = av_clip_uint8(block[1]);
82 1306824 pixels[2] = av_clip_uint8(block[2]);
83 1306824 pixels[3] = av_clip_uint8(block[3]);
84 1306824 pixels[4] = av_clip_uint8(block[4]);
85 1306824 pixels[5] = av_clip_uint8(block[5]);
86 1306824 pixels[6] = av_clip_uint8(block[6]);
87 1306824 pixels[7] = av_clip_uint8(block[7]);
88
89 1306824 pixels += line_size;
90 1306824 block += 8;
91 }
92 163353 }
93
94 14262 static void put_pixels_clamped4_c(const int16_t *block, uint8_t *restrict pixels,
95 int line_size)
96 {
97 int i;
98
99 /* read the pixels */
100
2/2
✓ Branch 0 taken 57048 times.
✓ Branch 1 taken 14262 times.
71310 for(i=0;i<4;i++) {
101 57048 pixels[0] = av_clip_uint8(block[0]);
102 57048 pixels[1] = av_clip_uint8(block[1]);
103 57048 pixels[2] = av_clip_uint8(block[2]);
104 57048 pixels[3] = av_clip_uint8(block[3]);
105
106 57048 pixels += line_size;
107 57048 block += 8;
108 }
109 14262 }
110
111 static void put_pixels_clamped2_c(const int16_t *block, uint8_t *restrict pixels,
112 int line_size)
113 {
114 int i;
115
116 /* read the pixels */
117 for(i=0;i<2;i++) {
118 pixels[0] = av_clip_uint8(block[0]);
119 pixels[1] = av_clip_uint8(block[1]);
120
121 pixels += line_size;
122 block += 8;
123 }
124 }
125
126 1102033 static void put_signed_pixels_clamped_c(const int16_t *block,
127 uint8_t *restrict pixels,
128 ptrdiff_t line_size)
129 {
130 int i, j;
131
132
2/2
✓ Branch 0 taken 8816264 times.
✓ Branch 1 taken 1102033 times.
9918297 for (i = 0; i < 8; i++) {
133
2/2
✓ Branch 0 taken 70530112 times.
✓ Branch 1 taken 8816264 times.
79346376 for (j = 0; j < 8; j++) {
134
2/2
✓ Branch 0 taken 119 times.
✓ Branch 1 taken 70529993 times.
70530112 if (*block < -128)
135 119 *pixels = 0;
136
2/2
✓ Branch 0 taken 44017 times.
✓ Branch 1 taken 70485976 times.
70529993 else if (*block > 127)
137 44017 *pixels = 255;
138 else
139 70485976 *pixels = (uint8_t) (*block + 128);
140 70530112 block++;
141 70530112 pixels++;
142 }
143 8816264 pixels += (line_size - 8);
144 }
145 1102033 }
146
147 452108 void ff_add_pixels_clamped_c(const int16_t *block, uint8_t *restrict pixels,
148 ptrdiff_t line_size)
149 {
150 int i;
151
152 /* read the pixels */
153
2/2
✓ Branch 0 taken 3616864 times.
✓ Branch 1 taken 452108 times.
4068972 for (i = 0; i < 8; i++) {
154 3616864 pixels[0] = av_clip_uint8(pixels[0] + block[0]);
155 3616864 pixels[1] = av_clip_uint8(pixels[1] + block[1]);
156 3616864 pixels[2] = av_clip_uint8(pixels[2] + block[2]);
157 3616864 pixels[3] = av_clip_uint8(pixels[3] + block[3]);
158 3616864 pixels[4] = av_clip_uint8(pixels[4] + block[4]);
159 3616864 pixels[5] = av_clip_uint8(pixels[5] + block[5]);
160 3616864 pixels[6] = av_clip_uint8(pixels[6] + block[6]);
161 3616864 pixels[7] = av_clip_uint8(pixels[7] + block[7]);
162 3616864 pixels += line_size;
163 3616864 block += 8;
164 }
165 452108 }
166
167 73763 static void add_pixels_clamped4_c(const int16_t *block, uint8_t *restrict pixels,
168 int line_size)
169 {
170 int i;
171
172 /* read the pixels */
173
2/2
✓ Branch 0 taken 295052 times.
✓ Branch 1 taken 73763 times.
368815 for(i=0;i<4;i++) {
174 295052 pixels[0] = av_clip_uint8(pixels[0] + block[0]);
175 295052 pixels[1] = av_clip_uint8(pixels[1] + block[1]);
176 295052 pixels[2] = av_clip_uint8(pixels[2] + block[2]);
177 295052 pixels[3] = av_clip_uint8(pixels[3] + block[3]);
178 295052 pixels += line_size;
179 295052 block += 8;
180 }
181 73763 }
182
183 static void add_pixels_clamped2_c(const int16_t *block, uint8_t *restrict pixels,
184 int line_size)
185 {
186 int i;
187
188 /* read the pixels */
189 for(i=0;i<2;i++) {
190 pixels[0] = av_clip_uint8(pixels[0] + block[0]);
191 pixels[1] = av_clip_uint8(pixels[1] + block[1]);
192 pixels += line_size;
193 block += 8;
194 }
195 }
196
197 14262 static void ff_jref_idct4_put(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
198 {
199 14262 ff_j_rev_dct4 (block);
200 14262 put_pixels_clamped4_c(block, dest, line_size);
201 14262 }
202 73763 static void ff_jref_idct4_add(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
203 {
204 73763 ff_j_rev_dct4 (block);
205 73763 add_pixels_clamped4_c(block, dest, line_size);
206 73763 }
207
208 static void ff_jref_idct2_put(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
209 {
210 ff_j_rev_dct2 (block);
211 put_pixels_clamped2_c(block, dest, line_size);
212 }
213 static void ff_jref_idct2_add(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
214 {
215 ff_j_rev_dct2 (block);
216 add_pixels_clamped2_c(block, dest, line_size);
217 }
218
219 static void ff_jref_idct1_put(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
220 {
221 dest[0] = av_clip_uint8((block[0] + 4)>>3);
222 }
223 static void ff_jref_idct1_add(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
224 {
225 dest[0] = av_clip_uint8(dest[0] + ((block[0] + 4)>>3));
226 }
227
228 1511 av_cold void ff_idctdsp_init(IDCTDSPContext *c, AVCodecContext *avctx)
229 {
230 1511 av_unused const unsigned high_bit_depth = avctx->bits_per_raw_sample > 8;
231
232
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1510 times.
1511 if (avctx->lowres==1) {
233 1 c->idct_put = ff_jref_idct4_put;
234 1 c->idct_add = ff_jref_idct4_add;
235 1 c->idct = ff_j_rev_dct4;
236 1 c->perm_type = FF_IDCT_PERM_NONE;
237
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1510 times.
1510 } else if (avctx->lowres==2) {
238 c->idct_put = ff_jref_idct2_put;
239 c->idct_add = ff_jref_idct2_add;
240 c->idct = ff_j_rev_dct2;
241 c->perm_type = FF_IDCT_PERM_NONE;
242
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1510 times.
1510 } else if (avctx->lowres==3) {
243 c->idct_put = ff_jref_idct1_put;
244 c->idct_add = ff_jref_idct1_add;
245 c->idct = ff_j_rev_dct1;
246 c->perm_type = FF_IDCT_PERM_NONE;
247 } else {
248
3/4
✓ Branch 0 taken 1485 times.
✓ Branch 1 taken 25 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1485 times.
1510 if (avctx->bits_per_raw_sample == 10 || avctx->bits_per_raw_sample == 9) {
249 /* 10-bit MPEG-4 Simple Studio Profile requires a higher precision IDCT
250 However, it only uses idct_put */
251
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 24 times.
25 if (c->mpeg4_studio_profile) {
252 1 c->idct_put = ff_simple_idct_put_int32_10bit;
253 1 c->idct_add = NULL;
254 1 c->idct = NULL;
255 } else {
256 24 c->idct_put = ff_simple_idct_put_int16_10bit;
257 24 c->idct_add = ff_simple_idct_add_int16_10bit;
258 24 c->idct = ff_simple_idct_int16_10bit;
259 }
260 25 c->perm_type = FF_IDCT_PERM_NONE;
261
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1481 times.
1485 } else if (avctx->bits_per_raw_sample == 12) {
262 4 c->idct_put = ff_simple_idct_put_int16_12bit;
263 4 c->idct_add = ff_simple_idct_add_int16_12bit;
264 4 c->idct = ff_simple_idct_int16_12bit;
265 4 c->perm_type = FF_IDCT_PERM_NONE;
266 } else {
267
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1477 times.
1481 if (avctx->idct_algo == FF_IDCT_INT) {
268 4 c->idct_put = ff_jref_idct_put;
269 4 c->idct_add = ff_jref_idct_add;
270 4 c->idct = ff_j_rev_dct;
271 4 c->perm_type = FF_IDCT_PERM_LIBMPEG2;
272 #if CONFIG_FAANIDCT
273
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1477 times.
1477 } else if (avctx->idct_algo == FF_IDCT_FAAN) {
274 c->idct_put = ff_faanidct_put;
275 c->idct_add = ff_faanidct_add;
276 c->idct = ff_faanidct;
277 c->perm_type = FF_IDCT_PERM_NONE;
278 #endif /* CONFIG_FAANIDCT */
279 } else { // accurate/default
280 1477 c->idct_put = ff_simple_idct_put_int16_8bit;
281 1477 c->idct_add = ff_simple_idct_add_int16_8bit;
282 1477 c->idct = ff_simple_idct_int16_8bit;
283 1477 c->perm_type = FF_IDCT_PERM_NONE;
284 }
285 }
286 }
287
288 1511 c->put_pixels_clamped = ff_put_pixels_clamped_c;
289 1511 c->put_signed_pixels_clamped = put_signed_pixels_clamped_c;
290 1511 c->add_pixels_clamped = ff_add_pixels_clamped_c;
291
292
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1507 times.
1511 if (CONFIG_MPEG4_DECODER && avctx->idct_algo == FF_IDCT_XVID)
293 4 ff_xvid_idct_init(c, avctx);
294
295 #if ARCH_AARCH64
296 ff_idctdsp_init_aarch64(c, avctx, high_bit_depth);
297 #elif ARCH_ALPHA
298 ff_idctdsp_init_alpha(c, avctx, high_bit_depth);
299 #elif ARCH_ARM
300 ff_idctdsp_init_arm(c, avctx, high_bit_depth);
301 #elif ARCH_PPC
302 ff_idctdsp_init_ppc(c, avctx, high_bit_depth);
303 #elif ARCH_RISCV
304 ff_idctdsp_init_riscv(c, avctx, high_bit_depth);
305 #elif ARCH_X86
306 1511 ff_idctdsp_init_x86(c, avctx, high_bit_depth);
307 #elif ARCH_MIPS
308 ff_idctdsp_init_mips(c, avctx, high_bit_depth);
309 #elif ARCH_LOONGARCH
310 ff_idctdsp_init_loongarch(c, avctx, high_bit_depth);
311 #endif
312
313 1511 ff_init_scantable_permutation(c->idct_permutation,
314 c->perm_type);
315 1511 }
316