FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libswscale/ops_backend.c
Date: 2025-09-09 00:08:58
Exec Total Coverage
Lines: 20 23 87.0%
Functions: 2 2 100.0%
Branches: 10 12 83.3%

Line Branch Exec Source
1 /**
2 * Copyright (C) 2025 Niklas Haas
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include "ops_backend.h"
22
23 #if AV_GCC_VERSION_AT_LEAST(4, 4)
24 #pragma GCC optimize ("finite-math-only")
25 #endif
26
27 /* Array-based reference implementation */
28
29 #ifndef SWS_BLOCK_SIZE
30 # define SWS_BLOCK_SIZE 32
31 #endif
32
33 typedef uint8_t u8block_t[SWS_BLOCK_SIZE];
34 typedef uint16_t u16block_t[SWS_BLOCK_SIZE];
35 typedef uint32_t u32block_t[SWS_BLOCK_SIZE];
36 typedef float f32block_t[SWS_BLOCK_SIZE];
37
38 #define BIT_DEPTH 8
39 # include "ops_tmpl_int.c"
40 #undef BIT_DEPTH
41
42 #define BIT_DEPTH 16
43 # include "ops_tmpl_int.c"
44 #undef BIT_DEPTH
45
46 #define BIT_DEPTH 32
47 # include "ops_tmpl_int.c"
48 # include "ops_tmpl_float.c"
49 #undef BIT_DEPTH
50
51 1162 static void process(const SwsOpExec *exec, const void *priv,
52 const int bx_start, const int y_start, int bx_end, int y_end)
53 {
54 1162 const SwsOpChain *chain = priv;
55 1162 const SwsOpImpl *impl = chain->impl;
56 SwsOpIter iter;
57
58
2/2
✓ Branch 0 taken 2324 times.
✓ Branch 1 taken 1162 times.
3486 for (iter.y = y_start; iter.y < y_end; iter.y++) {
59
2/2
✓ Branch 0 taken 9296 times.
✓ Branch 1 taken 2324 times.
11620 for (int i = 0; i < 4; i++) {
60 9296 iter.in[i] = exec->in[i] + (iter.y - y_start) * exec->in_stride[i];
61 9296 iter.out[i] = exec->out[i] + (iter.y - y_start) * exec->out_stride[i];
62 }
63
64
2/2
✓ Branch 0 taken 4648 times.
✓ Branch 1 taken 2324 times.
6972 for (int block = bx_start; block < bx_end; block++) {
65 4648 iter.x = block * SWS_BLOCK_SIZE;
66 4648 ((void (*)(SwsOpIter *, const SwsOpImpl *)) impl->cont)
67 (&iter, &impl[1]);
68 }
69 }
70 1162 }
71
72 6422 static int compile(SwsContext *ctx, SwsOpList *ops, SwsCompiledOp *out)
73 {
74 int ret;
75
76 6422 SwsOpChain *chain = ff_sws_op_chain_alloc();
77
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6422 times.
6422 if (!chain)
78 return AVERROR(ENOMEM);
79
80 static const SwsOpTable *const tables[] = {
81 &bitfn(op_table_int, u8),
82 &bitfn(op_table_int, u16),
83 &bitfn(op_table_int, u32),
84 &bitfn(op_table_float, f32),
85 };
86
87 do {
88 19240 ret = ff_sws_op_compile_tables(tables, FF_ARRAY_ELEMS(tables), ops,
89 SWS_BLOCK_SIZE, chain);
90
2/2
✓ Branch 0 taken 12818 times.
✓ Branch 1 taken 6422 times.
19240 } while (ret == AVERROR(EAGAIN));
91
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6422 times.
6422 if (ret < 0) {
92 ff_sws_op_chain_free(chain);
93 return ret;
94 }
95
96 6422 *out = (SwsCompiledOp) {
97 .func = process,
98 .block_size = SWS_BLOCK_SIZE,
99 6422 .cpu_flags = chain->cpu_flags,
100 .priv = chain,
101 .free = (void (*)(void *)) ff_sws_op_chain_free,
102 };
103 6422 return 0;
104 }
105
106 const SwsOpBackend backend_c = {
107 .name = "c",
108 .compile = compile,
109 };
110