FFmpeg
ops_tmpl_common.c
Go to the documentation of this file.
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 #ifndef BIT_DEPTH
24 # error Should only be included from ops_tmpl_*.c!
25 #endif
26 
27 #define WRAP_CONVERT_UINT(N) \
28 DECL_PATTERN(convert_uint##N) \
29 { \
30  u##N##block_t xu, yu, zu, wu; \
31  \
32  SWS_LOOP \
33  for (int i = 0; i < SWS_BLOCK_SIZE; i++) { \
34  if (X) \
35  xu[i] = x[i]; \
36  if (Y) \
37  yu[i] = y[i]; \
38  if (Z) \
39  zu[i] = z[i]; \
40  if (W) \
41  wu[i] = w[i]; \
42  } \
43  \
44  CONTINUE(u##N##block_t, xu, yu, zu, wu); \
45 } \
46  \
47 WRAP_COMMON_PATTERNS(convert_uint##N, \
48  .op = SWS_OP_CONVERT, \
49  .convert.to = SWS_PIXEL_U##N, \
50 );
51 
52 #if BIT_DEPTH != 8
54 #endif
55 
56 #if BIT_DEPTH != 16
58 #endif
59 
60 #if BIT_DEPTH != 32 || defined(IS_FLOAT)
62 #endif
63 
65 {
66  SWS_LOOP
67  for (int i = 0; i < SWS_BLOCK_SIZE; i++) {
68  if (!X)
69  x[i] = impl->priv.px[0];
70  if (!Y)
71  y[i] = impl->priv.px[1];
72  if (!Z)
73  z[i] = impl->priv.px[2];
74  if (!W)
75  w[i] = impl->priv.px[3];
76  }
77 
78  CONTINUE(block_t, x, y, z, w);
79 }
80 
81 #define WRAP_CLEAR(X, Y, Z, W) \
82 DECL_IMPL(clear##_##X##Y##Z##W) \
83 { \
84  CALL(clear, X, Y, Z, W); \
85 } \
86  \
87 DECL_ENTRY(clear##_##X##Y##Z##W, \
88  .setup = ff_sws_setup_q4, \
89  .op = SWS_OP_CLEAR, \
90  .flexible = true, \
91  .unused = { !X, !Y, !Z, !W }, \
92 );
93 
94 WRAP_CLEAR(1, 1, 1, 0) /* rgba alpha */
95 WRAP_CLEAR(0, 1, 1, 1) /* argb alpha */
96 
97 WRAP_CLEAR(0, 0, 1, 1) /* vuya chroma */
98 WRAP_CLEAR(1, 0, 0, 1) /* yuva chroma */
99 WRAP_CLEAR(1, 1, 0, 0) /* ayuv chroma */
100 WRAP_CLEAR(0, 1, 0, 1) /* uyva chroma */
101 WRAP_CLEAR(1, 0, 1, 0) /* xvyu chroma */
102 
103 WRAP_CLEAR(1, 0, 0, 0) /* gray -> yuva */
104 WRAP_CLEAR(0, 1, 0, 0) /* gray -> ayuv */
105 WRAP_CLEAR(0, 0, 1, 0) /* gray -> vuya */
106 
108 {
109  SWS_LOOP
110  for (int i = 0; i < SWS_BLOCK_SIZE; i++) {
111  if (X)
112  x[i] = FFMIN(x[i], impl->priv.px[0]);
113  if (Y)
114  y[i] = FFMIN(y[i], impl->priv.px[1]);
115  if (Z)
116  z[i] = FFMIN(z[i], impl->priv.px[2]);
117  if (W)
118  w[i] = FFMIN(w[i], impl->priv.px[3]);
119  }
120 
121  CONTINUE(block_t, x, y, z, w);
122 }
123 
125 {
126  SWS_LOOP
127  for (int i = 0; i < SWS_BLOCK_SIZE; i++) {
128  if (X)
129  x[i] = FFMAX(x[i], impl->priv.px[0]);
130  if (Y)
131  y[i] = FFMAX(y[i], impl->priv.px[1]);
132  if (Z)
133  z[i] = FFMAX(z[i], impl->priv.px[2]);
134  if (W)
135  w[i] = FFMAX(w[i], impl->priv.px[3]);
136  }
137 
138  CONTINUE(block_t, x, y, z, w);
139 }
140 
142  .op = SWS_OP_MIN,
143  .setup = ff_sws_setup_q4,
144  .flexible = true,
145 );
146 
148  .op = SWS_OP_MAX,
149  .setup = ff_sws_setup_q4,
150  .flexible = true,
151 );
152 
154 {
155  const pixel_t scale = impl->priv.px[0];
156 
157  SWS_LOOP
158  for (int i = 0; i < SWS_BLOCK_SIZE; i++) {
159  if (X)
160  x[i] *= scale;
161  if (Y)
162  y[i] *= scale;
163  if (Z)
164  z[i] *= scale;
165  if (W)
166  w[i] *= scale;
167  }
168 
169  CONTINUE(block_t, x, y, z, w);
170 }
171 
173  .op = SWS_OP_SCALE,
174  .setup = ff_sws_setup_q,
175  .flexible = true,
176 );
WRAP_CLEAR
#define WRAP_CLEAR(X, Y, Z, W)
Definition: ops_tmpl_common.c:81
W
@ W
Definition: vf_addroi.c:27
ops_backend.h
block_t
#define block_t
Definition: ops_tmpl_float.c:34
w
uint8_t w
Definition: llviddspenc.c:38
max
#define max(a, b)
Definition: cuda_runtime.h:33
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
WRAP_CONVERT_UINT
#define WRAP_CONVERT_UINT(N)
Copyright (C) 2025 Niklas Haas.
Definition: ops_tmpl_common.c:27
X
@ X
Definition: vf_addroi.c:27
DECL_PATTERN
DECL_PATTERN(clear)
Definition: ops_tmpl_common.c:64
WRAP_COMMON_PATTERNS
WRAP_COMMON_PATTERNS(min,.op=SWS_OP_MIN,.setup=ff_sws_setup_q4,.flexible=true,)
SWS_OP_SCALE
@ SWS_OP_SCALE
Definition: ops.h:64
ff_sws_setup_q
int ff_sws_setup_q(const SwsOp *op, SwsOpPriv *out)
Definition: ops_chain.c:265
CONTINUE
#define CONTINUE(TYPE,...)
Definition: ops_backend.h:116
op
static int op(uint8_t **dst, const uint8_t *dst_end, GetByteContext *gb, int pixel, int count, int *x, int width, int linesize)
Perform decode operation.
Definition: anm.c:76
SWS_LOOP
#define SWS_LOOP
Definition: ops_backend.h:57
SWS_OP_MIN
@ SWS_OP_MIN
Definition: ops.h:65
SWS_BLOCK_SIZE
#define SWS_BLOCK_SIZE
Copyright (C) 2025 Niklas Haas.
Definition: ops_backend.c:30
pixel_t
#define pixel_t
Definition: ops_tmpl_float.c:33
Y
#define Y
Definition: boxblur.h:37
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
ff_sws_setup_q4
int ff_sws_setup_q4(const SwsOp *op, SwsOpPriv *out)
Definition: ops_chain.c:278
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
SWS_OP_MAX
@ SWS_OP_MAX
Definition: ops.h:66
scale
static void scale(int *out, const int *in, const int w, const int h, const int shift)
Definition: intra.c:273
min
float min
Definition: vorbis_enc_data.h:429