FFmpeg
Loading...
Searching...
No Matches
ops.c File Reference
#include "libavutil/attributes.h"
#include "libavutil/avassert.h"
#include "libavutil/avstring.h"
#include "libavutil/bprint.h"
#include "libavutil/bswap.h"
#include "libavutil/mem.h"
#include "libavutil/rational.h"
#include "libavutil/refstruct.h"
#include "format.h"
#include "ops.h"
#include "ops_internal.h"

Go to the source code of this file.

Macros

#define FORWARD(I, J, EXPR)
 
#define RESET(I)
 

Enumerations

enum  { SWS_COMP_IDENTITY , SWS_COMP_DIRTY = ~(SWS_COMP_COPY | SWS_COMP_CONST) }
 

Functions

const char * ff_sws_pixel_type_name (SwsPixelType type)
 
const char * ff_sws_op_type_name (SwsOpType op)
 
SwsCompMask ff_sws_comp_mask_q4 (const AVRational64 q[4])
 
void ff_sws_comp_mask_swizzle (SwsCompMask *mask, const SwsSwizzleOp *swiz)
 
SwsCompMask ff_sws_comp_mask_needed (const SwsOp *op)
 
int ff_sws_rw_op_planes (const SwsOp *op)
 Return the number of planes involved in a read/write operation.
 
static int op_index (const SwsOp *op)
 
const SwsOp * ff_sws_op_prev (const SwsOp *op)
 Return the previous/next operation in the list, or NULL if there is none.
 
const SwsOp * ff_sws_op_next (const SwsOp *op)
 
SwsPixelType ff_sws_op_output_type (const SwsOp *op)
 
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, or SWS_PIXEL_NONE if no type can be established.
 
static AVRational64 av_min_q64 (AVRational64 a, AVRational64 b)
 
static AVRational64 av_max_q64 (AVRational64 a, AVRational64 b)
 
void ff_sws_apply_op_q (const SwsOp *op, AVRational64 x[4])
 Apply an operation to an AVRational64.
 
static SwsCompFlags merge_comp_flags (SwsCompFlags a, SwsCompFlags b)
 
static void apply_filter_weights (SwsOpPad *pad, const SwsFilterWeights *weights)
 
static void update_output_pads (SwsOpList *ops, SwsOp *op)
 
static void update_input_pads (SwsOpList *ops, SwsOp *op, SwsCompMask need_out[4])
 
void ff_sws_op_list_update (SwsOpList *ops)
 Infer + propagate known information about components.
 
static void op_ref (SwsOp *op)
 
static void op_unref (SwsOp *op)
 
SwsOpList * ff_sws_op_list_alloc (void)
 
void ff_sws_op_list_free (SwsOpList **p_ops)
 
SwsOpList * ff_sws_op_list_duplicate (const SwsOpList *ops)
 Returns a duplicate of ops, or NULL on OOM.
 
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.
 
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_op_list_remove_at (SwsOpList *ops, int index, int count)
 
int ff_sws_op_list_insert_at (SwsOpList *ops, int index, SwsOp *op)
 
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.
 
bool ff_sws_op_list_is_noop (const SwsOpList *ops)
 Returns whether an op list represents a true no-op operation, i.e.
 
uint32_t ff_sws_linear_mask (const SwsLinearOp *c)
 
static const char * describe_comp_flags (SwsCompFlags flags)
 
static void print_deps (AVBPrint *bp, SwsCompMask dep)
 
static void print_q (AVBPrint *bp, const AVRational64 q)
 
static void print_q4 (AVBPrint *bp, const AVRational64 q4[4], SwsCompMask mask)
 
void ff_sws_op_desc (AVBPrint *bp, const SwsOp *op)
 Describe an operation in human-readable form.
 
static void desc_plane_order (AVBPrint *bp, int nb_planes, const uint8_t *order)
 
void ff_sws_op_list_print (void *log, int lev, int lev_extra, const SwsOpList *ops)
 Print out the contents of an operation list.
 

Variables

const SwsOpBackend backend_c
 Copyright (C) 2025 Niklas Haas.
 
const SwsOpBackend backend_murder
 
const SwsOpBackend backend_aarch64
 
const SwsOpBackend backend_x86
 
const SwsOpBackend *const ff_sws_op_backends []
 
static const char *const rw_mode_names []
 

Macro Definition Documentation

◆ FORWARD

#define FORWARD ( I,
J,
EXPR )
Value:
do { \
SwsOpPad *dst = &out[I]; \
const SwsOpPad *src = &in[J]; \
SwsCompFlags flags = src->flags; \
if (!src->type || dst->type && dst->type != src->type) \
invalid |= SWS_COMP(I); \
dst->flags = merge_comp_flags(dst->flags, (EXPR)); \
dst->dep_in |= src->dep_in; \
dst->type = src->type; \
} while (0)
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:97
static FILE * out
#define flags(name, subs,...)
Definition cbs_h264.c:74
static SwsCompFlags merge_comp_flags(SwsCompFlags a, SwsCompFlags b)
Definition ops.c:323
SwsCompFlags
Definition ops.h:229
#define src
Definition vp8dsp.c:248
#define SWS_COMP(X)
Definition uops.h:133

Referenced by update_output_pads().

◆ RESET

#define RESET ( I)
Value:
do { \
SwsOpPad *dst = &out[I]; \
dst->type = SWS_PIXEL_NONE; \
dst->flags = 0; \
dst->min = dst->max = (AVRational64) {0}; \
dst->dep_in = SWS_COMP_NONE; \
} while (0)
64-bit Rational number (pair of numerator and denominator).
Definition rational64.h:52
@ SWS_COMP_NONE
Definition uops.h:131
@ SWS_PIXEL_NONE
Definition uops.h:41

Referenced by update_output_pads().

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
SWS_COMP_IDENTITY 
SWS_COMP_DIRTY 

Definition at line 315 of file ops.c.

Function Documentation

◆ ff_sws_pixel_type_name()

const char * ff_sws_pixel_type_name ( SwsPixelType type)

Definition at line 56 of file ops.c.

Referenced by ff_sws_op_desc(), ff_sws_op_list_print(), and ff_sws_uop_name().

◆ ff_sws_op_type_name()

const char * ff_sws_op_type_name ( SwsOpType op)

Definition at line 71 of file ops.c.

Referenced by ff_sws_op_desc().

◆ ff_sws_comp_mask_q4()

SwsCompMask ff_sws_comp_mask_q4 ( const AVRational64 q[4])

Definition at line 100 of file ops.c.

Referenced by ff_sws_op_desc(), and translate_op().

◆ ff_sws_comp_mask_swizzle()

void ff_sws_comp_mask_swizzle ( SwsCompMask * mask,
const SwsSwizzleOp * swiz )

Definition at line 110 of file ops.c.

Referenced by op_commute_clear().

◆ ff_sws_comp_mask_needed()

SwsCompMask ff_sws_comp_mask_needed ( const SwsOp * op)

◆ ff_sws_rw_op_planes()

int ff_sws_rw_op_planes ( const SwsOp * op)

Return the number of planes involved in a read/write operation.

Definition at line 133 of file ops.c.

Referenced by compile_ops_memcpy(), ff_sws_op_list_is_noop(), ff_sws_op_list_print(), rw_data_planes(), rw_op_img_count(), and translate_rw_op().

◆ op_index()

static int op_index ( const SwsOp * op)
inlinestatic

◆ ff_sws_op_prev()

const SwsOp * ff_sws_op_prev ( const SwsOp * op)

Return the previous/next operation in the list, or NULL if there is none.

Definition at line 153 of file ops.c.

Referenced by compile_subpass(), ff_sws_op_input_type(), op_list_get_plane_copy(), and update_output_pads().

◆ ff_sws_op_next()

const SwsOp * ff_sws_op_next ( const SwsOp * op)

Definition at line 162 of file ops.c.

◆ ff_sws_op_output_type()

SwsPixelType ff_sws_op_output_type ( const SwsOp * op)

Definition at line 171 of file ops.c.

Referenced by ff_sws_op_input_type().

◆ ff_sws_op_input_type()

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, or SWS_PIXEL_NONE if no type can be established.

Definition at line 186 of file ops.c.

Referenced by ff_sws_apply_op_q(), ff_sws_op_desc(), ff_sws_op_list_optimize(), ff_sws_op_list_split_at(), op_commute_clear(), translate_dither_op(), translate_linear_op(), translate_op(), and translate_swizzle().

◆ av_min_q64()

static AVRational64 av_min_q64 ( AVRational64 a,
AVRational64 b )
static

Definition at line 192 of file ops.c.

Referenced by ff_sws_apply_op_q().

◆ av_max_q64()

static AVRational64 av_max_q64 ( AVRational64 a,
AVRational64 b )
static

Definition at line 197 of file ops.c.

Referenced by ff_sws_apply_op_q().

◆ ff_sws_apply_op_q()

void ff_sws_apply_op_q ( const SwsOp * op,
AVRational64 x[4] )

Apply an operation to an AVRational64.

No-op for read/write operations.

Definition at line 202 of file ops.c.

Referenced by op_commute_clear(), and update_output_pads().

◆ merge_comp_flags()

static SwsCompFlags merge_comp_flags ( SwsCompFlags a,
SwsCompFlags b )
static

Definition at line 323 of file ops.c.

◆ apply_filter_weights()

static void apply_filter_weights ( SwsOpPad * pad,
const SwsFilterWeights * weights )
static

Definition at line 330 of file ops.c.

Referenced by update_output_pads().

◆ update_output_pads()

static void update_output_pads ( SwsOpList * ops,
SwsOp * op )
static

Definition at line 345 of file ops.c.

Referenced by ff_sws_op_list_update().

◆ update_input_pads()

static void update_input_pads ( SwsOpList * ops,
SwsOp * op,
SwsCompMask need_out[4] )
static

Definition at line 612 of file ops.c.

Referenced by ff_sws_op_list_update().

◆ ff_sws_op_list_update()

void ff_sws_op_list_update ( SwsOpList * ops)

Infer + propagate known information about components.

Called automatically when needed by the optimizer and compiler.

Definition at line 677 of file ops.c.

Referenced by add_ops_convert_pass(), compile_backend(), and ff_sws_op_list_optimize().

◆ op_ref()

static void op_ref ( SwsOp * op)
static

Definition at line 689 of file ops.c.

Referenced by ff_sws_op_list_duplicate().

◆ op_unref()

static void op_unref ( SwsOp * op)
static

Definition at line 709 of file ops.c.

Referenced by ff_sws_op_list_free(), ff_sws_op_list_insert_at(), and ff_sws_op_list_remove_at().

◆ ff_sws_op_list_alloc()

SwsOpList * ff_sws_op_list_alloc ( void )

Definition at line 730 of file ops.c.

Referenced by ff_sws_op_list_generate().

◆ ff_sws_op_list_free()

◆ ff_sws_op_list_duplicate()

SwsOpList * ff_sws_op_list_duplicate ( const SwsOpList * ops)

Returns a duplicate of ops, or NULL on OOM.

Definition at line 757 of file ops.c.

Referenced by compile_backend(), ff_sws_op_list_split_at(), ff_sws_op_list_split_planes(), print_passes(), register_all_uops(), and register_op().

◆ ff_sws_op_list_input()

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.

for a pure CLEAR-only operation list).

This will always be an op of type SWS_OP_READ.

Definition at line 782 of file ops.c.

Referenced by compile_single(), define_shader_bindings(), emit_shader(), ff_sws_op_list_is_noop(), get_input_size(), and op_list_get_plane_copy().

◆ ff_sws_op_list_output()

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.

This will always be an op of type SWS_OP_WRITE.

Definition at line 791 of file ops.c.

Referenced by compile_single(), compile_subpass(), define_shader_bindings(), emit_shader(), ff_sws_compile_pass(), ff_sws_op_list_is_noop(), ff_sws_op_list_split_planes(), and op_list_get_plane_copy().

◆ ff_sws_op_list_remove_at()

void ff_sws_op_list_remove_at ( SwsOpList * ops,
int index,
int count )

Definition at line 800 of file ops.c.

Referenced by ff_sws_op_list_optimize(), and ff_sws_op_list_split_at().

◆ ff_sws_op_list_insert_at()

int ff_sws_op_list_insert_at ( SwsOpList * ops,
int index,
SwsOp * op )

◆ ff_sws_op_list_append()

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.

Definition at line 826 of file ops.c.

Referenced by add_filter(), apply_lut3d(), decode_colors(), decode_pixfmt(), encode_colors(), encode_pixfmt(), ff_sws_op_list_split_at(), and fmt_dither().

◆ ff_sws_op_list_is_noop()

bool ff_sws_op_list_is_noop ( const SwsOpList * ops)

Returns whether an op list represents a true no-op operation, i.e.

may be eliminated entirely from an execution graph.

Note that this check is unlikely to ever be hit in practice, since it would imply the existence of planar formats with different plane orders between them, e.g. rgbap <-> gbrap, which doesn't currently exist. However, the check is cheap and lets me sleep at night.

Definition at line 831 of file ops.c.

Referenced by compile_subpass(), ff_sws_compile_pass(), and print_passes().

◆ ff_sws_linear_mask()

uint32_t ff_sws_linear_mask ( const SwsLinearOp * c)

◆ describe_comp_flags()

static const char * describe_comp_flags ( SwsCompFlags flags)
static

Definition at line 873 of file ops.c.

Referenced by ff_sws_op_list_print().

◆ print_deps()

static void print_deps ( AVBPrint * bp,
SwsCompMask dep )
static

Definition at line 889 of file ops.c.

Referenced by ff_sws_op_list_print().

◆ print_q()

static void print_q ( AVBPrint * bp,
const AVRational64 q )
static

Definition at line 898 of file ops.c.

◆ print_q4()

static void print_q4 ( AVBPrint * bp,
const AVRational64 q4[4],
SwsCompMask mask )
static

Definition at line 911 of file ops.c.

Referenced by ff_sws_op_desc().

◆ ff_sws_op_desc()

void ff_sws_op_desc ( AVBPrint * bp,
const SwsOp * op )

Describe an operation in human-readable form.

Definition at line 932 of file ops.c.

Referenced by ff_sws_op_list_print().

◆ desc_plane_order()

static void desc_plane_order ( AVBPrint * bp,
int nb_planes,
const uint8_t * order )
static

Definition at line 1027 of file ops.c.

Referenced by ff_sws_op_list_print().

◆ ff_sws_op_list_print()

void ff_sws_op_list_print ( void * log_ctx,
int log_level,
int log_level_extra,
const SwsOpList * ops )

Print out the contents of an operation list.

Note: This requires having called ff_sws_op_list_update() to refresh the output pads, or the output may be stale/missing.

Definition at line 1041 of file ops.c.

Referenced by add_ops_convert_pass(), compile_backend(), compile_subpass(), ff_sws_compile_pass(), and print_ops().

Variable Documentation

◆ backend_c

const SwsOpBackend backend_c
extern

Copyright (C) 2025 Niklas Haas.

This file is part of FFmpeg.

FFmpeg is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

FFmpeg is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with FFmpeg; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

Definition at line 195 of file uops_backend.c.

◆ backend_murder

const SwsOpBackend backend_murder
extern

Definition at line 162 of file ops_memcpy.c.

◆ backend_aarch64

const SwsOpBackend backend_aarch64
extern

Definition at line 252 of file ops.c.

◆ backend_x86

const SwsOpBackend backend_x86
extern

Definition at line 736 of file ops.c.

◆ ff_sws_op_backends

const SwsOpBackend* const ff_sws_op_backends[]
Initial value:
= {
}
#define NULL
Definition coverity.c:32
const SwsOpBackend backend_c
Copyright (C) 2025 Niklas Haas.
const SwsOpBackend backend_murder
Definition ops_memcpy.c:162

Definition at line 42 of file ops.c.

Referenced by ff_sws_ops_compile(), and run_test().

◆ rw_mode_names

const char* const rw_mode_names[]
static
Initial value:
= {
[SWS_RW_PLANAR] = "planar",
[SWS_RW_PACKED] = "packed",
[SWS_RW_PALETTE] = "palette"
}
@ SWS_RW_PALETTE
Definition ops.h:89
@ SWS_RW_PLANAR
Note: 1-component reads are either SWS_RW_PLANAR or SWS_RW_PACKED, depending on the underlying interp...
Definition ops.h:87
@ SWS_RW_PACKED
Definition ops.h:88

Definition at line 926 of file ops.c.

Referenced by ff_sws_op_desc().