31 if ((ret = (x)) < 0) \
46 for (
int i = 0;
i < 4;
i++)
60 for (
int i = 0;
i < 4;
i++)
65 for (
int i = 0;
i < 4;
i++)
129 for (
int i = 0;
i < 4;
i++) {
132 const int j =
op->swizzle.in[
i];
143 for (
int i = 0;
i < 4;
i++) {
146 const int j =
op->swizzle.in[
i];
190 for (
int i = 0;
i < 4;
i++)
224 return (1 << p) == x ? p : 0;
251 for (
int i = 0;
i < 4;
i++) {
260 if (
scale.factor.den)
262 return scale.factor.den;
273 for (
int i = 0;
i < 4;
i++) {
274 bool const_row =
c->m[
i][4].den == 1;
275 for (
int j = 0; j < 4; j++) {
276 const_row &=
c->m[
i][j].num == 0 ||
283 for (
int j = 0; j < 5; j++)
284 c->m[
i][j] =
Q(
i == j);
303 uint32_t nonzero = 0;
304 for (
int i = 0;
i < 4;
i++) {
305 for (
int j = 0; j < 4; j++) {
314 for (
int i = 0;
i < 4;
i++) {
317 for (
int j = 0; j < 4; j++) {
320 c.m[
i][
i] =
c.m[
i][j];
338 for (
int i = 0;
i < 4;
i++) {
355 for (
int n = 1; n < ops->
num_ops; n++) {
372 if (size_from < size_to) {
382 for (
int n = 0; n < ops->
num_ops; n++) {
404 for (
int i = 0;
i <
op->rw.elems;
i++) {
406 swiz.
in[
i] = 3 - (
i - nb_planes);
410 const int idx = nb_planes++;
416 if (nb_planes < op->rw.elems) {
417 op->rw.elems = nb_planes;
451 if (next->
op ==
op->op) {
458 if (!
op->shift.amount) {
465 for (
int i = 0;
i < 4;
i++) {
471 op->clear.value[
i].num == 0)
490 for (
int i = 0;
i < 4;
i++) {
503 for (
int j = 0; j < 4; j++) {
508 for (
int i = 0;
i < 4;
i++) {
524 for (
int i = 0;
i < 4;
i++) {
527 if (
op->swizzle.in[
i] !=
i)
540 for (
int i = 0;
i < 4;
i++)
549 const int src =
op->swizzle.in[
dst];
552 for (
int i =
dst;
i < 4;
i++) {
553 if (
op->swizzle.in[
i] ==
dst)
555 else if (
op->swizzle.in[
i] ==
src)
565 const int src =
op->swizzle.in[
dst];
591 for (
int i = 0;
i < 4;
i++) {
607 for (
int i = 0;
i < 4;
i++) {
623 for (
int i = 0;
i < 4;
i++) {
624 if (
op->dither.y_offset[
i] < 0)
627 op->dither.y_offset[
i] = -1;
656 for (
int i = 0;
i < 4;
i++) {
658 for (
int j = 0; j < 5; j++) {
660 for (
int k = 0; k < 4; k++)
664 op->lin.m[
i][j] = sum;
672 for (
int j = 0; j < 4; j++) {
676 for (
int i = 0;
i < 4;
i++)
677 op->lin.m[
i][j] =
Q(
i == j);
682 for (
int i = 0;
i < 4;
i++) {
686 for (
int j = 0; j < 5; j++)
687 op->lin.m[
i][j] =
Q(
i == j);
722 if (
op->scale.factor.num == 1 &&
op->scale.factor.den == 1) {
737 op->shift.amount =
FFABS(factor2);
767 for (
int n = 0; n < ops->
num_ops - 1; n++) {
784 for (
int n = 0; n < ops->
num_ops - 1; n++) {
815 for (
int i = 0;
i < 4;
i++)
845 .op = SWS_OP_SWIZZLE,
866 if (!mask1 || !mask2) {
900 for (
int n = 0; n < num_groups; n++) {
905 shuffle[base_out +
i] = idx + (idx >= 0) * base_in;
916 case 2:
return val.u16 ==
val.u8 * 0x101ul;
917 case 4:
return val.u32 ==
val.u8 * 0x1010101ul;
942 uint32_t
mask[4] = {0};
945 for (
int i = 0;
i < 4;
i++) {
947 mask[
i] = 0x01010101 *
i * read_size + 0x03020100;
952 for (
int opidx = 1; opidx < uops->
num_ops; opidx++) {
960 const int dst_idx = par->
move.
dst[
i];
961 const int src_idx = par->
move.
src[
i];
962 uint32_t *
src = src_idx < 0 ? &
tmp : &
mask[src_idx];
963 uint32_t *
dst = dst_idx < 0 ? &
tmp : &
mask[dst_idx];
970 for (
int i = 0;
i < 4;
i++) {
979 for (
int i = 0;
i < 4;
i++) {
984 (clear_val >= 0 && clear_val !=
val.u8))
986 mask[
i] = 0xFFFFFFFFul;
993 for (
int i = 0;
i < 4;
i++)
1013 .read_size = read_elems * read_size,
1014 .write_size = write_elems * write_size,
1015 .clear_value = clear_val >= 0 ? clear_val : 0,
1020 for (
int i = 0;
i < write_elems;
i++) {
1021 const int offset =
i * write_size;
1022 for (
int b = 0;
b < write_size;
b++)
1035 data->pixels = num_groups;
1057 default:
return false;
1092 memset(&
op->par, 0,
sizeof(
op->par));
1127 switch (nb_planes) {
1135 switch (nb_planes) {
1143 switch (nb_planes) {
1163 fmt->
height =
read->rw.filter.kernel->dst_size;
1165 fmt->
width =
read->rw.filter.kernel->dst_size;
1192 for (
int i = 0;
i < 4;
i++) {
1194 const int o = nb_planes++;
1209 for (
int i = 0;
i < nb_planes;
i++) {
1210 const int idx = swiz_wr.
in[
i];
1233 .rw.elems = nb_planes,
1241 .rw.elems = nb_planes,
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
static double val(void *priv, double ch)
static const AVFilterPad inputs[]
static const AVFilterPad outputs[]
static AVFormatContext * ctx
simple assert() macros that are a bit more flexible than ISO C assert().
#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.
#define av_unreachable(msg)
Asserts that are used as compiler optimization hints depending upon ASSERT_LEVEL and NBDEBUG.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
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.
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
static uint64_t shuffle(uint64_t in, const uint8_t *shuffle, int shuffle_len)
static const uint8_t bits[8]
AVRational64 ff_mul_q64(AVRational64 b, AVRational64 c)
Multiply two 64-bit rationals.
AVRational64 ff_add_q64(AVRational64 b, AVRational64 c)
Add two 64-bit rationals.
int ff_cmp_q64(AVRational64 a, AVRational64 b)
Compare two 64-bit rationals.
static av_always_inline void scale(vec_s32 res[4], vec_s16 res_packed[2], const int shift)
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.
Macro definitions for various function/variable attributes.
static const struct @257111027162314367033347246032313251342043035002 planes[]
static const uint16_t mask[17]
#define FFSWAP(type, a, b)
uint32_t ff_sws_linear_mask(const SwsLinearOp *c)
int ff_sws_op_list_insert_at(SwsOpList *ops, int index, SwsOp *op)
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.
void ff_sws_op_list_free(SwsOpList **p_ops)
void ff_sws_op_list_update(SwsOpList *ops)
Infer + propagate known information about components.
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.
void ff_sws_comp_mask_swizzle(SwsCompMask *mask, const SwsSwizzleOp *swiz)
SwsPixelType ff_sws_op_input_type(const SwsOp *op)
Return the input/output type of an operation, if all inputs/outputs are the same type,...
SwsCompMask ff_sws_comp_mask_needed(const SwsOp *op)
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.
void ff_sws_apply_op_q(const SwsOp *op, AVRational64 x[4])
Apply an operation to an AVRational64.
void ff_sws_op_list_remove_at(SwsOpList *ops, int index, int count)
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...
#define SWS_SWIZZLE(X, Y, Z, W)
#define SWS_OP_NEEDED(op, idx)
static bool pixel_is_repeating(SwsPixelType type, SwsPixel val)
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 int exact_log2(const int x)
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 ...
static int solve_shuffle(const SwsUOpList *const uops, SwsUOp *out)
int ff_sws_op_list_optimize(SwsOpList *ops)
Fuse compatible and eliminate redundant operations, as well as replacing some operations with more ef...
#define RET(x)
Copyright (C) 2025 Niklas Haas.
static bool op_commute_filter(SwsOp *op, SwsOp *prev)
Try to commute a filter op with the previous operation.
static bool op_commute_clear(SwsOp *op, SwsOp *next)
Try to commute a clear op with the next operation.
static bool is_scale(const SwsUOp *op, int64_t val)
int ff_sws_uop_list_optimize(SwsContext *ctx, SwsUOpFlags flags, SwsUOpList *uops)
Called internally by ff_sws_ops_translate().
static void get_input_size(const SwsOpList *ops, SwsFormat *fmt)
static int exact_log2_q64(const AVRational64 x)
int ff_sws_op_list_split_at(SwsOpList *ops1, SwsOpList **out_ops2, int index)
Split an op list into two at the given index.
static int select_planes(SwsOpList *ops, SwsCompMask planes)
static bool extract_swizzle(SwsLinearOp *op, const SwsOpPad inputs[4], SwsSwizzleOp *out_swiz)
static bool extract_scalar(const SwsLinearOp *c, const SwsOpPad outputs[4], const SwsOpPad inputs[4], 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 SwsOpPad inputs[4], SwsClearOp *out_clear)
static int op_result_is_exact(const SwsOp *op)
static bool op_commute_swizzle(SwsOp *op, SwsOp *next)
Try to commute a swizzle op with the next operation.
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...
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_GBRPF32
#define AV_PIX_FMT_GRAYF32
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
#define AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_GBRAPF32
#define AV_PIX_FMT_YUV444P16
Utilities for rational number calculation.
void * av_refstruct_ref(void *obj)
Create a new reference to an object managed via this API, i.e.
#define FF_ARRAY_ELEMS(a)
64-bit Rational number (pair of numerator and denominator).
Main external API structure.
SwsPixelType type[4]
Pixel type per output component.
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 ...
int8_t src[SWS_UOP_MOVE_MAX]
int8_t dst[SWS_UOP_MOVE_MAX]
Helper struct for representing a list of operations.
SwsOpPad inputs[4]
Source component metadata associated with pixel values from each corresponding component (in plane/me...
SwsOpPad outputs[4]
Metadata about the operation's input/output components.
uint8_t pattern[4]
Packed bits are assumed to be LSB-aligned within the underlying integer type; i.e.
SwsFilterWeights * kernel
SwsPixelType type
Examples: rgba = 4x u8 packed yuv444p = 3x u8 rgb565 = 1x u16 <- use SWS_OP_UNPACK to unpack monow = ...
struct SwsReadWriteOp::@312356277033155231251141106170064356360153154105 filter
Filter kernel to apply to each plane while sampling.
union SwsUOp::@242237116251216327057105100216205033300341206345 data
int ff_sws_uop_list_append(SwsUOpList *uops, SwsUOp *uop)
void ff_sws_uop_list_remove_at(SwsUOpList *uops, int index, int count)
#define SWS_COMP_TEST(mask, X)
#define SWS_COMP_ELEMS(N)
@ SWS_UOP_FLAG_EXPAND_BIT
static av_const bool ff_sws_pixel_type_is_int(SwsPixelType type)
uint8_t SwsCompMask
Bit-mask of components.
static av_const int ff_sws_pixel_type_size(SwsPixelType type)