FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libswscale/ops_backend.h
Date: 2026-04-24 19:58:39
Exec Total Coverage
Lines: 4 4 100.0%
Functions: 1 1 100.0%
Branches: 1 2 50.0%

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 #ifndef SWSCALE_OPS_BACKEND_H
22 #define SWSCALE_OPS_BACKEND_H
23
24 /**
25 * Helper macros for the C-based backend.
26 *
27 * To use these macros, the following types must be defined:
28 * - PIXEL_TYPE should be one of SWS_PIXEL_*
29 * - pixel_t should be the type of pixels
30 * - block_t should be the type of blocks (groups of pixels)
31 */
32
33 #include <assert.h>
34 #include <float.h>
35 #include <stdint.h>
36
37 #include "libavutil/attributes.h"
38 #include "libavutil/mem.h"
39
40 #include "ops_chain.h"
41
42 /**
43 * Internal context holding per-iter execution data. The data pointers will be
44 * directly incremented by the corresponding read/write functions.
45 */
46 typedef struct SwsOpIter {
47 uintptr_t in[4];
48 uintptr_t out[4];
49 int x, y;
50
51 /* Link back to per-slice execution context */
52 const SwsOpExec *exec;
53 } SwsOpIter;
54
55 #ifdef __clang__
56 # define SWS_LOOP AV_PRAGMA(clang loop vectorize(assume_safety))
57 #elif defined(__GNUC__)
58 # define SWS_LOOP AV_PRAGMA(GCC ivdep)
59 #else
60 # define SWS_LOOP
61 #endif
62
63 /* Miscellaneous helpers */
64 #define bitfn2(name, ext) name ## _ ## ext
65 #define bitfn(name, ext) bitfn2(name, ext)
66
67 #define FN_SUFFIX AV_JOIN(FMT_CHAR, BIT_DEPTH)
68 #define fn(name) bitfn(name, FN_SUFFIX)
69
70 #define av_q2pixel(q) ((q).den ? (pixel_t) (q).num / (q).den : 0)
71 #define bump_ptr(ptr, bump) ((pixel_t *) ((uintptr_t) (ptr) + (bump)))
72
73 /* Helper macros to make writing common function signatures less painful */
74 #define DECL_FUNC(NAME, ...) \
75 static av_always_inline void fn(NAME)(SwsOpIter *restrict iter, \
76 const SwsOpImpl *restrict impl, \
77 block_t x, block_t y, \
78 block_t z, block_t w, \
79 __VA_ARGS__)
80
81 #define DECL_READ(NAME, ...) \
82 DECL_FUNC(NAME, const pixel_t *restrict in0, const pixel_t *restrict in1, \
83 const pixel_t *restrict in2, const pixel_t *restrict in3, \
84 __VA_ARGS__)
85
86 #define DECL_WRITE(NAME, ...) \
87 DECL_FUNC(NAME, pixel_t *restrict out0, pixel_t *restrict out1, \
88 pixel_t *restrict out2, pixel_t *restrict out3, \
89 __VA_ARGS__)
90
91 /* Helper macros to call into functions declared with DECL_FUNC_* */
92 #define CALL(FUNC, ...) \
93 fn(FUNC)(iter, impl, x, y, z, w, __VA_ARGS__)
94
95 #define CALL_READ(FUNC, ...) \
96 CALL(FUNC, (const pixel_t *) iter->in[0], (const pixel_t *) iter->in[1], \
97 (const pixel_t *) iter->in[2], (const pixel_t *) iter->in[3], \
98 __VA_ARGS__)
99
100 #define CALL_WRITE(FUNC, ...) \
101 CALL(FUNC, (pixel_t *) iter->out[0], (pixel_t *) iter->out[1], \
102 (pixel_t *) iter->out[2], (pixel_t *) iter->out[3], __VA_ARGS__)
103
104 /* Helper macros to declare continuation functions */
105 #define DECL_IMPL(FUNC, NAME, ...) \
106 static void av_flatten fn(NAME)(SwsOpIter *restrict iter, \
107 const SwsOpImpl *restrict impl, \
108 void *restrict x, void *restrict y, \
109 void *restrict z, void *restrict w) \
110 { \
111 CALL(FUNC, __VA_ARGS__); \
112 }
113
114 /* Helper macro to call into the next continuation */
115 #define CONTINUE(X, Y, Z, W) \
116 ((void (*)(SwsOpIter *, const SwsOpImpl *, \
117 void *restrict, void *restrict, \
118 void *restrict, void *restrict)) impl->cont) \
119 (iter, &impl[1], (X), (Y), (Z), (W))
120
121 /* Helper macros for common op setup code */
122 #define DECL_SETUP(NAME, PARAMS, OUT) \
123 static int fn(NAME)(const SwsImplParams *PARAMS, SwsImplResult *OUT)
124
125 #define SETUP_MEMDUP(c, out) ff_setup_memdup(&(c), sizeof(c), out)
126 772 static inline int ff_setup_memdup(const void *c, size_t size, SwsImplResult *out)
127 {
128 772 out->priv.ptr = av_memdup(c, size);
129 772 out->free = ff_op_priv_free;
130
1/2
✓ Branch 0 taken 772 times.
✗ Branch 1 not taken.
772 return out->priv.ptr ? 0 : AVERROR(ENOMEM);
131 }
132
133 /* Helper macro for declaring op table entries */
134 #define DECL_ENTRY(NAME, MASK, ...) \
135 static const SwsOpEntry fn(op_##NAME) = { \
136 .func = (SwsFuncPtr) fn(NAME), \
137 .type = PIXEL_TYPE, \
138 .mask = (MASK), \
139 __VA_ARGS__ \
140 }
141
142 /* Helpers to define functions for common subsets of components */
143 #define DECL_PATTERN(NAME) \
144 DECL_FUNC(NAME, const bool X, const bool Y, const bool Z, const bool W)
145
146 #define WRAP_PATTERN(FUNC, X, Y, Z, W, ...) \
147 DECL_IMPL(FUNC, FUNC##_##X##Y##Z##W, X, Y, Z, W) \
148 DECL_ENTRY(FUNC##_##X##Y##Z##W, SWS_COMP_MASK(X, Y, Z, W), __VA_ARGS__)
149
150 #define WRAP_COMMON_PATTERNS(FUNC, ...) \
151 WRAP_PATTERN(FUNC, 1, 0, 0, 0, __VA_ARGS__); \
152 WRAP_PATTERN(FUNC, 1, 0, 0, 1, __VA_ARGS__); \
153 WRAP_PATTERN(FUNC, 1, 1, 1, 0, __VA_ARGS__); \
154 WRAP_PATTERN(FUNC, 1, 1, 1, 1, __VA_ARGS__)
155
156 #define REF_COMMON_PATTERNS(NAME) \
157 &fn(op_##NAME##_1000), \
158 &fn(op_##NAME##_1001), \
159 &fn(op_##NAME##_1110), \
160 &fn(op_##NAME##_1111)
161
162 #endif
163