FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Enumerations | Functions | Variables
vf_colormatrix.c File Reference

ColorMatrix 2.0 is based on the original ColorMatrix filter by Wilbert Dijkhof. More...

#include <float.h>
#include "avfilter.h"
#include "formats.h"
#include "internal.h"
#include "video.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "libavutil/avstring.h"

Go to the source code of this file.

Data Structures

struct  ColorMatrixContext
 
struct  ThreadData
 

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, NB_CLMODES, COLOR_MODE_NONE = -1,
  COLOR_MODE_BT709, COLOR_MODE_FCC, COLOR_MODE_BT601, COLOR_MODE_SMPTE240M,
  COLOR_MODE_COUNT
}
 

Functions

 AVFILTER_DEFINE_CLASS (colormatrix)
 
static void inverse3x3 (double im[3][3], const double m[3][3])
 
static void solve_coefficients (double cm[3][3], double rgb[3][3], const 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_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 query_formats (AVFilterContext *ctx)
 
static int filter_frame (AVFilterLink *link, AVFrame *in)
 

Variables

static const double yuv_coeff [4][3][3]
 
static const AVOption colormatrix_options []
 
static const char *const color_modes [] = {"bt709", "fcc", "bt601", "smpte240m"}
 
static const AVFilterPad colormatrix_inputs []
 
static const AVFilterPad colormatrix_outputs []
 
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

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

Definition at line 40 of file vf_colormatrix.c.

Referenced by calc_coefficients().

#define CB (   n)    av_clip_uint8(n)
#define OFFSET (   x)    offsetof(ColorMatrixContext, x)

Definition at line 87 of file vf_colormatrix.c.

Definition at line 88 of file vf_colormatrix.c.

#define ma   m[0][0]

Definition at line 104 of file vf_colormatrix.c.

Referenced by inverse3x3().

#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]

Definition at line 109 of file vf_colormatrix.c.

Referenced by inverse3x3().

#define mg   m[2][0]

Definition at line 110 of file vf_colormatrix.c.

Referenced by inverse3x3().

#define mh   m[2][1]
#define mi   m[2][2]

Definition at line 112 of file vf_colormatrix.c.

Referenced by inverse3x3().

#define ima   im[0][0]

Definition at line 114 of file vf_colormatrix.c.

Referenced by adpcm_compress_trellis(), and inverse3x3().

#define imb   im[0][1]

Definition at line 115 of file vf_colormatrix.c.

Referenced by inverse3x3().

#define imc   im[0][2]

Definition at line 116 of file vf_colormatrix.c.

Referenced by avcodec_register_all(), and inverse3x3().

#define imd   im[1][0]

Definition at line 117 of file vf_colormatrix.c.

Referenced by inverse3x3().

#define ime   im[1][1]

Definition at line 118 of file vf_colormatrix.c.

Referenced by inverse3x3().

#define imf   im[1][2]

Definition at line 119 of file vf_colormatrix.c.

Referenced by inverse3x3().

#define img   im[2][0]
#define imh   im[2][1]

Definition at line 121 of file vf_colormatrix.c.

Referenced by inverse3x3().

#define imi   im[2][2]

Definition at line 122 of file vf_colormatrix.c.

Referenced by inverse3x3().

Enumeration Type Documentation

enum ColorMode
Enumerator
CHANNEL 
INTENSITY 
NB_CLMODES 
COLOR_MODE_NONE 
COLOR_MODE_BT709 
COLOR_MODE_FCC 
COLOR_MODE_BT601 
COLOR_MODE_SMPTE240M 
COLOR_MODE_COUNT 

Definition at line 58 of file vf_colormatrix.c.

Function Documentation

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

Definition at line 124 of file vf_colormatrix.c.

Referenced by calc_coefficients().

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

Definition at line 139 of file vf_colormatrix.c.

Referenced by calc_coefficients().

static void calc_coefficients ( AVFilterContext ctx)
static

Definition at line 147 of file vf_colormatrix.c.

Referenced by init().

static av_cold int init ( AVFilterContext ctx)
static

Definition at line 176 of file vf_colormatrix.c.

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

Definition at line 195 of file vf_colormatrix.c.

Referenced by filter_frame().

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

Definition at line 233 of file vf_colormatrix.c.

Referenced by filter_frame().

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

Definition at line 281 of file vf_colormatrix.c.

Referenced by filter_frame().

static int config_input ( AVFilterLink inlink)
static

Definition at line 335 of file vf_colormatrix.c.

static int query_formats ( AVFilterContext ctx)
static

Definition at line 350 of file vf_colormatrix.c.

static int filter_frame ( AVFilterLink link,
AVFrame in 
)
static

Definition at line 364 of file vf_colormatrix.c.

Variable Documentation

const double yuv_coeff[4][3][3]
static
Initial value:
= {
{ { +0.7152, +0.0722, +0.2126 },
{ -0.3850, +0.5000, -0.1150 },
{ -0.4540, -0.0460, +0.5000 } },
{ { +0.5900, +0.1100, +0.3000 },
{ -0.3310, +0.5000, -0.1690 },
{ -0.4210, -0.0790, +0.5000 } },
{ { +0.5870, +0.1140, +0.2990 },
{ -0.3313, +0.5000, -0.1687 },
{ -0.4187, -0.0813, +0.5000 } },
{ { +0.7010, +0.0870, +0.2120 },
{ -0.3840, +0.5000, -0.1160 },
{ -0.4450, -0.0550, +0.5000 } },
}

Definition at line 43 of file vf_colormatrix.c.

Referenced by calc_coefficients().

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" },
{ "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" },
{ NULL }
}
#define NULL
Definition: coverity.c:32
#define FLAGS
#define OFFSET(x)

Definition at line 90 of file vf_colormatrix.c.

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

Definition at line 174 of file vf_colormatrix.c.

Referenced by config_input().

const AVFilterPad colormatrix_inputs[]
static
Initial value:
= {
{
.name = "default",
.config_props = config_input,
.filter_frame = filter_frame,
},
{ NULL }
}
#define NULL
Definition: coverity.c:32
static int filter_frame(AVFilterLink *link, AVFrame *in)
static int config_input(AVFilterLink *inlink)

Definition at line 428 of file vf_colormatrix.c.

const AVFilterPad colormatrix_outputs[]
static
Initial value:
= {
{
.name = "default",
},
{ NULL }
}
#define NULL
Definition: coverity.c:32

Definition at line 438 of file vf_colormatrix.c.

AVFilter ff_vf_colormatrix
Initial value:
= {
.name = "colormatrix",
.description = NULL_IF_CONFIG_SMALL("Convert color matrix."),
.priv_size = sizeof(ColorMatrixContext),
.init = init,
.priv_class = &colormatrix_class,
}
static av_cold int init(AVFilterContext *ctx)
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:248
static int query_formats(AVFilterContext *ctx)
#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:451
static const AVFilterPad colormatrix_inputs[]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:175
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:442
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:239
static int flags
Definition: cpu.c:47
static const AVFilterPad colormatrix_outputs[]

Definition at line 446 of file vf_colormatrix.c.