Go to the documentation of this file.
   30         if ((ret = (x)) < 0)                                                   \ 
   71     return ((
a & 
b) & flags_and) | ((
a | 
b) & flags_or);
 
   83     for (
int n = 0; n < ops->
num_ops; n++) {
 
   88         memcpy(
op->comps.min, prev.
min, 
sizeof(prev.
min));
 
   89         memcpy(
op->comps.max, prev.
max, 
sizeof(prev.
max));
 
   98             for (
int i = 0; 
i < 
op->rw.elems; 
i++) {
 
  106                         for (
int c = 0; 
c < 4; 
c++) {
 
  115                     op->comps.min[
i] = 
Q(0);
 
  116                     op->comps.max[
i] = 
Q((1ULL << 
bits) - 1);
 
  119             for (
int i = 
op->rw.elems; 
i < 4; 
i++)
 
  123             for (
int i = 0; 
i < 
op->rw.elems; 
i++)
 
  132             for (
int i = 0; 
i < 4; 
i++)
 
  137             for (
int i = 0; 
i < 4; 
i++)
 
  141             for (
int i = 0; 
i < 4; 
i++) {
 
  142                 if (
op->pack.pattern[
i])
 
  150             for (
int i = 0; 
i < 4; 
i++) {
 
  151                 if (
op->pack.pattern[
i])
 
  160             for (
int i = 0; 
i < 4; 
i++) {
 
  161                 if (
op->c.q4[
i].den) {
 
  162                     if (
op->c.q4[
i].num == 0) {
 
  164                     } 
else if (
op->c.q4[
i].den == 1) {
 
  173             for (
int i = 0; 
i < 4; 
i++)
 
  174                 op->comps.flags[
i] = prev.
flags[
op->swizzle.in[
i]];
 
  177             for (
int i = 0; 
i < 4; 
i++) {
 
  184             for (
int i = 0; 
i < 4; 
i++) {
 
  187                 for (
int j = 0; j < 4; j++) {
 
  201                 if (
op->lin.m[
i][4].num) { 
 
  203                     if (
op->lin.m[
i][4].den != 1) 
 
  214             for (
int i = 0; 
i < 4; 
i++) {
 
  216                 if (
op->c.q.den != 1) 
 
  232     for (
int n = ops->
num_ops - 1; n >= 0; n--) {
 
  238             for (
int i = 0; 
i < 
op->rw.elems; 
i++)
 
  240             for (
int i = 
op->rw.elems; 
i < 4; 
i++)
 
  251             for (
int i = 0; 
i < 4; 
i++)
 
  256             for (
int i = 0; 
i < 4; 
i++) {
 
  257                 if (
op->pack.pattern[
i])
 
  259                 op->comps.unused[
i] = 
i > 0;
 
  261             op->comps.unused[0] = unused;
 
  265             for (
int i = 0; 
i < 4; 
i++) {
 
  266                 if (
op->pack.pattern[
i])
 
  269                     op->comps.unused[
i] = 
true;
 
  273             for (
int i = 0; 
i < 4; 
i++) {
 
  275                     op->comps.unused[
i] = 
true;
 
  281             bool unused[4] = { 
true, 
true, 
true, 
true };
 
  282             for (
int i = 0; 
i < 4; 
i++)
 
  284             for (
int i = 0; 
i < 4; 
i++)
 
  285                 op->comps.unused[
i] = unused[
i];
 
  289             for (
int j = 0; j < 4; j++) {
 
  291                 for (
int i = 0; 
i < 4; 
i++) {
 
  292                     if (
op->lin.m[
i][j].num)
 
  295                 op->comps.unused[j] = unused;
 
  311     return (1 << 
p) == x ? 
p : 0;
 
  337     for (
int i = 0; 
i < 4; 
i++) {
 
  358     for (
int i = 0; 
i < 4; 
i++) {
 
  359         bool const_row = 
c->m[
i][4].den == 1; 
 
  360         for (
int j = 0; j < 4; j++) {
 
  361             const_row &= 
c->m[
i][j].num == 0 || 
 
  365             clear.
q4[
i] = 
c->m[
i][4];
 
  366             for (
int j = 0; j < 5; j++)
 
  367                 c->m[
i][j] = 
Q(
i == j);
 
  385     for (
int i = 0; 
i < 4; 
i++) {
 
  387         for (
int j = 0; j < 4; j++) {
 
  395         if (idx >= 0 && idx != 
i) {
 
  397             c.m[
i][
i] = 
c.m[
i][idx];
 
  419     for (
int n = 0; n < ops->
num_ops;) {
 
  442             if (!
op->rw.packed) {
 
  477             if (next->
op == 
op->op) {
 
  478                 op->c.u += next->
c.
u;
 
  491             for (
int i = 0; 
i < 4; 
i++) {
 
  492                 if (!
op->c.q4[
i].den)
 
  497                     op->c.q4[
i].num == 0)
 
  504                 } 
else if (
op->c.q4[
i].den) {
 
  516                 for (
int i = 0; 
i < 4; 
i++) {
 
  539             bool has_duplicates = 
false;
 
  540             for (
int i = 0; 
i < 4; 
i++) {
 
  543                 if (
op->swizzle.in[
i] != 
i)
 
  545                 has_duplicates |= seen[
op->swizzle.in[
i]];
 
  546                 seen[
op->swizzle.in[
i]] = 
true;
 
  558                 for (
int i = 0; 
i < 4; 
i++)
 
  571                     for (
int i = 0; 
i < 4; 
i++) {
 
  573                             next->
c.
q4[
op->swizzle.in[
i]] = 
c.q4[
i];
 
  592             if (
op->type == 
op->convert.to) {
 
  611                 op->convert.expand = 
true;
 
  618             for (
int i = 0; 
i < 4; 
i++) {
 
  632             for (
int i = 0; 
i < 4; 
i++) {
 
  646             for (
int i = 0; 
i < 4; 
i++) {
 
  671                 for (
int i = 0; 
i < 4; 
i++) {
 
  672                     for (
int j = 0; j < 5; j++) {
 
  674                         for (
int k = 0; k < 4; k++)
 
  678                         op->lin.m[
i][j] = sum;
 
  687             for (
int j = 0; j < 4; j++) {
 
  691                 for (
int i = 0; 
i < 4; 
i++)
 
  692                     op->lin.m[
i][j] = 
Q(
i == j);
 
  693                 op->lin.mask &= ~col;
 
  698             for (
int i = 0; 
i < 4; 
i++) {
 
  702                 for (
int j = 0; j < 5; j++)
 
  703                     op->lin.m[
i][j] = 
Q(
i == j);
 
  704                 op->lin.mask &= ~row;
 
  742             if (
op->c.q.num == 1 && 
op->c.q.den == 1) {
 
  748             if (
op->c.q.den == 1 &&
 
  775                          int size, uint8_t clear_val,
 
  780     uint32_t 
mask[4] = {0};
 
  784     if (
read.rw.frac || (!
read.rw.packed && 
read.rw.elems > 1))
 
  787     for (
int i = 0; 
i < 
read.rw.elems; 
i++)
 
  788         mask[
i] = 0x01010101 * 
i * read_size + 0x03020100;
 
  790     for (
int opidx = 1; opidx < ops->
num_ops; opidx++) {
 
  795             for (
int i = 0; 
i < 4; 
i++)
 
  801             for (
int i = 0; 
i < 4; 
i++) {
 
  810             for (
int i = 0; 
i < 4; 
i++) {
 
  811                 if (!
op->c.q4[
i].den)
 
  813                 if (
op->c.q4[
i].num != 0 || !clear_val)
 
  815                 mask[
i] = 0x1010101ul * clear_val;
 
  820             if (!
op->convert.expand)
 
  822             for (
int i = 0; 
i < 4; 
i++) {
 
  824                 case 1: 
mask[
i] = 0x01010101 * (
mask[
i] & 0xFF);   
break;
 
  825                 case 2: 
mask[
i] = 0x00010001 * (
mask[
i] & 0xFFFF); 
break;
 
  832             if (
op->rw.frac || (!
op->rw.packed && 
op->rw.elems > 1))
 
  840             const int write_chunk = 
op->rw.elems * write_size;
 
  842             for (
int n = 0; n < num_groups; n++) {
 
  844                 const int base_out = n * write_chunk;
 
  845                 for (
int i = 0; 
i < 
op->rw.elems; 
i++) {
 
  846                     const int offset = base_out + 
i * write_size;
 
  847                     for (
int b = 0; 
b < write_size; 
b++) {
 
  848                         const uint8_t idx = 
mask[
i] >> (
b * 8);
 
  849                         if (idx != clear_val)
 
  
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
void ff_sws_op_list_update_comps(SwsOpList *ops)
Infer + propagate known information about components.
uint32_t ff_sws_linear_mask(const SwsLinearOp c)
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 ...
int depth
Number of bits in the component.
static void read_bytes(const uint8_t *src, float *dst, int src_stride, int dst_stride, int width, int height, float scale)
int ff_sws_op_list_optimize(SwsOpList *ops)
Fuse compatible and eliminate redundant operations, as well as replacing some operations with more ef...
int ff_sws_pixel_type_size(SwsPixelType type)
bool ff_sws_pixel_type_is_int(SwsPixelType type)
#define SWS_SWIZZLE(X, Y, Z, W)
static int read_chunk(AVFormatContext *s)
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 exact_log2_q(const AVRational x)
static AVRational ff_sws_pixel_expand(SwsPixelType from, SwsPixelType to)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Rational number (pair of numerator and denominator).
#define av_unreachable(msg)
Asserts that are used as compiler optimization hints depending upon ASSERT_LEVEL and NBDEBUG.
int plane
Which of the 4 planes contains the component.
void ff_sws_op_list_remove_at(SwsOpList *ops, int index, int count)
#define RET(x)
Copyright (C) 2025 Niklas Haas.
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_apply_op_q(const SwsOp *op, AVRational x[4])
Apply an operation to an AVRational.
static bool op_type_is_independent(SwsOpType op)
static bool extract_constant_rows(SwsLinearOp *c, SwsComps prev, SwsConst *out_clear)
int ff_sws_op_list_insert_at(SwsOpList *ops, int index, SwsOp *op)
static bool extract_scalar(const SwsLinearOp *c, SwsComps prev, SwsComps next, SwsConst *out_scale)
If a linear operation can be reduced to a scalar multiplication, returns the corresponding scaling fa...
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
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
static unsigned merge_comp_flags(unsigned a, unsigned b)
#define i(width, name, range_min, range_max)
static bool extract_swizzle(SwsLinearOp *op, SwsComps prev, SwsSwizzleOp *out_swiz)
static const unsigned flags_identity
#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
static void write_bytes(const float *src, uint8_t *dst, int src_stride, int dst_stride, int width, int height, int depth, float scale)
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
#define FFSWAP(type, a, b)
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
int ff_sws_solve_shuffle(const SwsOpList *const ops, uint8_t shuffle[], int size, uint8_t clear_val, int *read_bytes, int *write_bytes)
"Solve" an op list into a fixed shuffle mask, with an optional ability to also directly clear the out...
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
static void scale(int *out, const int *in, const int w, const int h, const int shift)
AVRational av_add_q(AVRational b, AVRational c)
Add two rationals.
Helper struct for representing a list of operations.
static uint64_t shuffle(uint64_t in, const uint8_t *shuffle, int shuffle_len)
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)