/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 const SwsOpTable *const tables[] = { |
52 | | &bitfn(op_table_int, u8), |
53 | | &bitfn(op_table_int, u16), |
54 | | &bitfn(op_table_int, u32), |
55 | | &bitfn(op_table_float, f32), |
56 | | }; |
57 | | |
58 | | static int compile(SwsContext *ctx, SwsOpList *ops, SwsCompiledOp *out) |
59 | 0 | { |
60 | 0 | int ret; |
61 | |
|
62 | 0 | SwsOpChain *chain = ff_sws_op_chain_alloc(); |
63 | 0 | if (!chain) |
64 | 0 | return AVERROR(ENOMEM); |
65 | | |
66 | 0 | av_assert0(ops->num_ops > 0); |
67 | 0 | const SwsPixelType read_type = ops->ops[0].type; |
68 | | |
69 | | /* Make on-stack copy of `ops` to iterate over */ |
70 | 0 | SwsOpList rest = *ops; |
71 | 0 | do { |
72 | 0 | ret = ff_sws_op_compile_tables(tables, FF_ARRAY_ELEMS(tables), &rest, |
73 | 0 | SWS_BLOCK_SIZE, chain); |
74 | 0 | } while (ret == AVERROR(EAGAIN)); |
75 | |
|
76 | 0 | if (ret < 0) { |
77 | 0 | ff_sws_op_chain_free(chain); |
78 | 0 | if (rest.num_ops < ops->num_ops) { |
79 | 0 | av_log(ctx, AV_LOG_TRACE, "Uncompiled remainder:\n"); |
80 | 0 | ff_sws_op_list_print(ctx, AV_LOG_TRACE, AV_LOG_TRACE, &rest); |
81 | 0 | } |
82 | 0 | return ret; |
83 | 0 | } |
84 | | |
85 | 0 | *out = (SwsCompiledOp) { |
86 | 0 | .slice_align = 1, |
87 | 0 | .block_size = SWS_BLOCK_SIZE, |
88 | 0 | .cpu_flags = chain->cpu_flags, |
89 | 0 | .priv = chain, |
90 | 0 | .free = ff_sws_op_chain_free_cb, |
91 | 0 | }; |
92 | |
|
93 | 0 | switch (read_type) { |
94 | 0 | case SWS_PIXEL_U8: out->func = process_u8; break; |
95 | 0 | case SWS_PIXEL_U16: out->func = process_u16; break; |
96 | 0 | case SWS_PIXEL_U32: out->func = process_u32; break; |
97 | 0 | case SWS_PIXEL_F32: out->func = process_f32; break; |
98 | 0 | default: av_unreachable("Invalid pixel type!"); |
99 | 0 | } |
100 | | |
101 | 0 | return 0; |
102 | 0 | } |
103 | | |
104 | | const SwsOpBackend backend_c = { |
105 | | .name = "c", |
106 | | .compile = compile, |
107 | | .hw_format = AV_PIX_FMT_NONE, |
108 | | }; |