FFmpeg
Data Structures | Macros | Enumerations | Functions | Variables
vf_colormatrix.c File Reference
#include <float.h>
#include "avfilter.h"
#include "internal.h"
#include "video.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"

Go to the source code of this file.

Data Structures

struct  ColorMatrixContext
 
struct  ThreadData
 Used for passing data between threads. More...
 

Macros

#define NS(n)   ((n) < 0 ? (int)((n)*65536.0-0.5+DBL_EPSILON) : (int)((n)*65536.0+0.5))
 
#define CB(n)   av_clip_uint8(n)
 
#define OFFSET(x)   offsetof(ColorMatrixContext, x)
 
#define FLAGS   AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
 
#define ma   m[0][0]
 
#define mb   m[0][1]
 
#define mc   m[0][2]
 
#define md   m[1][0]
 
#define me   m[1][1]
 
#define mf   m[1][2]
 
#define mg   m[2][0]
 
#define mh   m[2][1]
 
#define mi   m[2][2]
 
#define ima   im[0][0]
 
#define imb   im[0][1]
 
#define imc   im[0][2]
 
#define imd   im[1][0]
 
#define ime   im[1][1]
 
#define imf   im[1][2]
 
#define img   im[2][0]
 
#define imh   im[2][1]
 
#define imi   im[2][2]
 

Enumerations

enum  ColorMode {
  CHANNEL, INTENSITY, RAINBOW, MORELAND,
  NEBULAE, FIRE, FIERY, FRUIT,
  COOL, MAGMA, GREEN, VIRIDIS,
  PLASMA, CIVIDIS, TERRAIN, NB_CLMODES,
  COLOR_MODE_NONE = -1, COLOR_MODE_BT709, COLOR_MODE_FCC, COLOR_MODE_BT601,
  COLOR_MODE_SMPTE240M, COLOR_MODE_BT2020, COLOR_MODE_COUNT
}
 

Functions

 AVFILTER_DEFINE_CLASS (colormatrix)
 
static void inverse3x3 (double im[3][3], double m[3][3])
 
static void solve_coefficients (double cm[3][3], double rgb[3][3], double yuv[3][3])
 
static void calc_coefficients (AVFilterContext *ctx)
 
static av_cold int init (AVFilterContext *ctx)
 
static int process_slice_uyvy422 (AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
 
static int process_slice_yuv444p (AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
 
static int process_slice_yuv422p (AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
 
static int process_slice_yuv420p (AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
 
static int config_input (AVFilterLink *inlink)
 
static int filter_frame (AVFilterLink *link, AVFrame *in)
 

Variables

static const double yuv_coeff_luma [5][3]
 
static const AVOption colormatrix_options []
 
static const char *const color_modes [] = {"bt709", "fcc", "bt601", "smpte240m", "bt2020"}
 
static const AVFilterPad colormatrix_inputs []
 
const AVFilter ff_vf_colormatrix
 

Detailed Description

ColorMatrix 2.0 is based on the original ColorMatrix filter by Wilbert Dijkhof. It adds the ability to convert between any of: Rec.709, FCC, Rec.601, and SMPTE 240M. It also makes pre and post clipping optional, adds an option to use scaled or non-scaled coefficients, and more...

Definition in file vf_colormatrix.c.

Macro Definition Documentation

◆ NS

#define NS (   n)    ((n) < 0 ? (int)((n)*65536.0-0.5+DBL_EPSILON) : (int)((n)*65536.0+0.5))

Definition at line 38 of file vf_colormatrix.c.

◆ CB

#define CB (   n)    av_clip_uint8(n)

Definition at line 39 of file vf_colormatrix.c.

◆ OFFSET

#define OFFSET (   x)    offsetof(ColorMatrixContext, x)

Definition at line 79 of file vf_colormatrix.c.

◆ FLAGS

Definition at line 80 of file vf_colormatrix.c.

◆ ma

#define ma   m[0][0]

Definition at line 98 of file vf_colormatrix.c.

◆ mb

#define mb   m[0][1]

Definition at line 99 of file vf_colormatrix.c.

◆ mc

#define mc   m[0][2]

Definition at line 100 of file vf_colormatrix.c.

◆ md

#define md   m[1][0]

Definition at line 101 of file vf_colormatrix.c.

◆ me

#define me   m[1][1]

Definition at line 102 of file vf_colormatrix.c.

◆ mf

#define mf   m[1][2]

Definition at line 103 of file vf_colormatrix.c.

◆ mg

#define mg   m[2][0]

Definition at line 104 of file vf_colormatrix.c.

◆ mh

#define mh   m[2][1]

Definition at line 105 of file vf_colormatrix.c.

◆ mi

#define mi   m[2][2]

Definition at line 106 of file vf_colormatrix.c.

◆ ima

#define ima   im[0][0]

Definition at line 108 of file vf_colormatrix.c.

◆ imb

#define imb   im[0][1]

Definition at line 109 of file vf_colormatrix.c.

◆ imc

#define imc   im[0][2]

Definition at line 110 of file vf_colormatrix.c.

◆ imd

#define imd   im[1][0]

Definition at line 111 of file vf_colormatrix.c.

◆ ime

#define ime   im[1][1]

Definition at line 112 of file vf_colormatrix.c.

◆ imf

#define imf   im[1][2]

Definition at line 113 of file vf_colormatrix.c.

◆ img

#define img   im[2][0]

Definition at line 114 of file vf_colormatrix.c.

◆ imh

#define imh   im[2][1]

Definition at line 115 of file vf_colormatrix.c.

◆ imi

#define imi   im[2][2]

Definition at line 116 of file vf_colormatrix.c.

Enumeration Type Documentation

◆ ColorMode

enum ColorMode
Enumerator
CHANNEL 
INTENSITY 
RAINBOW 
MORELAND 
NEBULAE 
FIRE 
FIERY 
FRUIT 
COOL 
MAGMA 
GREEN 
VIRIDIS 
PLASMA 
CIVIDIS 
TERRAIN 
NB_CLMODES 
COLOR_MODE_NONE 
COLOR_MODE_BT709 
COLOR_MODE_FCC 
COLOR_MODE_BT601 
COLOR_MODE_SMPTE240M 
COLOR_MODE_BT2020 
COLOR_MODE_COUNT 

Definition at line 49 of file vf_colormatrix.c.

Function Documentation

◆ AVFILTER_DEFINE_CLASS()

AVFILTER_DEFINE_CLASS ( colormatrix  )

◆ inverse3x3()

static void inverse3x3 ( double  im[3][3],
double  m[3][3] 
)
static

Definition at line 118 of file vf_colormatrix.c.

Referenced by calc_coefficients().

◆ solve_coefficients()

static void solve_coefficients ( double  cm[3][3],
double  rgb[3][3],
double  yuv[3][3] 
)
static

Definition at line 133 of file vf_colormatrix.c.

Referenced by calc_coefficients().

◆ calc_coefficients()

static void calc_coefficients ( AVFilterContext ctx)
static

Definition at line 141 of file vf_colormatrix.c.

Referenced by init().

◆ init()

static av_cold int init ( AVFilterContext ctx)
static

Definition at line 184 of file vf_colormatrix.c.

◆ process_slice_uyvy422()

static int process_slice_uyvy422 ( AVFilterContext ctx,
void *  arg,
int  jobnr,
int  nb_jobs 
)
static

Definition at line 203 of file vf_colormatrix.c.

Referenced by filter_frame().

◆ process_slice_yuv444p()

static int process_slice_yuv444p ( AVFilterContext ctx,
void *  arg,
int  jobnr,
int  nb_jobs 
)
static

Definition at line 241 of file vf_colormatrix.c.

Referenced by filter_frame().

◆ process_slice_yuv422p()

static int process_slice_yuv422p ( AVFilterContext ctx,
void *  arg,
int  jobnr,
int  nb_jobs 
)
static

Definition at line 288 of file vf_colormatrix.c.

Referenced by filter_frame().

◆ process_slice_yuv420p()

static int process_slice_yuv420p ( AVFilterContext ctx,
void *  arg,
int  jobnr,
int  nb_jobs 
)
static

Definition at line 336 of file vf_colormatrix.c.

Referenced by filter_frame().

◆ config_input()

static int config_input ( AVFilterLink inlink)
static

Definition at line 390 of file vf_colormatrix.c.

◆ filter_frame()

static int filter_frame ( AVFilterLink link,
AVFrame in 
)
static

Definition at line 405 of file vf_colormatrix.c.

Variable Documentation

◆ yuv_coeff_luma

const double yuv_coeff_luma[5][3]
static
Initial value:
= {
{ +0.7152, +0.0722, +0.2126 },
{ +0.5900, +0.1100, +0.3000 },
{ +0.5870, +0.1140, +0.2990 },
{ +0.7010, +0.0870, +0.2120 },
{ +0.6780, +0.0593, +0.2627 },
}

Definition at line 41 of file vf_colormatrix.c.

Referenced by calc_coefficients().

◆ colormatrix_options

const AVOption colormatrix_options[]
static
Initial value:
= {
{ "src", "set source color matrix", OFFSET(source), AV_OPT_TYPE_INT, {.i64=COLOR_MODE_NONE}, COLOR_MODE_NONE, COLOR_MODE_COUNT-1, .flags=FLAGS, .unit="color_mode" },
{ "dst", "set destination color matrix", OFFSET(dest), AV_OPT_TYPE_INT, {.i64=COLOR_MODE_NONE}, COLOR_MODE_NONE, COLOR_MODE_COUNT-1, .flags=FLAGS, .unit="color_mode" },
{ "bt709", "set BT.709 colorspace", 0, AV_OPT_TYPE_CONST, {.i64=COLOR_MODE_BT709}, .flags=FLAGS, .unit="color_mode" },
{ "fcc", "set FCC colorspace ", 0, AV_OPT_TYPE_CONST, {.i64=COLOR_MODE_FCC}, .flags=FLAGS, .unit="color_mode" },
{ "bt601", "set BT.601 colorspace", 0, AV_OPT_TYPE_CONST, {.i64=COLOR_MODE_BT601}, .flags=FLAGS, .unit="color_mode" },
{ "bt470", "set BT.470 colorspace", 0, AV_OPT_TYPE_CONST, {.i64=COLOR_MODE_BT601}, .flags=FLAGS, .unit="color_mode" },
{ "bt470bg", "set BT.470 colorspace", 0, AV_OPT_TYPE_CONST, {.i64=COLOR_MODE_BT601}, .flags=FLAGS, .unit="color_mode" },
{ "smpte170m", "set SMTPE-170M colorspace", 0, AV_OPT_TYPE_CONST, {.i64=COLOR_MODE_BT601}, .flags=FLAGS, .unit="color_mode" },
{ "smpte240m", "set SMPTE-240M colorspace", 0, AV_OPT_TYPE_CONST, {.i64=COLOR_MODE_SMPTE240M}, .flags=FLAGS, .unit="color_mode" },
{ "bt2020", "set BT.2020 colorspace", 0, AV_OPT_TYPE_CONST, {.i64=COLOR_MODE_BT2020}, .flags=FLAGS, .unit="color_mode" },
{ NULL }
}

Definition at line 82 of file vf_colormatrix.c.

◆ color_modes

const char* const color_modes[] = {"bt709", "fcc", "bt601", "smpte240m", "bt2020"}
static

Definition at line 182 of file vf_colormatrix.c.

Referenced by config_input().

◆ colormatrix_inputs

const AVFilterPad colormatrix_inputs[]
static
Initial value:
= {
{
.name = "default",
.config_props = config_input,
.filter_frame = filter_frame,
},
}

Definition at line 475 of file vf_colormatrix.c.

◆ ff_vf_colormatrix

const AVFilter ff_vf_colormatrix
Initial value:

Definition at line 484 of file vf_colormatrix.c.

COLOR_MODE_COUNT
@ COLOR_MODE_COUNT
Definition: vf_colormatrix.c:56
colormatrix_inputs
static const AVFilterPad colormatrix_inputs[]
Definition: vf_colormatrix.c:475
ff_video_default_filterpad
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.
Definition: video.c:37
filter_frame
static int filter_frame(AVFilterLink *link, AVFrame *in)
Definition: vf_colormatrix.c:405
COLOR_MODE_FCC
@ COLOR_MODE_FCC
Definition: vf_colormatrix.c:52
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:73
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:182
NULL
#define NULL
Definition: coverity.c:32
COLOR_MODE_SMPTE240M
@ COLOR_MODE_SMPTE240M
Definition: vf_colormatrix.c:54
source
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a source
Definition: filter_design.txt:255
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:106
FILTER_PIXFMTS
#define FILTER_PIXFMTS(...)
Definition: internal.h:168
config_input
static int config_input(AVFilterLink *inlink)
Definition: vf_colormatrix.c:390
AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
Definition: avfilter.h:147
COLOR_MODE_BT709
@ COLOR_MODE_BT709
Definition: vf_colormatrix.c:51
init
static av_cold int init(AVFilterContext *ctx)
Definition: vf_colormatrix.c:184
COLOR_MODE_BT601
@ COLOR_MODE_BT601
Definition: vf_colormatrix.c:53
AV_PIX_FMT_UYVY422
@ AV_PIX_FMT_UYVY422
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
Definition: pixfmt.h:88
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:235
COLOR_MODE_NONE
@ COLOR_MODE_NONE
Definition: vf_colormatrix.c:50
AV_PIX_FMT_YUV444P
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:78
ColorMatrixContext
Definition: vf_colormatrix.c:59
AVFILTER_FLAG_SLICE_THREADS
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:117
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AV_PIX_FMT_YUV422P
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:77
COLOR_MODE_BT2020
@ COLOR_MODE_BT2020
Definition: vf_colormatrix.c:55
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:183
FLAGS
#define FLAGS
Definition: vf_colormatrix.c:80
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:244
OFFSET
#define OFFSET(x)
Definition: vf_colormatrix.c:79