Go to the documentation of this file.
31 if ((ret = (x)) < 0) \
126 for (
int i = 0;
i < 4;
i++) {
129 const int j =
op->swizzle.in[
i];
140 for (
int i = 0;
i < 4;
i++) {
143 const int j =
op->swizzle.in[
i];
185 prev->
type =
op->filter.type;
217 return (1 <<
p) == x ?
p : 0;
244 for (
int i = 0;
i < 4;
i++) {
254 if (
scale.factor.den)
256 return scale.factor.den;
266 for (
int i = 0;
i < 4;
i++) {
267 bool const_row =
c->m[
i][4].den == 1;
268 for (
int j = 0; j < 4; j++) {
269 const_row &=
c->m[
i][j].num == 0 ||
275 for (
int j = 0; j < 5; j++)
276 c->m[
i][j] =
Q(
i == j);
296 uint32_t nonzero = 0;
297 for (
int i = 0;
i < 4;
i++) {
298 for (
int j = 0; j < 4; j++) {
307 for (
int i = 0;
i < 4;
i++) {
310 for (
int j = 0; j < 4; j++) {
313 c.m[
i][
i] =
c.m[
i][j];
332 for (
int i = 0;
i < 4;
i++) {
349 for (
int n = 1; n < ops->
num_ops; n++) {
366 if (size_from < size_to) {
377 for (
int n = 0; n < ops->
num_ops; n++) {
399 for (
int i = 0;
i <
op->rw.elems;
i++) {
401 swiz.
in[
i] = 3 - (
i - nb_planes);
405 const int idx = nb_planes++;
411 if (nb_planes < op->rw.elems) {
412 op->rw.elems = nb_planes;
415 .type =
op->rw.filter.op ?
op->rw.filter.type :
op->type,
447 if (next->
op ==
op->op) {
454 if (!
op->shift.amount) {
461 for (
int i = 0;
i < 4;
i++) {
467 op->clear.value[
i].num == 0)
486 for (
int i = 0;
i < 4;
i++) {
497 for (
int i = 0;
i < 4;
i++) {
500 if (
op->swizzle.in[
i] !=
i)
513 for (
int i = 0;
i < 4;
i++)
522 const int src =
op->swizzle.in[
dst];
523 if (
src >
dst && src < prev->rw.elems) {
525 for (
int i =
dst;
i < 4;
i++) {
526 if (
op->swizzle.in[
i] ==
dst)
528 else if (
op->swizzle.in[
i] ==
src)
538 const int src =
op->swizzle.in[
dst];
539 if (
src >
dst && src < next->rw.elems) {
550 if (
op->type ==
op->convert.to) {
572 op->convert.expand =
true;
579 for (
int i = 0;
i < 4;
i++) {
593 for (
int i = 0;
i < 4;
i++) {
607 for (
int i = 0;
i < 4;
i++) {
608 if (
op->dither.y_offset[
i] < 0)
611 op->dither.y_offset[
i] = -1;
639 for (
int i = 0;
i < 4;
i++) {
640 for (
int j = 0; j < 5; j++) {
642 for (
int k = 0; k < 4; k++)
646 op->lin.m[
i][j] = sum;
655 for (
int j = 0; j < 4; j++) {
659 for (
int i = 0;
i < 4;
i++)
660 op->lin.m[
i][j] =
Q(
i == j);
661 op->lin.mask &= ~col;
666 for (
int i = 0;
i < 4;
i++) {
670 for (
int j = 0; j < 5; j++)
671 op->lin.m[
i][j] =
Q(
i == j);
672 op->lin.mask &= ~row;
710 if (
op->scale.factor.num == 1 &&
op->scale.factor.den == 1) {
725 op->shift.amount =
FFABS(factor2);
747 for (
int n = 0; n < ops->
num_ops - 1; n++) {
764 for (
int n = 0; n < ops->
num_ops - 1; n++) {
813 .op = SWS_OP_SWIZZLE,
835 if (!mask1 || !mask2) {
869 for (
int n = 0; n < num_groups; n++) {
874 shuffle[base_out +
i] = idx + (idx >= 0) * base_in;
885 case 2:
return val.u16 ==
val.u8 * 0x101ul;
886 case 4:
return val.u32 ==
val.u8 * 0x1010101ul;
911 uint32_t
mask[4] = {0};
914 for (
int i = 0;
i < 4;
i++) {
916 mask[
i] = 0x01010101 *
i * read_size + 0x03020100;
921 for (
int opidx = 1; opidx < uops->
num_ops; opidx++) {
929 const int dst_idx = par->
move.
dst[
i];
930 const int src_idx = par->
move.
src[
i];
931 uint32_t *
src = src_idx < 0 ? &
tmp : &
mask[src_idx];
932 uint32_t *
dst = dst_idx < 0 ? &
tmp : &
mask[dst_idx];
939 for (
int i = 0;
i < 4;
i++) {
948 for (
int i = 0;
i < 4;
i++) {
953 (clear_val >= 0 && clear_val !=
val.u8))
955 mask[
i] = 0xFFFFFFFFul;
962 for (
int i = 0;
i < 4;
i++)
983 .write_size = write_elems * write_size,
984 .clear_value = clear_val >= 0 ? clear_val : 0,
989 for (
int i = 0;
i < write_elems;
i++) {
990 const int offset =
i * write_size;
991 for (
int b = 0;
b < write_size;
b++)
1004 data->pixels = num_groups;
1059 switch (nb_planes) {
1067 switch (nb_planes) {
1075 switch (nb_planes) {
1095 fmt->
height =
read->rw.filter.kernel->dst_size;
1097 fmt->
width =
read->rw.filter.kernel->dst_size;
1104 if (index <= 0 || index >= ops1->
num_ops) {
1124 for (
int i = 0;
i < 4;
i++) {
1126 const int o = nb_planes++;
1139 for (
int i = 0;
i < nb_planes;
i++) {
1140 const int idx = swiz_wr.
in[
i];
1164 .rw.elems = nb_planes,
1172 .rw.elems = nb_planes,
void ff_sws_op_list_free(SwsOpList **p_ops)
static int select_planes(SwsOpList *ops, SwsCompMask planes)
AVPixelFormat
Pixel format.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
SwsOpList * ff_sws_op_list_duplicate(const SwsOpList *ops)
Returns a duplicate of ops, or NULL on OOM.
@ SWS_RW_PLANAR
Note: 1-component reads are either SWS_RW_PLANAR or SWS_RW_PACKED, depending on the underlying interp...
static bool extract_scalar(const SwsLinearOp *c, const SwsComps *comps, const SwsComps *prev, SwsScaleOp *out_scale)
If a linear operation can be reduced to a scalar multiplication, returns the corresponding scaling fa...
static bool extract_constant_rows(SwsLinearOp *c, const SwsComps *prev, SwsClearOp *out_clear)
SwsComps comps_src
Source component metadata associated with pixel values from each corresponding component (in plane/me...
const SwsOp * ff_sws_op_list_input(const SwsOpList *ops)
Returns the input operation for a given op list, or NULL if there is none (e.g.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
int ff_sws_op_list_append(SwsOpList *ops, SwsOp *op)
These will take over ownership of op and set it to {0}, even on failure.
static av_const bool ff_sws_pixel_type_is_int(SwsPixelType type)
static void get_input_size(const SwsOpList *ops, SwsFormat *fmt)
static int exact_log2_q64(const AVRational64 x)
int ff_sws_op_list_optimize(SwsOpList *ops)
Fuse compatible and eliminate redundant operations, as well as replacing some operations with more ef...
static int solve_shuffle(const SwsUOpList *const uops, SwsUOp *out)
SwsCompMask ff_sws_comp_mask_needed(const SwsOp *op)
int ff_sws_shuffle_mask(const SwsUOp *uop, int8_t shuffle[], int size)
Compute a shuffle mask for pshufb-style ASM functions, by repeating the shuffle pattern for as many g...
#define SWS_COMP_TEST(mask, X)
#define AV_PIX_FMT_YUVA444P16
static double val(void *priv, double ch)
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
#define AV_PIX_FMT_GRAY16
int ff_sws_op_list_split_at(SwsOpList *ops1, SwsOpList **out_ops2, int index)
Split an op list into two at the given index.
#define SWS_COMP_ELEMS(N)
#define FF_ARRAY_ELEMS(a)
#define SWS_OP_NEEDED(op, idx)
struct SwsReadWriteOp::@581 filter
Filter kernel to apply to each plane while sampling.
#define flags(name, subs,...)
static const struct @604 planes[]
#define AV_PIX_FMT_YUV444P16
#define SWS_SWIZZLE(X, Y, Z, W)
static AVRational64 ff_sws_pixel_expand(SwsPixelType from, SwsPixelType to)
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.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int av_cmp_q64(AVRational64 a, AVRational64 b)
Compare two 64-bit rationals.
static bool extract_swizzle(SwsLinearOp *op, const SwsComps *prev, SwsSwizzleOp *out_swiz)
static AVFormatContext * ctx
uint8_t SwsCompMask
Bit-mask of components.
static bool op_commute_filter(SwsOp *op, SwsOp *prev)
Try to commute a filter op with the previous operation.
const SwsOp * ff_sws_op_list_output(const SwsOpList *ops)
Returns the output operation for a given op list, or NULL if there is none.
AVRational64 av_mul_q64(AVRational64 b, AVRational64 c)
Multiply two 64-bit rationals.
#define AV_PIX_FMT_GRAYF32
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
static av_const int ff_sws_pixel_type_size(SwsPixelType type)
SwsFilterWeights * kernel
#define av_unreachable(msg)
Asserts that are used as compiler optimization hints depending upon ASSERT_LEVEL and NBDEBUG.
int8_t dst[SWS_UOP_MOVE_MAX]
void ff_sws_op_list_remove_at(SwsOpList *ops, int index, int count)
#define RET(x)
Copyright (C) 2025 Niklas Haas.
void ff_sws_apply_op_q(const SwsOp *op, AVRational64 x[4])
Apply an operation to an AVRational64.
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
void ff_sws_uop_list_remove_at(SwsUOpList *uops, int index, int count)
uint8_t pattern[4]
Packed bits are assumed to be LSB-aligned within the underlying integer type; i.e.
void ff_sws_comp_mask_swizzle(SwsCompMask *mask, const SwsSwizzleOp *swiz)
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
#define i(width, name, range_min, range_max)
#define AV_PIX_FMT_GBRPF32
int ff_sws_op_list_insert_at(SwsOpList *ops, int index, SwsOp *op)
uint32_t ff_sws_linear_mask(const SwsLinearOp *c)
void ff_sws_op_list_update_comps(SwsOpList *ops)
Infer + propagate known information about components.
64-bit Rational number (pair of numerator and denominator).
void * av_refstruct_ref(void *obj)
Create a new reference to an object managed via this API, i.e.
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
SwsComps comps
Metadata about the operation's input/output components.
static enum AVPixelFormat get_planar_fmt(SwsPixelType type, int nb_planes)
Determine a suitable intermediate buffer format for a given combination of pixel types and number of ...
int ff_sws_uop_list_optimize(SwsContext *ctx, SwsUOpFlags flags, SwsUOpList *uops)
Called internally by ff_sws_ops_translate().
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is needed
#define FFSWAP(type, a, b)
static bool op_commute_swizzle(SwsOp *op, SwsOp *next)
Try to commute a swizzle op with the next operation.
#define AV_PIX_FMT_GBRAPF32
static bool pixel_is_repeating(SwsPixelType type, SwsPixel val)
static int op_result_is_exact(const SwsOp *op)
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
int ff_sws_uop_list_append(SwsUOpList *uops, SwsUOp *uop)
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
static void scale(int *out, const int *in, const int w, const int h, const int shift)
int8_t src[SWS_UOP_MOVE_MAX]
static bool op_commute_clear(SwsOp *op, SwsOp *next)
Try to commute a clear op with the next operation.
SwsReadWriteMode mode
Examples: rgba = 4x u8 packed yuv444p = 3x u8 rgb565 = 1x u16 <- use SWS_OP_UNPACK to unpack monow = ...
Helper struct for representing a list of operations.
Main external API structure.
static uint64_t shuffle(uint64_t in, const uint8_t *shuffle, int shuffle_len)
int ff_sws_op_list_split_planes(SwsOpList *ops1, SwsOpList **out_ops2, SwsCompMask planes)
Reduce an op list into a reduced subset that operates only on a given subset of planes.
static uint32_t BS_FUNC() read(BSCTX *bc, unsigned int n)
Return n bits from the buffer, n has to be in the 0-32 range.
static int exact_log2(const int x)
AVRational64 m[4][5]
Generalized 5x5 affine transformation: [ Out.x ] = [ A B C D E ] [ Out.y ] = [ F G H I J ] * [ x y z ...
AVRational64 av_add_q64(AVRational64 b, AVRational64 c)
Add two 64-bit rationals.