FFmpeg
Loading...
Searching...
No Matches
ops.h File Reference
#include <assert.h>
#include <stdbool.h>
#include <stdalign.h>
#include "libavutil/bprint.h"
#include "graph.h"
#include "filters.h"
#include "lut3d.h"
#include "rational64.h"
#include "uops.h"

Go to the source code of this file.

Data Structures

struct  SwsReadWriteOp
 
struct  SwsPackOp
 
struct  SwsSwizzleOp
 
struct  SwsShiftOp
 
struct  SwsClearOp
 
struct  SwsConvertOp
 
struct  SwsClampOp
 
struct  SwsScaleOp
 
struct  SwsDitherOp
 
struct  SwsLinearOp
 
struct  SwsFilterOp
 
struct  SwsLut3dOp
 
struct  SwsOpPad
 
struct  SwsOp
 
struct  SwsOpList
 Helper struct for representing a list of operations. More...
 

Macros

#define SWS_SWIZZLE(X, Y, Z, W)
 
#define SWS_OP_NEEDED(op, idx)
 

Enumerations

enum  SwsOpType {
  SWS_OP_INVALID = 0 , SWS_OP_READ , SWS_OP_WRITE , SWS_OP_SWAP_BYTES ,
  SWS_OP_SWIZZLE , SWS_OP_UNPACK , SWS_OP_PACK , SWS_OP_LSHIFT ,
  SWS_OP_RSHIFT , SWS_OP_CLEAR , SWS_OP_CONVERT , SWS_OP_MIN ,
  SWS_OP_MAX , SWS_OP_SCALE , SWS_OP_LINEAR , SWS_OP_DITHER ,
  SWS_OP_FILTER_H , SWS_OP_FILTER_V , SWS_OP_LUT_3D , SWS_OP_TYPE_NB
}
 Copyright (C) 2025 Niklas Haas. More...
 
enum  SwsReadWriteMode { SWS_RW_PLANAR , SWS_RW_PACKED , SWS_RW_PALETTE }
 
enum  SwsCompFlags {
  SWS_COMP_EXACT = 1 << 0 , SWS_COMP_ZERO = 1 << 1 , SWS_COMP_SWAPPED = 1 << 2 , SWS_COMP_COPY = 1 << 3 ,
  SWS_COMP_CONST = 1 << 4
}
 

Functions

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)
 
uint32_t ff_sws_linear_mask (const SwsLinearOp *c)
 
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.
 
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.
 
SwsPixelType ff_sws_op_output_type (const SwsOp *op)
 
void ff_sws_op_desc (AVBPrint *bp, const SwsOp *op)
 Describe an operation in human-readable form.
 
void ff_sws_apply_op_q (const SwsOp *op, AVRational64 x[4])
 Apply an operation to an AVRational64.
 
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)
 
SwsOpList * ff_sws_op_list_alloc (void)
 
void ff_sws_op_list_free (SwsOpList **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.
 
bool ff_sws_op_list_is_noop (const SwsOpList *ops)
 Returns whether an op list represents a true no-op operation, i.e.
 
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.
 
int ff_sws_op_list_insert_at (SwsOpList *ops, int index, SwsOp *op)
 
void ff_sws_op_list_remove_at (SwsOpList *ops, int index, int count)
 
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.
 
void ff_sws_op_list_update (SwsOpList *ops)
 Infer + propagate known information about components.
 
int ff_sws_op_list_optimize (SwsOpList *ops)
 Fuse compatible and eliminate redundant operations, as well as replacing some operations with more efficient alternatives.
 

Macro Definition Documentation

◆ SWS_SWIZZLE

#define SWS_SWIZZLE ( X,
Y,
Z,
W )
Value:
((SwsSwizzleOp) { .in = {X, Y, Z, W} })
#define Y
Definition boxblur.h:37
#define X
Definition f_ebur128.c:158
#define W(a, i, v)
Definition jpegls.h:119
#define Z
Definition uops_tmpl.h:108

Definition at line 141 of file ops.h.

Referenced by extract_swizzle(), ff_sws_op_list_optimize(), ff_sws_op_list_split_at(), fmt_analyze_regular(), and select_planes().

◆ SWS_OP_NEEDED

#define SWS_OP_NEEDED ( op,
idx )
Value:
((op)->outputs[idx].dep_out != 0)
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.
Definition anm.c:76

Definition at line 282 of file ops.h.

Referenced by ff_sws_comp_mask_needed(), ff_sws_op_list_optimize(), ff_sws_op_list_split_at(), ff_sws_op_output_type(), ff_sws_ops_translate(), op_commute_swizzle(), op_result_is_exact(), translate_dither_op(), translate_linear_op(), translate_op(), and translate_swizzle().

Enumeration Type Documentation

◆ SwsOpType

enum SwsOpType

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

Enumerator
SWS_OP_INVALID 
SWS_OP_READ 
SWS_OP_WRITE 
SWS_OP_SWAP_BYTES 
SWS_OP_SWIZZLE 
SWS_OP_UNPACK 
SWS_OP_PACK 
SWS_OP_LSHIFT 
SWS_OP_RSHIFT 
SWS_OP_CLEAR 
SWS_OP_CONVERT 
SWS_OP_MIN 
SWS_OP_MAX 
SWS_OP_SCALE 
SWS_OP_LINEAR 
SWS_OP_DITHER 
SWS_OP_FILTER_H 
SWS_OP_FILTER_V 
SWS_OP_LUT_3D 
SWS_OP_TYPE_NB 

Definition at line 36 of file ops.h.

◆ SwsReadWriteMode

Enumerator
SWS_RW_PLANAR 

Note: 1-component reads are either SWS_RW_PLANAR or SWS_RW_PACKED, depending on the underlying interpretation.

If multiple components are packed into one element (e.g. rgb10a2 -> u16), they are marked as SWS_RW_PACKED. Otherwise (e.g. gray16le), they are SWS_RW_PLANAR.

This is a purely semantic/informative difference; the underlying code treats 1-components reads/writes the same regardless of mode.

SWS_RW_PACKED 
SWS_RW_PALETTE 

Definition at line 77 of file ops.h.

◆ SwsCompFlags

Enumerator
SWS_COMP_EXACT 
SWS_COMP_ZERO 
SWS_COMP_SWAPPED 
SWS_COMP_COPY 
SWS_COMP_CONST 

Definition at line 229 of file ops.h.

Function Documentation

◆ 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_linear_mask()

uint32_t ff_sws_linear_mask ( const SwsLinearOp * c)

◆ 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().

◆ 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().

◆ 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_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().

◆ 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().

◆ 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_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_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_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_insert_at()

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

◆ 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_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().

◆ 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().

◆ ff_sws_op_list_optimize()

int ff_sws_op_list_optimize ( SwsOpList * ops)

Fuse compatible and eliminate redundant operations, as well as replacing some operations with more efficient alternatives.

Definition at line 346 of file ops_optimizer.c.

Referenced by enum_ops_fmt(), ff_sws_compile_pass(), ff_sws_op_list_split_at(), and select_planes().