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  /* Pointer bump, difference between stride and processed line size */
45  ptrdiff_t in_bump[4];
46  ptrdiff_t out_bump[4];
47 
48  /* Extra metadata, may or may not be useful */
49  int32_t width, height; /* Overall image dimensions */
50  int32_t slice_y, slice_h; /* Start and height of current slice */
51  int32_t block_size_in; /* Size of a block of pixels in bytes */
53 
54  /* Subsampling factors for each plane */
55  uint8_t in_sub_y[4], out_sub_y[4];
56  uint8_t in_sub_x[4], out_sub_x[4];
57 
58  /* Pointers back to the original SwsFrame */
61 } SwsOpExec;
62 
63 static_assert(sizeof(SwsOpExec) == 24 * sizeof(void *) +
64  6 * sizeof(int32_t) +
65  16 * sizeof(uint8_t) +
66  2 * sizeof(void *),
67  "SwsOpExec layout mismatch");
68 
69 /**
70  * Process a given range of pixel blocks.
71  *
72  * Note: `bx_start` and `bx_end` are in units of `SwsCompiledOp.block_size`.
73  */
74 typedef void (*SwsOpFunc)(const SwsOpExec *exec, const void *priv,
75  int bx_start, int y_start, int bx_end, int y_end);
76 
77 #define SWS_DECL_FUNC(NAME) \
78  void NAME(const SwsOpExec *, const void *, int, int, int, int)
79 
80 typedef struct SwsCompiledOp {
82 
83  int slice_align; /* slice height alignment */
84  int block_size; /* number of pixels processed per iteration */
85  int over_read; /* implementation over-reads input by this many bytes */
86  int over_write; /* implementation over-writes output by this many bytes */
87  int cpu_flags; /* active set of CPU flags (informative) */
88 
89  /* Arbitrary private data */
90  void *priv;
91  void (*free)(void *priv);
93 
94 #endif /* SWSCALE_OPS_DISPATCH_H */
SwsCompiledOp::func
SwsOpFunc func
Definition: ops_dispatch.h:81
SwsOpExec::in_bump
ptrdiff_t in_bump[4]
Definition: ops_dispatch.h:45
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
SwsOpExec::block_size_in
int32_t block_size_in
Definition: ops_dispatch.h:51
SwsCompiledOp::over_read
int over_read
Definition: ops_dispatch.h:85
SwsCompiledOp::cpu_flags
int cpu_flags
Definition: ops_dispatch.h:87
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:74
SwsFrame
Represents a view into a single field of frame data.
Definition: format.h:188
SwsCompiledOp::over_write
int over_write
Definition: ops_dispatch.h:86
SwsOpExec::out_frame
const SwsFrame * out_frame
Definition: ops_dispatch.h:60
SwsOpExec::height
int32_t height
Definition: ops_dispatch.h:49
SwsOpExec
Copyright (C) 2026 Niklas Haas.
Definition: ops_dispatch.h:35
SwsOpExec::slice_h
int32_t slice_h
Definition: ops_dispatch.h:50
SwsOpExec::block_size_out
int32_t block_size_out
Definition: ops_dispatch.h:52
SwsOpExec::in_sub_x
uint8_t in_sub_x[4]
Definition: ops_dispatch.h:56
frame.h
SwsOpExec::out
uint8_t * out[4]
Definition: ops_dispatch.h:38
graph.h
SwsOpExec::out_sub_y
uint8_t out_sub_y[4]
Definition: ops_dispatch.h:55
SwsOpExec::out_sub_x
uint8_t out_sub_x[4]
Definition: ops_dispatch.h:56
SwsOpExec::width
int32_t width
Definition: ops_dispatch.h:49
SwsCompiledOp::priv
void * priv
Definition: ops_dispatch.h:90
SwsCompiledOp::block_size
int block_size
Definition: ops_dispatch.h:84
SwsOpExec::in_frame
const SwsFrame * in_frame
Definition: ops_dispatch.h:59
SwsCompiledOp
Definition: ops_dispatch.h:80
SwsCompiledOp::slice_align
int slice_align
Definition: ops_dispatch.h:83
SwsOpExec::in_sub_y
uint8_t in_sub_y[4]
Definition: ops_dispatch.h:55
int32_t
int32_t
Definition: audioconvert.c:56
SwsOpExec::slice_y
int32_t slice_y
Definition: ops_dispatch.h:50
SwsOpExec::out_bump
ptrdiff_t out_bump[4]
Definition: ops_dispatch.h:46
SwsCompiledOp::free
void(* free)(void *priv)
Definition: ops_dispatch.h:91