Coverage Report

Created: 2025-11-16 07:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ffmpeg/libswscale/ops_backend.c
Line
Count
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
0
#  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
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
0
{
54
0
    const SwsOpChain *chain = priv;
55
0
    const SwsOpImpl *impl = chain->impl;
56
0
    SwsOpIter iter;
57
58
0
    for (iter.y = y_start; iter.y < y_end; iter.y++) {
59
0
        for (int i = 0; i < 4; i++) {
60
0
            iter.in[i]  = exec->in[i]  + (iter.y - y_start) * exec->in_stride[i];
61
0
            iter.out[i] = exec->out[i] + (iter.y - y_start) * exec->out_stride[i];
62
0
        }
63
64
0
        for (int block = bx_start; block < bx_end; block++) {
65
0
            iter.x = block * SWS_BLOCK_SIZE;
66
0
            ((void (*)(SwsOpIter *, const SwsOpImpl *)) impl->cont)
67
0
                (&iter, &impl[1]);
68
0
        }
69
0
    }
70
0
}
71
72
static int compile(SwsContext *ctx, SwsOpList *ops, SwsCompiledOp *out)
73
0
{
74
0
    int ret;
75
76
0
    SwsOpChain *chain = ff_sws_op_chain_alloc();
77
0
    if (!chain)
78
0
        return AVERROR(ENOMEM);
79
80
0
    static const SwsOpTable *const tables[] = {
81
0
        &bitfn(op_table_int,    u8),
82
0
        &bitfn(op_table_int,   u16),
83
0
        &bitfn(op_table_int,   u32),
84
0
        &bitfn(op_table_float, f32),
85
0
    };
86
87
0
    do {
88
0
        ret = ff_sws_op_compile_tables(tables, FF_ARRAY_ELEMS(tables), ops,
89
0
                                       SWS_BLOCK_SIZE, chain);
90
0
    } while (ret == AVERROR(EAGAIN));
91
0
    if (ret < 0) {
92
0
        ff_sws_op_chain_free(chain);
93
0
        return ret;
94
0
    }
95
96
0
    *out = (SwsCompiledOp) {
97
0
        .func       = process,
98
0
        .block_size = SWS_BLOCK_SIZE,
99
0
        .cpu_flags  = chain->cpu_flags,
100
0
        .priv       = chain,
101
0
        .free       = ff_sws_op_chain_free_cb,
102
0
    };
103
0
    return 0;
104
0
}
105
106
const SwsOpBackend backend_c = {
107
    .name       = "c",
108
    .compile    = compile,
109
};