Go to the documentation of this file.
45 #define FMT(fmt, ...) tprintf((char[256]) {0}, 256, fmt, __VA_ARGS__)
46 static const char *
tprintf(
char buf[],
size_t size,
const char *fmt, ...)
57 const int elems =
op->rw.packed ?
op->rw.elems : 1;
59 const int bits = 8 >>
op->rw.frac;
66 union { uint32_t
u;
float f; } x;
69 }
while (!isnormal(x.f));
76 for (
int i = 0;
i < num;
i++)
82 for (
int i = 0;
i < num;
i++)
91 for (
int i = 0;
i < num;
i++)
101 for (
int i = 0;
i < num;
i++)
129 void *plane =
src0[
p];
130 switch (read_op->
type) {
132 fill8(plane,
sizeof(
src0[
p]) /
sizeof(uint8_t), ranges[
p]);
135 fill16(plane,
sizeof(
src0[
p]) /
sizeof(uint16_t), ranges[
p]);
138 fill32(plane,
sizeof(
src0[
p]) /
sizeof(uint32_t), ranges[
p]);
141 fill32f(plane,
sizeof(
src0[
p]) /
sizeof(uint32_t), ranges[
p]);
147 memset(dst0, 0,
sizeof(dst0));
148 memset(dst1, 0,
sizeof(dst1));
166 for (
int y = 0; y <
LINES - 1; y++)
168 in_bump_y[
LINES - 1] = 0;
176 for (
int x = 0; x <
PIXELS; x++)
177 in_offset_x[x] =
offsets[x] * rw_bits >> 3;
186 uintptr_t
id = (uintptr_t) comp_new->
func;
187 id ^= (
id << 6) + (
id >> 2) + 0x9e3779b97f4a7c15 + comp_new->
cpu_flags;
194 exec.
out[
i] = (
void *) dst0[
i];
202 exec.
out[
i] = (
void *) dst1[
i];
208 const int stride =
sizeof(dst0[
i][0]);
210 switch (write_op->
type) {
249 static const unsigned def_ranges[4] = {0};
253 const SwsOp *read_op, *write_op;
256 .plane_src = {0, 1, 2, 3},
257 .plane_dst = {0, 1, 2, 3},
262 write_op = &ops[oplist.
num_ops];
265 switch (read_op->
type) {
279 if (ranges[
p] && ranges[
p] <= INT_MAX) {
322 }
else if (
ret < 0) {
336 #define CHECK_RANGES(NAME, RANGES, N_IN, N_OUT, IN, OUT, ...) \
338 check_ops(NAME, RANGES, (SwsOp[]) { \
346 .op = SWS_OP_WRITE, \
353 #define MK_RANGES(R) ((const unsigned[]) { R, R, R, R })
354 #define CHECK_RANGE(NAME, RANGE, N_IN, N_OUT, IN, OUT, ...) \
355 CHECK_RANGES(NAME, MK_RANGES(RANGE), N_IN, N_OUT, IN, OUT, __VA_ARGS__)
357 #define CHECK_COMMON_RANGE(NAME, RANGE, IN, OUT, ...) \
358 CHECK_RANGE(FMT("%s_p1000", NAME), RANGE, 4, 4, IN, OUT, __VA_ARGS__); \
359 CHECK_RANGE(FMT("%s_p1110", NAME), RANGE, 4, 4, IN, OUT, __VA_ARGS__); \
360 CHECK_RANGE(FMT("%s_p1111", NAME), RANGE, 4, 4, IN, OUT, __VA_ARGS__); \
361 CHECK_RANGE(FMT("%s_p1001", NAME), RANGE, 4, 4, IN, OUT, __VA_ARGS__, { \
362 .op = SWS_OP_SWIZZLE, \
364 .swizzle = SWS_SWIZZLE(0, 3, 1, 2), \
367 #define CHECK(NAME, N_IN, N_OUT, IN, OUT, ...) \
368 CHECK_RANGE(NAME, 0, N_IN, N_OUT, IN, OUT, __VA_ARGS__)
370 #define CHECK_COMMON(NAME, IN, OUT, ...) \
371 CHECK_COMMON_RANGE(NAME, 0, IN, OUT, __VA_ARGS__)
377 for (
int i = 1;
i <= 4;
i++) {
379 for (
int o = 1; o <=
i; o++) {
426 for (
int frac = 1; frac <= 3; frac++) {
427 const int bits = 8 >> frac;
479 {
U8, {{ 3, 3, 2 }}},
480 {
U8, {{ 2, 3, 3 }}},
481 {
U8, {{ 1, 2, 1 }}},
482 {
U16, {{ 5, 6, 5 }}},
483 {
U16, {{ 5, 5, 5 }}},
484 {
U16, {{ 4, 4, 4 }}},
485 {
U32, {{ 2, 10, 10, 10 }}},
486 {
U32, {{10, 10, 10, 2 }}},
492 const int num = pack.
pattern[3] ? 4 : 3;
497 const unsigned ranges[4] = {
520 const unsigned num =
rnd();
525 const unsigned den =
rnd();
545 {{ none, none, none,
zero }},
546 {{
zero, none, none, none }},
548 {{ none, none, none,
alpha }},
549 {{
alpha, none, none, none }},
568 .clear = patterns[
i],
576 .clear.value[3] = { 0, 1 },
609 static const int patterns[][4] = {
637 const int x = patterns[
i][0], y = patterns[
i][1],
638 z = patterns[
i][2],
w = patterns[
i][3];
639 CHECK(
FMT(
"swizzle_%d%d%d%d_%s", x, y, z,
w,
type), 4, 4, t, t, {
656 const char *
name =
FMT(
"convert_%s_%s", itype, otype);
667 uint32_t
range = UINT32_MAX >> (32 - osize * 8);
682 .convert.expand =
true,
689 .convert.expand =
true,
701 for (
int size_log2 = 0; size_log2 <= 8; size_log2++) {
702 const int size = 1 << size_log2;
720 .dither.size_log2 = size_log2,
750 static const struct {
773 const uint32_t
mask = patterns[
p].mask;
776 for (
int i = 0;
i < 4;
i++) {
777 for (
int j = 0; j < 5; j++) {
801 const unsigned max = (1 <<
bits) - 1;
807 .scale = {{
max, 1 }},
816 .scale = {{
scale, 1 }},
822 .scale = {
rndq(t) },
855 for (
int n = 1; n <= 4; n++) {
884 for (
int n = 1; n <= 4; n++) {
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 default minimum maximum flags name is the option name
static void check_compiled(const char *name, const SwsOpBackend *backend, const SwsOp *read_op, const SwsOp *write_op, const int ranges[NB_PLANES], const SwsCompiledOp *comp_ref, const SwsCompiledOp *comp_new)
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
int src_size
The relative sizes of the input and output images.
SwsComps comps_src
Source component metadata associated with pixel values from each corresponding component (in plane/me...
ptrdiff_t in_bump[4]
Pointer bump, difference between stride and processed line size.
#define CHECK_COMMON(NAME, IN, OUT,...)
AVRational m[4][5]
Generalized 5x5 affine transformation: [ Out.x ] = [ A B C D E ] [ Out.y ] = [ F G H I J ] * [ x y z ...
static void check_min_max(void)
#define u(width, name, range_min, range_max)
Represents a computed filter kernel.
void checkasm_check_sw_ops(void)
static void check_convert(void)
int * offsets
The computed source pixel positions for each row of the filter.
static void check_swap_bytes(void)
void(* filter)(uint8_t *src, int stride, int qscale)
#define CHECK_COMMON_RANGE(NAME, RANGE, IN, OUT,...)
static void check_read_write(void)
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
static void check_linear(void)
static void check_filter(void)
int ff_sws_pixel_type_size(SwsPixelType type)
int ff_sws_filter_generate(void *log, const SwsFilterParams *params, SwsFilterWeights **out)
Generate a filter kernel for the given parameters.
#define DECLARE_ALIGNED_64(t, v)
static void check_clear(void)
SwsPixelType
Copyright (C) 2025 Niklas Haas.
#define CHECK_RANGE(NAME, RANGE, N_IN, N_OUT, IN, OUT,...)
const SwsOpBackend *const ff_sws_op_backends[]
static void check_scale(void)
bool ff_sws_pixel_type_is_int(SwsPixelType type)
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
enum AVPixelFormat hw_format
If NONE, backend only supports software frames.
static void * av_refstruct_allocz(size_t size)
Equivalent to av_refstruct_alloc_ext(size, 0, NULL, NULL)
#define FF_ARRAY_ELEMS(a)
static const int offsets[]
#define AV_CEIL_RSHIFT(a, b)
#define SWS_SWIZZLE(X, Y, Z, W)
int flags
Flags modifying the (de)muxer behaviour.
int32_t * in_bump_y
Line bump; determines how many additional lines to advance (after incrementing normally to the next l...
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.
static void fill32(uint32_t *line, int num, unsigned range)
static AVFormatContext * ctx
Copyright (C) 2026 Niklas Haas.
SwsFilterWeights * kernel
static void fill16(uint16_t *line, int num, unsigned range)
static int rw_pixel_bits(const SwsOp *op)
static const char * tprintf(char buf[], size_t size, const char *fmt,...)
void ff_sws_compiled_op_unref(SwsCompiledOp *comp)
Rational number (pair of numerator and denominator).
@ SWS_SCALE_SINC
unwindowed sinc
#define SWS_PARAM_DEFAULT
uint8_t pattern[4]
Packed bits are assumed to be LSB-aligned within the underlying integer type; i.e.
SwsContext * sws_alloc_context(void)
Allocate an empty SwsContext and set its fields to default values.
static int shift(int a, int b)
#define i(width, name, range_min, range_max)
static int zero(InterplayACMContext *s, unsigned ind, unsigned col)
void av_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
static void fill32f(float *line, int num, unsigned range)
@ SWS_SCALE_POINT
nearest neighbor (point sampling)
int32_t * in_offset_x
Pixel offset map; for horizontal scaling, in bytes.
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
double scaler_params[SWS_NUM_SCALER_PARAMS]
#define checkasm_call_checked(func,...)
static void check_shift(void)
SwsOpType filter
Filter kernel to apply to each plane while sampling.
static void check_swizzle(void)
const char * ff_sws_pixel_type_name(SwsPixelType type)
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
int ff_sws_ops_compile_backend(SwsContext *ctx, const SwsOpBackend *backend, const SwsOpList *ops, SwsCompiledOp *out)
Attempt to compile a list of operations using a specific backend.
static AVRational rndq(SwsPixelType t)
#define check_key(key,...)
#define declare_func(ret,...)
static void scale(int *out, const int *in, const int w, const int h, const int shift)
static const int16_t alpha[]
static void fill8(uint8_t *line, int num, unsigned range)
void sws_free_context(SwsContext **ctx)
Free the context and everything associated with it, and write NULL to the provided pointer.
static void set_range(AVRational *rangeq, unsigned range, unsigned range_def)
#define checkasm_call(func,...)
static void check_pack_unpack(void)
static void check_ops(const char *name, const unsigned ranges[NB_PLANES], const SwsOp *ops)
#define checkasm_check(prefix,...)
Helper struct for representing a list of operations.
Main external API structure.
#define CHECK(NAME, N_IN, N_OUT, IN, OUT,...)
SwsScaler scaler
The filter kernel and parameters to use.
#define CHECK_RANGES(NAME, RANGES, N_IN, N_OUT, IN, OUT,...)
static void check_dither(void)