/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 | | /** |
24 | | * We want to disable FP contraction because this is a reference backend that |
25 | | * establishes a bit-exact reference result. |
26 | | */ |
27 | | #ifdef __clang__ |
28 | | #pragma STDC FP_CONTRACT OFF |
29 | | #elif AV_GCC_VERSION_AT_LEAST(4, 8) |
30 | | #pragma GCC optimize ("fp-contract=off") |
31 | | #elif defined(_MSC_VER) |
32 | | #pragma fp_contract (off) |
33 | | #endif |
34 | | |
35 | | #if AV_GCC_VERSION_AT_LEAST(4, 4) |
36 | | #pragma GCC optimize ("finite-math-only") |
37 | | #endif |
38 | | |
39 | | /* Array-based reference implementation */ |
40 | | |
41 | | #ifndef SWS_BLOCK_SIZE |
42 | 0 | # define SWS_BLOCK_SIZE 32 |
43 | | #endif |
44 | | |
45 | | typedef uint8_t u8block_t[SWS_BLOCK_SIZE]; |
46 | | typedef uint16_t u16block_t[SWS_BLOCK_SIZE]; |
47 | | typedef uint32_t u32block_t[SWS_BLOCK_SIZE]; |
48 | | typedef float f32block_t[SWS_BLOCK_SIZE]; |
49 | | |
50 | | #define BIT_DEPTH 8 |
51 | | # include "ops_tmpl_int.c" |
52 | | #undef BIT_DEPTH |
53 | | |
54 | | #define BIT_DEPTH 16 |
55 | | # include "ops_tmpl_int.c" |
56 | | #undef BIT_DEPTH |
57 | | |
58 | | #define BIT_DEPTH 32 |
59 | | # include "ops_tmpl_int.c" |
60 | | # include "ops_tmpl_float.c" |
61 | | #undef BIT_DEPTH |
62 | | |
63 | | static const SwsOpTable *const tables[] = { |
64 | | &bitfn(op_table_int, u8), |
65 | | &bitfn(op_table_int, u16), |
66 | | &bitfn(op_table_int, u32), |
67 | | &bitfn(op_table_float, f32), |
68 | | }; |
69 | | |
70 | | static int compile(SwsContext *ctx, SwsOpList *ops, SwsCompiledOp *out) |
71 | 0 | { |
72 | 0 | int ret; |
73 | |
|
74 | 0 | SwsOpChain *chain = ff_sws_op_chain_alloc(); |
75 | 0 | if (!chain) |
76 | 0 | return AVERROR(ENOMEM); |
77 | | |
78 | 0 | av_assert0(ops->num_ops > 0); |
79 | 0 | const SwsPixelType read_type = ops->ops[0].type; |
80 | |
|
81 | 0 | for (int i = 0; i < ops->num_ops; i++) { |
82 | 0 | ret = ff_sws_op_compile_tables(ctx, tables, FF_ARRAY_ELEMS(tables), |
83 | 0 | ops, i, SWS_BLOCK_SIZE, chain); |
84 | 0 | if (ret < 0) { |
85 | 0 | av_log(ctx, AV_LOG_TRACE, "Failed to compile op %d\n", i); |
86 | 0 | ff_sws_op_chain_free(chain); |
87 | 0 | return ret; |
88 | 0 | } |
89 | 0 | } |
90 | | |
91 | 0 | *out = (SwsCompiledOp) { |
92 | 0 | .slice_align = 1, |
93 | 0 | .block_size = SWS_BLOCK_SIZE, |
94 | 0 | .cpu_flags = chain->cpu_flags, |
95 | 0 | .over_read = chain->over_read, |
96 | 0 | .over_write = chain->over_write, |
97 | 0 | .priv = chain, |
98 | 0 | .free = ff_sws_op_chain_free_cb, |
99 | 0 | }; |
100 | |
|
101 | 0 | switch (read_type) { |
102 | 0 | case SWS_PIXEL_U8: out->func = process_u8; break; |
103 | 0 | case SWS_PIXEL_U16: out->func = process_u16; break; |
104 | 0 | case SWS_PIXEL_U32: out->func = process_u32; break; |
105 | 0 | case SWS_PIXEL_F32: out->func = process_f32; break; |
106 | 0 | default: av_unreachable("Invalid pixel type!"); |
107 | 0 | } |
108 | | |
109 | 0 | return 0; |
110 | 0 | } |
111 | | |
112 | | const SwsOpBackend backend_c = { |
113 | | .name = "c", |
114 | | .compile = compile, |
115 | | .hw_format = AV_PIX_FMT_NONE, |
116 | | }; |