31 if ((ret = (x)) < 0) \
127 for (
int i = 0;
i < 4;
i++) {
130 const int j =
op->swizzle.in[
i];
141 for (
int i = 0;
i < 4;
i++) {
144 const int j =
op->swizzle.in[
i];
187 prev->
type =
op->filter.type;
220 return (1 << p) == x ? p : 0;
247 for (
int i = 0;
i < 4;
i++) {
257 if (
scale.factor.den)
259 return scale.factor.den;
270 for (
int i = 0;
i < 4;
i++) {
271 bool const_row =
c->m[
i][4].den == 1;
272 for (
int j = 0; j < 4; j++) {
273 const_row &=
c->m[
i][j].num == 0 ||
279 for (
int j = 0; j < 5; j++)
280 c->m[
i][j] =
Q(
i == j);
299 uint32_t nonzero = 0;
300 for (
int i = 0;
i < 4;
i++) {
301 for (
int j = 0; j < 4; j++) {
310 for (
int i = 0;
i < 4;
i++) {
313 for (
int j = 0; j < 4; j++) {
316 c.m[
i][
i] =
c.m[
i][j];
334 for (
int i = 0;
i < 4;
i++) {
351 for (
int n = 1; n < ops->
num_ops; n++) {
368 if (size_from < size_to) {
379 for (
int n = 0; n < ops->
num_ops; n++) {
401 for (
int i = 0;
i <
op->rw.elems;
i++) {
403 swiz.
in[
i] = 3 - (
i - nb_planes);
407 const int idx = nb_planes++;
413 if (nb_planes < op->rw.elems) {
414 op->rw.elems = nb_planes;
417 .type =
op->rw.filter.op ?
op->rw.filter.type :
op->type,
449 if (next->
op ==
op->op) {
456 if (!
op->shift.amount) {
463 for (
int i = 0;
i < 4;
i++) {
469 op->clear.value[
i].num == 0)
488 for (
int i = 0;
i < 4;
i++) {
499 for (
int i = 0;
i < 4;
i++) {
502 if (
op->swizzle.in[
i] !=
i)
515 for (
int i = 0;
i < 4;
i++)
524 const int src =
op->swizzle.in[
dst];
527 for (
int i =
dst;
i < 4;
i++) {
528 if (
op->swizzle.in[
i] ==
dst)
530 else if (
op->swizzle.in[
i] ==
src)
540 const int src =
op->swizzle.in[
dst];
552 if (
op->type ==
op->convert.to) {
574 op->convert.expand =
true;
581 for (
int i = 0;
i < 4;
i++) {
597 for (
int i = 0;
i < 4;
i++) {
613 for (
int i = 0;
i < 4;
i++) {
614 if (
op->dither.y_offset[
i] < 0)
617 op->dither.y_offset[
i] = -1;
646 for (
int i = 0;
i < 4;
i++) {
647 for (
int j = 0; j < 5; j++) {
649 for (
int k = 0; k < 4; k++)
653 op->lin.m[
i][j] = sum;
661 for (
int j = 0; j < 4; j++) {
665 for (
int i = 0;
i < 4;
i++)
666 op->lin.m[
i][j] =
Q(
i == j);
671 for (
int i = 0;
i < 4;
i++) {
675 for (
int j = 0; j < 5; j++)
676 op->lin.m[
i][j] =
Q(
i == j);
714 if (
op->scale.factor.num == 1 &&
op->scale.factor.den == 1) {
729 op->shift.amount =
FFABS(factor2);
759 for (
int n = 0; n < ops->
num_ops - 1; n++) {
776 for (
int n = 0; n < ops->
num_ops - 1; n++) {
825 .op = SWS_OP_SWIZZLE,
847 if (!mask1 || !mask2) {
881 for (
int n = 0; n < num_groups; n++) {
886 shuffle[base_out +
i] = idx + (idx >= 0) * base_in;
897 case 2:
return val.u16 ==
val.u8 * 0x101ul;
898 case 4:
return val.u32 ==
val.u8 * 0x1010101ul;
923 uint32_t
mask[4] = {0};
926 for (
int i = 0;
i < 4;
i++) {
928 mask[
i] = 0x01010101 *
i * read_size + 0x03020100;
933 for (
int opidx = 1; opidx < uops->
num_ops; opidx++) {
941 const int dst_idx = par->
move.
dst[
i];
942 const int src_idx = par->
move.
src[
i];
943 uint32_t *
src = src_idx < 0 ? &
tmp : &
mask[src_idx];
944 uint32_t *
dst = dst_idx < 0 ? &
tmp : &
mask[dst_idx];
951 for (
int i = 0;
i < 4;
i++) {
960 for (
int i = 0;
i < 4;
i++) {
965 (clear_val >= 0 && clear_val !=
val.u8))
967 mask[
i] = 0xFFFFFFFFul;
974 for (
int i = 0;
i < 4;
i++)
994 .read_size = read_elems * read_size,
995 .write_size = write_elems * write_size,
996 .clear_value = clear_val >= 0 ? clear_val : 0,
1001 for (
int i = 0;
i < write_elems;
i++) {
1002 const int offset =
i * write_size;
1003 for (
int b = 0;
b < write_size;
b++)
1016 data->pixels = num_groups;
1037 }
else if (ret < 0 && ret !=
AVERROR(ENOTSUP)) {
1071 switch (nb_planes) {
1079 switch (nb_planes) {
1087 switch (nb_planes) {
1107 fmt->
height =
read->rw.filter.kernel->dst_size;
1109 fmt->
width =
read->rw.filter.kernel->dst_size;
1136 for (
int i = 0;
i < 4;
i++) {
1138 const int o = nb_planes++;
1151 for (
int i = 0;
i < nb_planes;
i++) {
1152 const int idx = swiz_wr.
in[
i];
1176 .rw.elems = nb_planes,
1184 .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 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)
AVRational64 av_mul_q64(AVRational64 b, AVRational64 c)
Multiply two 64-bit rationals.
int av_cmp_q64(AVRational64 a, AVRational64 b)
Compare two 64-bit rationals.
AVRational64 av_add_q64(AVRational64 b, AVRational64 c)
Add two 64-bit rationals.
static void scale(int *out, const int *in, const int w, const int h, 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)
void ff_sws_op_list_update_comps(SwsOpList *ops)
Infer + propagate known information about components.
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)
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)
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 AVRational64 ff_sws_pixel_expand(SwsPixelType from, SwsPixelType to)
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.
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 SwsComps *prev, SwsSwizzleOp *out_swiz)
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...
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)
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.
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.
SwsComps comps_src
Source component metadata associated with pixel values from each corresponding component (in plane/me...
SwsComps comps
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
SwsReadWriteMode mode
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)
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)