FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavutil/pixelutils.c
Date: 2024-12-12 01:08:13
Exec Total Coverage
Lines: 20 22 90.9%
Functions: 7 7 100.0%
Branches: 9 14 64.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 <stddef.h>
20
21 #include "config.h"
22 #include "pixelutils.h"
23
24 #if CONFIG_PIXELUTILS
25 #include <stdlib.h>
26 #include <string.h>
27
28 #include "attributes.h"
29 #include "macros.h"
30
31 #include "x86/pixelutils.h"
32
33 68221 static av_always_inline int sad_wxh(const uint8_t *src1, ptrdiff_t stride1,
34 const uint8_t *src2, ptrdiff_t stride2,
35 int w, int h)
36 {
37 68221 int x, y, sum = 0;
38
39
2/2
✓ Branch 0 taken 545912 times.
✓ Branch 1 taken 68221 times.
614133 for (y = 0; y < h; y++) {
40
2/2
✓ Branch 0 taken 4377376 times.
✓ Branch 1 taken 545912 times.
4923288 for (x = 0; x < w; x++)
41 4377376 sum += abs(src1[x] - src2[x]);
42 545912 src1 += stride1;
43 545912 src2 += stride2;
44 }
45 68221 return sum;
46 }
47
48 #define DECLARE_BLOCK_FUNCTIONS(size) \
49 static int block_sad_##size##x##size##_c(const uint8_t *src1, ptrdiff_t stride1, \
50 const uint8_t *src2, ptrdiff_t stride2) \
51 { \
52 return sad_wxh(src1, stride1, src2, stride2, size, size); \
53 }
54
55 24 DECLARE_BLOCK_FUNCTIONS(2)
56 24 DECLARE_BLOCK_FUNCTIONS(4)
57 68149 DECLARE_BLOCK_FUNCTIONS(8)
58 12 DECLARE_BLOCK_FUNCTIONS(16)
59 12 DECLARE_BLOCK_FUNCTIONS(32)
60
61 static const av_pixelutils_sad_fn sad_c[] = {
62 block_sad_2x2_c,
63 block_sad_4x4_c,
64 block_sad_8x8_c,
65 block_sad_16x16_c,
66 block_sad_32x32_c,
67 };
68 #else
69 #include "log.h"
70 #endif /* CONFIG_PIXELUTILS */
71
72 62 av_pixelutils_sad_fn av_pixelutils_get_sad_fn(int w_bits, int h_bits, int aligned, void *log_ctx)
73 {
74 #if !CONFIG_PIXELUTILS
75 av_log(log_ctx, AV_LOG_ERROR, "pixelutils support is required "
76 "but libavutil is not compiled with it\n");
77 return NULL;
78 #else
79 av_pixelutils_sad_fn sad[FF_ARRAY_ELEMS(sad_c)];
80
81 62 memcpy(sad, sad_c, sizeof(sad));
82
83
3/6
✓ Branch 0 taken 62 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 62 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 62 times.
✗ Branch 5 not taken.
62 if (w_bits < 1 || w_bits > FF_ARRAY_ELEMS(sad) ||
84
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 62 times.
62 h_bits < 1 || h_bits > FF_ARRAY_ELEMS(sad))
85 return NULL;
86
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 62 times.
62 if (w_bits != h_bits) // only squared sad for now
87 return NULL;
88
89 #if ARCH_X86
90 62 ff_pixelutils_sad_init_x86(sad, aligned);
91 #endif
92
93 62 return sad[w_bits - 1];
94 #endif
95 }
96