FFmpeg
ops_dispatch.h
Go to the documentation of this file.
1 /**
2  * Copyright (C) 2026 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_DISPATCH_H
22 #define SWSCALE_OPS_DISPATCH_H
23 
24 #include <assert.h>
25 
26 #include "libavutil/frame.h"
27 #include "graph.h"
28 
29 /**
30  * Global execution context for all compiled functions.
31  *
32  * Note: This struct is hard-coded in assembly, so do not change the layout
33  * without updating the corresponding assembly definitions.
34  */
35 typedef struct SwsOpExec {
36  /* The data pointers point to the first pixel to process */
37  const uint8_t *in[4];
38  uint8_t *out[4];
39 
40  /* Separation between lines in bytes */
41  ptrdiff_t in_stride[4];
42  ptrdiff_t out_stride[4];
43 
44  /**
45  * Pointer bump, difference between stride and processed line size.
46  *
47  * Assumes that each read kernel increments pointers by the processed
48  * block size, except when using horizontal filtering, in which case
49  * this is always equal to the input stride.
50  */
51  ptrdiff_t in_bump[4];
52  ptrdiff_t out_bump[4];
53 
54  /* Extra metadata, may or may not be useful */
55  int32_t width, height; /* Overall output image dimensions */
56  int32_t slice_y, slice_h; /* Start and height of current slice */
57  int32_t block_size_in; /* Size of a block of pixels in bytes */
59 
60  /* Subsampling factors for each plane */
61  uint8_t in_sub_y[4], out_sub_y[4];
62  uint8_t in_sub_x[4], out_sub_x[4];
63 
64  /**
65  * Line bump; determines how many additional lines to advance (after
66  * incrementing normally to the next line), for each filtered output line.
67  *
68  * Indexed by the line's true y coordinate. If NULL, then the bumps are
69  * effectively all zero. Note that these bumps still need to be
70  * multiplied by the corresponding line stride.
71  */
73 
74  /**
75  * Pixel offset map; for horizontal scaling, in bytes. Indexed by the x
76  * coordinate of the output pixel. This is always aligned up to a multiple
77  * of the block size, so implementations may safely over-read up to the
78  * next block boundary.
79  */
81 } SwsOpExec;
82 
83 static_assert(sizeof(SwsOpExec) == 24 * sizeof(void *) +
84  6 * sizeof(int32_t) +
85  16 * sizeof(uint8_t) +
86  2 * sizeof(void *),
87  "SwsOpExec layout mismatch");
88 
89 /**
90  * Process a given range of pixel blocks.
91  *
92  * Note: `bx_start` and `bx_end` are in units of `SwsCompiledOp.block_size`.
93  */
94 typedef void (*SwsOpFunc)(const SwsOpExec *exec, const void *priv,
95  int bx_start, int y_start, int bx_end, int y_end);
96 
97 #define SWS_DECL_FUNC(NAME) \
98  void NAME(const SwsOpExec *, const void *, int, int, int, int)
99 
100 typedef struct SwsCompiledOp {
101  /* Function to execute */
102  union {
105  };
106 
107  /**
108  * If `opaque` is true, then `func_opaque`, `priv` and `free` are directly
109  * forwarded as `SwsPass.run`, `SwsPass.priv` and `SwsPass.free`
110  * respectively.
111  */
112  bool opaque;
113 
114  /* Execution parameters for all functions */
115  int slice_align; /* slice height alignment */
116  int cpu_flags; /* active set of CPU flags (informative) */
117 
118  /* Execution parameters for non-opaque functions only */
119  int block_size; /* number of pixels processed per iteration */
120  int over_read; /* implementation over-reads input by this many bytes */
121  int over_write; /* implementation over-writes output by this many bytes */
122 
123  /* Arbitrary private data */
124  void *priv;
125  void (*free)(void *priv);
126 } SwsCompiledOp;
127 
129 
130 #endif /* SWSCALE_OPS_DISPATCH_H */
SwsCompiledOp::func
SwsOpFunc func
Definition: ops_dispatch.h:103
comp
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
Definition: eamad.c:79
SwsOpExec::in_bump
ptrdiff_t in_bump[4]
Pointer bump, difference between stride and processed line size.
Definition: ops_dispatch.h:51
SwsOpExec::out_stride
ptrdiff_t out_stride[4]
Definition: ops_dispatch.h:42
SwsOpExec::in
const uint8_t * in[4]
Definition: ops_dispatch.h:37
SwsCompiledOp::opaque
bool opaque
If opaque is true, then func_opaque, priv and free are directly forwarded as SwsPass....
Definition: ops_dispatch.h:112
SwsOpExec::block_size_in
int32_t block_size_in
Definition: ops_dispatch.h:57
SwsCompiledOp::over_read
int over_read
Definition: ops_dispatch.h:120
SwsCompiledOp::cpu_flags
int cpu_flags
Definition: ops_dispatch.h:116
SwsOpExec::in_stride
ptrdiff_t in_stride[4]
Definition: ops_dispatch.h:41
SwsOpFunc
void(* SwsOpFunc)(const SwsOpExec *exec, const void *priv, int bx_start, int y_start, int bx_end, int y_end)
Process a given range of pixel blocks.
Definition: ops_dispatch.h:94
SwsCompiledOp::func_opaque
SwsPassFunc func_opaque
Definition: ops_dispatch.h:104
SwsCompiledOp::over_write
int over_write
Definition: ops_dispatch.h:121
SwsOpExec::in_bump_y
int32_t * in_bump_y
Line bump; determines how many additional lines to advance (after incrementing normally to the next l...
Definition: ops_dispatch.h:72
SwsOpExec::height
int32_t height
Definition: ops_dispatch.h:55
SwsOpExec
Copyright (C) 2026 Niklas Haas.
Definition: ops_dispatch.h:35
SwsOpExec::slice_h
int32_t slice_h
Definition: ops_dispatch.h:56
SwsOpExec::block_size_out
int32_t block_size_out
Definition: ops_dispatch.h:58
SwsOpExec::in_sub_x
uint8_t in_sub_x[4]
Definition: ops_dispatch.h:62
ff_sws_compiled_op_unref
void ff_sws_compiled_op_unref(SwsCompiledOp *comp)
Definition: ops_dispatch.c:104
frame.h
SwsOpExec::out
uint8_t * out[4]
Definition: ops_dispatch.h:38
SwsOpExec::in_offset_x
int32_t * in_offset_x
Pixel offset map; for horizontal scaling, in bytes.
Definition: ops_dispatch.h:80
graph.h
SwsOpExec::out_sub_y
uint8_t out_sub_y[4]
Definition: ops_dispatch.h:61
SwsOpExec::out_sub_x
uint8_t out_sub_x[4]
Definition: ops_dispatch.h:62
SwsOpExec::width
int32_t width
Definition: ops_dispatch.h:55
SwsCompiledOp::priv
void * priv
Definition: ops_dispatch.h:124
SwsCompiledOp::block_size
int block_size
Definition: ops_dispatch.h:119
SwsPassFunc
void(* SwsPassFunc)(const SwsFrame *out, const SwsFrame *in, int y, int h, const SwsPass *pass)
Output h lines of filtered data.
Definition: graph.h:45
SwsCompiledOp
Definition: ops_dispatch.h:100
SwsCompiledOp::slice_align
int slice_align
Definition: ops_dispatch.h:115
SwsOpExec::in_sub_y
uint8_t in_sub_y[4]
Definition: ops_dispatch.h:61
int32_t
int32_t
Definition: audioconvert.c:56
SwsOpExec::slice_y
int32_t slice_y
Definition: ops_dispatch.h:56
SwsOpExec::out_bump
ptrdiff_t out_bump[4]
Definition: ops_dispatch.h:52
SwsCompiledOp::free
void(* free)(void *priv)
Definition: ops_dispatch.h:125