FFmpeg
Data Structures | Macros | Enumerations | Functions
ops.h File Reference
#include <assert.h>
#include <stdbool.h>
#include <stdalign.h>
#include "graph.h"

Go to the source code of this file.

Data Structures

union  SwsConst
 
struct  SwsComps
 
struct  SwsReadWriteOp
 
struct  SwsPackOp
 
struct  SwsSwizzleOp
 
struct  SwsConvertOp
 
struct  SwsDitherOp
 
struct  SwsLinearOp
 
struct  SwsOp
 
struct  SwsOpList
 Helper struct for representing a list of operations. More...
 

Macros

#define SWS_SWIZZLE(X, Y, Z, W)   ((SwsSwizzleOp) { .in = {X, Y, Z, W} })
 
#define SWS_MASK(I, J)   (1 << (5 * (I) + (J)))
 
#define SWS_MASK_OFF(I)   SWS_MASK(I, 4)
 
#define SWS_MASK_ROW(I)   (0x1F << (5 * (I)))
 
#define SWS_MASK_COL(J)   (0x8421 << J)
 

Enumerations

enum  SwsPixelType {
  SWS_PIXEL_NONE = 0, SWS_PIXEL_U8, SWS_PIXEL_U16, SWS_PIXEL_U32,
  SWS_PIXEL_F32, SWS_PIXEL_TYPE_NB
}
 Copyright (C) 2025 Niklas Haas. More...
 
enum  SwsOpType {
  SWS_OP_INVALID = 0, SWS_OP_READ, SWS_OP_WRITE, SWS_OP_SWAP_BYTES,
  SWS_OP_UNPACK, SWS_OP_PACK, SWS_OP_CLEAR, SWS_OP_LSHIFT,
  SWS_OP_RSHIFT, SWS_OP_SWIZZLE, SWS_OP_CONVERT, SWS_OP_DITHER,
  SWS_OP_LINEAR, SWS_OP_SCALE, SWS_OP_MIN, SWS_OP_MAX,
  SWS_OP_TYPE_NB
}
 
enum  SwsCompFlags { SWS_COMP_GARBAGE = 1 << 0, SWS_COMP_EXACT = 1 << 1, SWS_COMP_ZERO = 1 << 2 }
 
enum  {
  SWS_MASK_ALL = (1 << 20) - 1, SWS_MASK_LUMA = SWS_MASK(0, 0) | SWS_MASK_OFF(0), SWS_MASK_ALPHA = SWS_MASK(3, 3) | SWS_MASK_OFF(3), SWS_MASK_DIAG3 = SWS_MASK(0, 0) | SWS_MASK(1, 1) | SWS_MASK(2, 2),
  SWS_MASK_OFF3 = SWS_MASK_OFF(0) | SWS_MASK_OFF(1) | SWS_MASK_OFF(2), SWS_MASK_MAT3, SWS_MASK_DIAG4 = SWS_MASK_DIAG3 | SWS_MASK(3, 3), SWS_MASK_OFF4 = SWS_MASK_OFF3 | SWS_MASK_OFF(3),
  SWS_MASK_MAT4 = SWS_MASK_ALL & ~SWS_MASK_OFF4
}
 
enum  SwsOpCompileFlags { SWS_OP_FLAG_OPTIMIZE = 1 << 0 }
 

Functions

const char * ff_sws_pixel_type_name (SwsPixelType type)
 
int ff_sws_pixel_type_size (SwsPixelType type) av_const
 
bool ff_sws_pixel_type_is_int (SwsPixelType type) av_const
 
SwsPixelType ff_sws_pixel_type_to_uint (SwsPixelType type) av_const
 
uint32_t ff_sws_linear_mask (SwsLinearOp)
 
void ff_sws_op_uninit (SwsOp *op)
 Frees any allocations associated with an SwsOp and sets it to {0}. More...
 
void ff_sws_apply_op_q (const SwsOp *op, AVRational x[4])
 Apply an operation to an AVRational. More...
 
SwsOpListff_sws_op_list_alloc (void)
 
void ff_sws_op_list_free (SwsOpList **ops)
 
SwsOpListff_sws_op_list_duplicate (const SwsOpList *ops)
 Returns a duplicate of ops, or NULL on OOM. More...
 
int ff_sws_op_list_max_size (const SwsOpList *ops)
 Returns the size of the largest pixel type used in ops. More...
 
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. More...
 
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, const SwsOpList *ops)
 Print out the contents of an operation list. More...
 
void ff_sws_op_list_update_comps (SwsOpList *ops)
 Infer + propagate known information about components. More...
 
int ff_sws_op_list_optimize (SwsOpList *ops)
 Fuse compatible and eliminate redundant operations, as well as replacing some operations with more efficient alternatives. More...
 
int ff_sws_compile_pass (SwsGraph *graph, SwsOpList *ops, int flags, SwsFormat dst, SwsPass *input, SwsPass **output)
 Resolves an operation list to a graph pass. More...
 

Macro Definition Documentation

◆ SWS_SWIZZLE

#define SWS_SWIZZLE (   X,
  Y,
  Z,
  W 
)    ((SwsSwizzleOp) { .in = {X, Y, Z, W} })

Definition at line 126 of file ops.h.

◆ SWS_MASK

#define SWS_MASK (   I,
 
)    (1 << (5 * (I) + (J)))

Definition at line 155 of file ops.h.

◆ SWS_MASK_OFF

#define SWS_MASK_OFF (   I)    SWS_MASK(I, 4)

Definition at line 156 of file ops.h.

◆ SWS_MASK_ROW

#define SWS_MASK_ROW (   I)    (0x1F << (5 * (I)))

Definition at line 157 of file ops.h.

◆ SWS_MASK_COL

#define SWS_MASK_COL (   J)    (0x8421 << J)

Definition at line 158 of file ops.h.

Enumeration Type Documentation

◆ SwsPixelType

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_PIXEL_NONE 
SWS_PIXEL_U8 
SWS_PIXEL_U16 
SWS_PIXEL_U32 
SWS_PIXEL_F32 
SWS_PIXEL_TYPE_NB 

Definition at line 30 of file ops.h.

◆ SwsOpType

enum SwsOpType
Enumerator
SWS_OP_INVALID 
SWS_OP_READ 
SWS_OP_WRITE 
SWS_OP_SWAP_BYTES 
SWS_OP_UNPACK 
SWS_OP_PACK 
SWS_OP_CLEAR 
SWS_OP_LSHIFT 
SWS_OP_RSHIFT 
SWS_OP_SWIZZLE 
SWS_OP_CONVERT 
SWS_OP_DITHER 
SWS_OP_LINEAR 
SWS_OP_SCALE 
SWS_OP_MIN 
SWS_OP_MAX 
SWS_OP_TYPE_NB 

Definition at line 44 of file ops.h.

◆ SwsCompFlags

Enumerator
SWS_COMP_GARBAGE 
SWS_COMP_EXACT 
SWS_COMP_ZERO 

Definition at line 71 of file ops.h.

◆ anonymous enum

anonymous enum
Enumerator
SWS_MASK_ALL 
SWS_MASK_LUMA 
SWS_MASK_ALPHA 
SWS_MASK_DIAG3 
SWS_MASK_OFF3 
SWS_MASK_MAT3 
SWS_MASK_DIAG4 
SWS_MASK_OFF4 
SWS_MASK_MAT4 

Definition at line 160 of file ops.h.

◆ SwsOpCompileFlags

Enumerator
SWS_OP_FLAG_OPTIMIZE 

Definition at line 255 of file ops.h.

Function Documentation

◆ ff_sws_pixel_type_name()

const char* ff_sws_pixel_type_name ( SwsPixelType  type)

◆ ff_sws_pixel_type_size()

int ff_sws_pixel_type_size ( SwsPixelType  type) const

◆ ff_sws_pixel_type_is_int()

bool ff_sws_pixel_type_is_int ( SwsPixelType  type) const

◆ ff_sws_pixel_type_to_uint()

SwsPixelType ff_sws_pixel_type_to_uint ( SwsPixelType  type) const

Definition at line 96 of file ops.c.

◆ ff_sws_linear_mask()

uint32_t ff_sws_linear_mask ( SwsLinearOp  )

Definition at line 328 of file ops.c.

Referenced by extract_swizzle(), and ff_sws_op_list_optimize().

◆ ff_sws_op_uninit()

void ff_sws_op_uninit ( SwsOp op)

Frees any allocations associated with an SwsOp and sets it to {0}.

◆ ff_sws_apply_op_q()

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

Apply an operation to an AVRational.

No-op for read/write operations.

Definition at line 122 of file ops.c.

Referenced by ff_sws_op_list_optimize(), and ff_sws_op_list_update_comps().

◆ ff_sws_op_list_alloc()

SwsOpList* ff_sws_op_list_alloc ( void  )

Definition at line 234 of file ops.c.

◆ ff_sws_op_list_free()

void ff_sws_op_list_free ( SwsOpList **  ops)

Definition at line 245 of file ops.c.

◆ 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 259 of file ops.c.

◆ ff_sws_op_list_max_size()

int ff_sws_op_list_max_size ( const SwsOpList ops)

Returns the size of the largest pixel type used in ops.

Definition at line 317 of file ops.c.

Referenced by compile().

◆ 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 312 of file ops.c.

◆ ff_sws_op_list_insert_at()

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

Definition at line 298 of file ops.c.

Referenced by ff_sws_op_list_append(), and ff_sws_op_list_optimize().

◆ ff_sws_op_list_remove_at()

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

Definition at line 288 of file ops.c.

Referenced by ff_sws_op_list_optimize().

◆ ff_sws_op_list_print()

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

Print out the contents of an operation list.

Definition at line 411 of file ops.c.

◆ ff_sws_op_list_update_comps()

void ff_sws_op_list_update_comps ( SwsOpList ops)

Infer + propagate known information about components.

Called automatically when needed by the optimizer and compiler.

Definition at line 75 of file ops_optimizer.c.

Referenced by 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 412 of file ops_optimizer.c.

◆ ff_sws_compile_pass()

int ff_sws_compile_pass ( SwsGraph graph,
SwsOpList ops,
int  flags,
SwsFormat  dst,
SwsPass input,
SwsPass **  output 
)

Resolves an operation list to a graph pass.

The first and last operations must be a read/write respectively. flags is a list of SwsOpCompileFlags.

Note: ops may be modified by this function.