38#if CONFIG_SWSCALE_VULKAN
44#if ARCH_AARCH64 && HAVE_NEON
46#elif ARCH_X86_64 && HAVE_X86ASM
50#if CONFIG_SWSCALE_VULKAN
103 for (
int i = 0;
i < 4;
i++) {
114 for (
int i = 0;
i < 4;
i++) {
115 const int src = swiz->
in[
i];
126 for (
int i = 0;
i < 4;
i++) {
136 switch (
op->rw.mode) {
150 return op - ops->
ops;
159 return idx > 0 ? &ops->
ops[idx - 1] :
NULL;
174 for (
int i = 0;
op &&
i < 4;
i++) {
179 else if (
op->outputs[
i].type !=
type)
214 for (
int i = 0;
i < 4;
i++)
221 for (
int i = 0;
i < 4;
i++)
229 for (
int i = 0;
i < 4;
i++) {
235 for (
int i = 0;
i < 4;
i++) {
244 for (
int i = 0;
i < 4;
i++) {
246 x[
i] =
op->clear.value[
i];
251 for (
int i = 0;
i < 4;
i++)
256 for (
int i = 0;
i < 4;
i++)
257 x[
i] = x[
i].den ?
Q((x[
i].
num / x[
i].den) >>
op->shift.amount) : x[
i];
261 const AVRational64 orig[4] = { x[0], x[1], x[2], x[3] };
262 for (
int i = 0;
i < 4;
i++)
263 x[
i] = orig[
op->swizzle.in[
i]];
268 for (
int i = 0;
i < 4;
i++)
269 x[
i] = x[
i].den ?
Q(x[
i].
num / x[
i].den) : x[
i];
273 for (
int i = 0;
i < 4;
i++) {
274 if (
op->dither.y_offset[
i] >= 0 && x[
i].
den)
279 for (
int i = 0;
i < 4;
i++)
283 for (
int i = 0;
i < 4;
i++)
287 const AVRational64 orig[4] = { x[0], x[1], x[2], x[3] };
288 for (
int i = 0;
i < 4;
i++) {
290 for (
int j = 0; j < 4; j++)
297 for (
int i = 0;
i < 4;
i++)
307 for (
int i = 0;
i < 3;
i++)
327 return ((
a &
b) & flags_and) | ((
a |
b) & flags_or);
352 for (
int i = 0;
i < 4;
i++) {
367 for (
int i = 0;
i < 4;
i++) {
374 for (
int i = 0;
i < 4;
i++) {
382#define FORWARD(I, J, EXPR) do { \
383 SwsOpPad *dst = &out[I]; \
384 const SwsOpPad *src = &in[J]; \
385 SwsCompFlags flags = src->flags; \
386 if (!src->type || dst->type && dst->type != src->type) \
387 invalid |= SWS_COMP(I); \
388 dst->flags = merge_comp_flags(dst->flags, (EXPR)); \
389 dst->dep_in |= src->dep_in; \
390 dst->type = src->type; \
393#define RESET(I) do { \
394 SwsOpPad *dst = &out[I]; \
395 dst->type = SWS_PIXEL_NONE; \
397 dst->min = dst->max = (AVRational64) {0}; \
398 dst->dep_in = SWS_COMP_NONE; \
405 for (
int i = 0;
i <
op->rw.elems;
i++) {
407 switch (
op->rw.mode) {
415 dst->type =
op->rw.type;
421 if (
op->rw.filter.op) {
423 dst->type =
op->rw.filter.type;
435 for (
int i =
op->rw.elems;
i < 4;
i++)
439 for (
int i = 0;
i < 4;
i++) {
447 for (
int i = 0;
i <
op->rw.elems;
i++)
449 for (
int i = 0;
i < 4;
i++)
454 for (
int i = 0;
i < 4;
i++)
459 for (
int i = 0;
i < 4;
i++) {
462 if (
op->clamp.limit[
i].den)
473 for (
int i = 0;
i < 4;
i++) {
477 if (
op->dither.y_offset[
i] < 0)
486 for (
int i = 0;
i < 4;
i++) {
487 const int pattern =
op->pack.pattern[
i];
492 out[
i].max =
Q((1ULL << pattern) - 1);
498 for (
int i = 0;
i < 4;
i++) {
499 if (
op->pack.pattern[
i])
506 for (
int i = 0;
i < 4;
i++) {
508 out[
i].type =
op->clear.type[
i];
510 if (
op->clear.value[
i].num == 0)
512 if (
op->clear.value[
i].den == 1)
520 for (
int i = 0;
i < 4;
i++)
524 for (
int i = 0;
i < 4;
i++) {
526 out[
i].type =
op->convert.to;
534 for (
int i = 0;
i < 4;
i++) {
537 dst->type =
op->lin.type[
i];
539 for (
int j = 0; j < 4; j++) {
557 if (
op->lin.m[
i][4].num) {
559 if (
op->lin.m[
i][4].den != 1)
567 for (
int i = 0;
i < 4;
i++) {
569 if (
op->scale.factor.den != 1)
571 if (
op->scale.factor.num < 0)
577 for (
int i = 0;
i < 4;
i++) {
580 out[
i].type =
op->filter.type;
585 for (
int i = 0;
i < 3;
i++) {
587 for (
int j = 0; j < 3; j++)
591 out[
i].max =
Q(UINT16_MAX);
603 for (
int i = 0;
i < 4;
i++) {
616 for (
int i = 0;
i < 4;
i++)
617 op->outputs[
i].dep_out = need_out[
i];
622 for (
int i = 0;
i <
op->rw.elems;
i++)
624 for (
int i =
op->rw.elems;
i < 4;
i++)
625 need_in[
i] = need_out[
i];
637 for (
int i = 0;
i < 4;
i++)
638 need_in[
i] = need_out[
i];
641 for (
int i = 0;
i < 4 &&
op->pack.pattern[
i];
i++)
642 need_in[0] |= need_out[
i];
645 for (
int i = 0;
i < 4 &&
op->pack.pattern[
i];
i++)
646 need_in[
i] = need_out[0];
649 for (
int i = 0;
i < 4;
i++) {
651 need_in[
i] = need_out[
i];
655 for (
int i = 0;
i < 4;
i++)
656 need_in[
op->swizzle.in[
i]] |= need_out[
i];
659 for (
int i = 0;
i < 4;
i++) {
660 for (
int j = 0; j < 4; j++) {
661 if (
op->lin.m[
i][j].num)
662 need_in[j] |= need_out[
i];
667 for (
int i = 0;
i < 3;
i++)
668 need_in[
i] = need_out[0] | need_out[1] | need_out[2];
669 need_in[3] = need_out[3];
673 memcpy(need_out, need_in,
sizeof(need_in));
680 for (
int n = 0; n < ops->
num_ops; n++)
685 for (
int n = ops->
num_ops - 1; n >= 0; n--)
693 if (
op->rw.filter.kernel)
736 for (
int i = 0;
i < 4;
i++)
774 for (
int i = 0;
i <
copy->num_ops;
i++) {
802 const int end = ops->
num_ops - count;
804 for (
int i = 0;
i < count;
i++)
853 for (
int i = 0;
i < num_planes;
i++) {
864 for (
int i = 0;
i < 4;
i++) {
865 for (
int j = 0; j < 5; j++) {
902 }
else if (q.
den == 1) {
904 }
else if (q.
num > 1000 || q.
num < -1000 || q.
den > 1000 || q.
den < -1000) {
914 for (
int i = 0;
i < 4;
i++) {
947 if (!
op->rw.filter.op)
963 op->pack.pattern[0],
op->pack.pattern[1],
964 op->pack.pattern[2],
op->pack.pattern[3]);
972 op->swizzle.x,
op->swizzle.y,
op->swizzle.z,
op->swizzle.w);
981 1 <<
op->dither.size_log2, 1 <<
op->dither.size_log2,
982 op->dither.y_offset[0],
op->dither.y_offset[1],
983 op->dither.y_offset[2],
op->dither.y_offset[3]);
996 for (
int i = 0;
i < 4;
i++) {
998 for (
int j = 0; j < 5; j++) {
1008 if (
op->scale.factor.den != 1)
1020 av_bprintf(bp,
"%-20s: %s",
name,
op->lut3d.dynamic ?
"dynamic" :
"static");
1029 bool inorder =
true;
1030 for (
int i = 0;
i < nb_planes;
i++)
1031 inorder &= order[
i] ==
i;
1036 for (
int i = 0;
i < nb_planes;
i++)
1044 AVBPrint bpc, *bp = &bpc;
1056 for (
int n = 0; n < ops->
num_ops; n++) {
1071 for (
int i = 0;
i < 4;
i++) {
1099 av_log(log, lev_extra,
"%s\n", bp->str);
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
const SwsOpBackend backend_aarch64
static double val(void *priv, double ch)
static double bound(const double threshold, const double val)
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.
void av_bprintf(AVBPrint *buf, const char *fmt,...)
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
#define AV_BPRINT_SIZE_AUTOMATIC
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
static LevelCodes lev[4+3+3]
const char * ff_sws_scaler_name(SwsScaler scaler)
Return the friendly name of a given scaler enum, or NULL if invalid.
AVRational64 ff_mul_q64(AVRational64 b, AVRational64 c)
Multiply two 64-bit rationals.
static AVRational64 ff_make_q64(int64_t num, int64_t den)
Create an AVRational64.
static double ff_q2d_64(AVRational64 a)
Convert an AVRational64 to a double.
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 int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
void av_bprint_clear(AVBPrint *buf)
Reset the string to "" but keep internal allocated data.
int av_log_get_level(void)
Get the current log level.
void * av_dynarray2_add(void **tab_ptr, int *nb_ptr, size_t elem_size, const uint8_t *elem_data)
Add an element of size elem_size to a dynamic array.
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
static const int weights[]
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.
static int shift(int a, int b)
static int16_t mult(Float11 *f1, Float11 *f2)
Macro definitions for various function/variable attributes.
@ SWS_FILTER_SCALE
14-bit coefficients are picked to fit comfortably within int16_t for efficient SIMD processing (e....
static const struct @257111027162314367033347246032313251342043035002 planes[]
static const uint16_t mask[17]
#define FFSWAP(type, a, b)
Memory handling functions.
void ff_sws_op_desc(AVBPrint *bp, const SwsOp *op)
Describe an operation in human-readable form.
const SwsOpBackend backend_c
Copyright (C) 2025 Niklas Haas.
SwsPixelType ff_sws_op_output_type(const SwsOp *op)
const SwsOp * ff_sws_op_next(const SwsOp *op)
uint32_t ff_sws_linear_mask(const SwsLinearOp *c)
static void update_output_pads(SwsOpList *ops, SwsOp *op)
static void print_q4(AVBPrint *bp, const AVRational64 q4[4], SwsCompMask mask)
static void desc_plane_order(AVBPrint *bp, int nb_planes, const uint8_t *order)
int ff_sws_op_list_insert_at(SwsOpList *ops, int index, SwsOp *op)
static void op_ref(SwsOp *op)
static void update_input_pads(SwsOpList *ops, SwsOp *op, SwsCompMask need_out[4])
const SwsOpBackend backend_x86
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)
const SwsOpBackend *const ff_sws_op_backends[]
static const char * describe_comp_flags(SwsCompFlags flags)
static AVRational64 av_min_q64(AVRational64 a, AVRational64 b)
const SwsOpBackend backend_murder
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)
SwsOpList * ff_sws_op_list_alloc(void)
#define FORWARD(I, J, EXPR)
static void print_deps(AVBPrint *bp, SwsCompMask dep)
const char * ff_sws_op_type_name(SwsOpType op)
static AVRational64 av_max_q64(AVRational64 a, AVRational64 b)
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 char * ff_sws_pixel_type_name(SwsPixelType type)
static SwsCompFlags merge_comp_flags(SwsCompFlags a, SwsCompFlags b)
SwsCompMask ff_sws_comp_mask_q4(const AVRational64 q[4])
int ff_sws_rw_op_planes(const SwsOp *op)
Return the number of planes involved in a read/write 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.
bool ff_sws_op_list_is_noop(const SwsOpList *ops)
Returns whether an op list represents a true no-op operation, i.e.
const SwsOp * ff_sws_op_prev(const SwsOp *op)
Return the previous/next operation in the list, or NULL if there is none.
void ff_sws_op_list_print(void *log, int lev, int lev_extra, const SwsOpList *ops)
Print out the contents of an operation list.
static const char *const rw_mode_names[]
void ff_sws_apply_op_q(const SwsOp *op, AVRational64 x[4])
Apply an operation to an AVRational64.
static int op_index(const SwsOp *op)
void ff_sws_op_list_remove_at(SwsOpList *ops, int index, int count)
static void apply_filter_weights(SwsOpPad *pad, const SwsFilterWeights *weights)
SwsOpList * ff_sws_op_list_duplicate(const SwsOpList *ops)
Returns a duplicate of ops, or NULL on OOM.
static void op_unref(SwsOp *op)
SwsOpType
Copyright (C) 2025 Niklas Haas.
@ SWS_RW_PLANAR
Note: 1-component reads are either SWS_RW_PLANAR or SWS_RW_PACKED, depending on the underlying interp...
#define SWS_OP_NEEDED(op, idx)
static void ff_sws_pack_decode(const uint8_t pattern[4], uint64_t mask[4], int shift[4])
Utilities for rational number calculation.
void av_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
const void * av_refstruct_ref_c(const void *obj)
Analog of av_refstruct_ref(), but for constant objects.
void * av_refstruct_ref(void *obj)
Create a new reference to an object managed via this API, i.e.
64-bit Rational number (pair of numerator and denominator).
Represents a computed filter kernel.
SwsScaler scaler
Copy of the parameters used to generate this filter, for reference.
int filter_size
The number of source texels to convolve over for each row.
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.
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.
#define SWS_COMP_TEST(mask, X)
static av_const bool ff_sws_pixel_type_is_int(SwsPixelType type)
uint8_t SwsCompMask
Bit-mask of components.
static void copy(const float *p1, float *p2, const int length)
const SwsOpBackend backend_spirv