FFmpeg
ops_internal.h
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 #ifndef SWSCALE_OPS_INTERNAL_H
22 #define SWSCALE_OPS_INTERNAL_H
23 
24 #include "libavutil/mem_internal.h"
25 
26 #include "ops.h"
27 #include "ops_dispatch.h"
28 
29 #define Q(N) ((AVRational) { N, 1 })
30 
32 {
33  const int src = ff_sws_pixel_type_size(from);
34  const int dst = ff_sws_pixel_type_size(to);
35  if (src > dst)
36  return Q(0);
37  int scale = 1;
38  for (int i = 1; i < dst / src; i++)
39  scale = (scale << (src * 8)) | 1;
40  return Q(scale);
41 }
42 
43 static inline void ff_sws_pack_op_decode(const SwsOp *op, uint64_t mask[4], int shift[4])
44 {
45  int size = 0;
46  for (int i = 0; i < 4; i++)
47  size += op->pack.pattern[i];
48  for (int i = 0; i < 4; i++) {
49  const int bits = op->pack.pattern[i];
50  mask[i] = (UINT64_C(1) << bits) - 1;
51  shift[i] = (i ? shift[i - 1] : size) - bits;
52  }
53 }
54 
55 /**
56  * "Solve" an op list into a fixed shuffle mask, with an optional ability to
57  * also directly clear the output value (for e.g. rgb24 -> rgb0). This can
58  * accept any operation chain that only consists of the following operations:
59  *
60  * - SWS_OP_READ (non-planar, non-fractional)
61  * - SWS_OP_SWIZZLE
62  * - SWS_OP_SWAP_BYTES
63  * - SWS_OP_CLEAR to zero (when clear_val is specified)
64  * - SWS_OP_CONVERT (integer expand)
65  * - SWS_OP_WRITE (non-planar, non-fractional)
66  *
67  * Basically, any operation that purely consists of moving around and reordering
68  * bytes within a single plane, can be turned into a shuffle mask.
69  *
70  * @param ops The operation list to decompose.
71  * @param shuffle The output shuffle mask.
72  * @param size The size (in bytes) of the output shuffle mask.
73  * @param clear_val If nonzero, this index will be used to clear the output.
74  * @param read_bytes Returns the number of bytes read per shuffle iteration.
75  * @param write_bytes Returns the number of bytes written per shuffle iteration.
76  *
77  * @return The number of pixels processed per iteration, or a negative error
78  code; in particular AVERROR(ENOTSUP) for unsupported operations.
79  */
80 int ff_sws_solve_shuffle(const SwsOpList *ops, uint8_t shuffle[], int size,
81  uint8_t clear_val, int *read_bytes, int *write_bytes);
82 
83 /**
84  * Eliminate SWS_OP_FILTER_* operations by merging them with prior SWS_OP_READ
85  * operations. This may require splitting the op list into multiple subpasses,
86  * along filter boundaries. After this function, `ops` will no longer contain
87  * bare filtering operations. The remainder, if any, is output to `out_rest`.
88  *
89  * Returns 0 or a negative error code.
90  */
91 int ff_sws_op_list_subpass(SwsOpList *ops, SwsOpList **out_rest);
92 
93 #endif /* SWSCALE_OPS_INTERNAL_H */
mem_internal.h
mask
int mask
Definition: mediacodecdec_common.c:154
ops.h
read_bytes
static void read_bytes(const uint8_t *src, float *dst, int src_stride, int dst_stride, int width, int height, float scale)
Definition: vf_nnedi.c:442
Q
#define Q(N)
Copyright (C) 2025 Niklas Haas.
Definition: ops_internal.h:29
ops_dispatch.h
ff_sws_pixel_type_size
int ff_sws_pixel_type_size(SwsPixelType type)
Definition: ops.c:77
SwsPixelType
SwsPixelType
Copyright (C) 2025 Niklas Haas.
Definition: ops.h:33
ff_sws_op_list_subpass
int ff_sws_op_list_subpass(SwsOpList *ops, SwsOpList **out_rest)
Eliminate SWS_OP_FILTER_* operations by merging them with prior SWS_OP_READ operations.
Definition: ops_optimizer.c:948
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
bits
uint8_t bits
Definition: vp3data.h:128
from
const char * from
Definition: jacosubdec.c:64
ff_sws_pixel_expand
static AVRational ff_sws_pixel_expand(SwsPixelType from, SwsPixelType to)
Definition: ops_internal.h:31
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
to
const char * to
Definition: webvttdec.c:35
shift
static int shift(int a, int b)
Definition: bonk.c:261
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:87
i
#define i(width, name, range_min, range_max)
Definition: cbs_h264.c:63
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:424
size
int size
Definition: twinvq_data.h:10344
SwsOp
Definition: ops.h:238
write_bytes
static void write_bytes(const float *src, uint8_t *dst, int src_stride, int dst_stride, int width, int height, int depth, float scale)
Definition: vf_nnedi.c:484
ff_sws_solve_shuffle
int ff_sws_solve_shuffle(const SwsOpList *ops, uint8_t shuffle[], int size, uint8_t clear_val, int *read_bytes, int *write_bytes)
"Solve" an op list into a fixed shuffle mask, with an optional ability to also directly clear the out...
Definition: ops_optimizer.c:798
scale
static void scale(int *out, const int *in, const int w, const int h, const int shift)
Definition: intra.c:278
ff_sws_pack_op_decode
static void ff_sws_pack_op_decode(const SwsOp *op, uint64_t mask[4], int shift[4])
Definition: ops_internal.h:43
SwsOpList
Helper struct for representing a list of operations.
Definition: ops.h:288
shuffle
static uint64_t shuffle(uint64_t in, const uint8_t *shuffle, int shuffle_len)
Definition: des.c:179
src
#define src
Definition: vp8dsp.c:248