FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Enumerations | Functions | Variables
vf_colorspace.c File Reference
#include "libavutil/avassert.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "libavutil/pixfmt.h"
#include "avfilter.h"
#include "colorspacedsp.h"
#include "formats.h"
#include "internal.h"
#include "video.h"

Go to the source code of this file.

Data Structures

struct  ColorPrimaries
 
struct  TransferCharacteristics
 
struct  LumaCoefficients
 
struct  WhitepointCoefficients
 
struct  ColorSpaceContext
 
struct  ThreadData
 

Macros

#define supported_depth(d)   ((d) == 8 || (d) == 10 || (d) == 12)
 
#define supported_subsampling(lcw, lch)   (((lcw) == 0 && (lch) == 0) || ((lcw) == 1 && (lch) == 0) || ((lcw) == 1 && (lch) == 1))
 
#define supported_format(d)
 
#define OFFSET(x)   offsetof(ColorSpaceContext, x)
 
#define FLAGS   AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM
 
#define ENUM(x, y, z)   { x, "", 0, AV_OPT_TYPE_CONST, { .i64 = y }, INT_MIN, INT_MAX, FLAGS, z }
 

Enumerations

enum  DitherMode { DITHER_NONE, DITHER_FSB, DITHER_NB }
 
enum  Colorspace {
  CS_UNSPECIFIED, CS_BT470M, CS_BT470BG, CS_BT601_6_525,
  CS_BT601_6_625, CS_BT709, CS_SMPTE170M, CS_SMPTE240M,
  CS_BT2020, CS_NB
}
 
enum  Whitepoint { WP_D65, WP_C, WP_NB }
 
enum  WhitepointAdaptation {
  WP_ADAPT_BRADFORD, WP_ADAPT_VON_KRIES, NB_WP_ADAPT_NON_IDENTITY, WP_ADAPT_IDENTITY = NB_WP_ADAPT_NON_IDENTITY,
  NB_WP_ADAPT
}
 

Functions

static const struct
LumaCoefficients
get_luma_coefficients (enum AVColorSpace csp)
 
static void fill_rgb2yuv_table (const struct LumaCoefficients *coeffs, double rgb2yuv[3][3])
 
static const struct
TransferCharacteristics
get_transfer_characteristics (enum AVColorTransferCharacteristic trc)
 
static const struct
ColorPrimaries
get_color_primaries (enum AVColorPrimaries prm)
 
static void invert_matrix3x3 (const double in[3][3], double out[3][3])
 
static int fill_gamma_table (ColorSpaceContext *s)
 
static void fill_rgb2xyz_table (const struct ColorPrimaries *coeffs, double rgb2xyz[3][3])
 
static void mul3x3 (double dst[3][3], const double src1[3][3], const double src2[3][3])
 
static void fill_whitepoint_conv_table (double out[3][3], enum WhitepointAdaptation wp_adapt, enum Whitepoint src, enum Whitepoint dst)
 
static void apply_lut (int16_t *buf[3], ptrdiff_t stride, int w, int h, const int16_t *lut)
 
static int convert (AVFilterContext *ctx, void *data, int job_nr, int n_jobs)
 
static int get_range_off (AVFilterContext *ctx, int *off, int *y_rng, int *uv_rng, enum AVColorRange rng, int depth)
 
static int create_filtergraph (AVFilterContext *ctx, const AVFrame *in, const AVFrame *out)
 
static int init (AVFilterContext *ctx)
 
static void uninit (AVFilterContext *ctx)
 
static int filter_frame (AVFilterLink *link, AVFrame *in)
 
static int query_formats (AVFilterContext *ctx)
 
static int config_props (AVFilterLink *outlink)
 
 AVFILTER_DEFINE_CLASS (colorspace)
 

Variables

static enum
AVColorTransferCharacteristic 
default_trc [CS_NB+1]
 
static enum AVColorPrimaries default_prm [CS_NB+1]
 
static enum AVColorSpace default_csp [CS_NB+1]
 
static const struct
LumaCoefficients 
luma_coefficients [AVCOL_SPC_NB]
 
static const struct
TransferCharacteristics 
transfer_characteristics [AVCOL_TRC_NB]
 
static const struct
WhitepointCoefficients 
whitepoint_coefficients [WP_NB]
 
static const struct ColorPrimaries color_primaries [AVCOL_PRI_NB]
 
static const AVOption colorspace_options []
 
static const AVFilterPad inputs []
 
static const AVFilterPad outputs []
 
AVFilter ff_vf_colorspace
 

Macro Definition Documentation

#define supported_depth (   d)    ((d) == 8 || (d) == 10 || (d) == 12)
#define supported_subsampling (   lcw,
  lch 
)    (((lcw) == 0 && (lch) == 0) || ((lcw) == 1 && (lch) == 0) || ((lcw) == 1 && (lch) == 1))
#define supported_format (   d)
Value:
((d) != NULL && (d)->nb_components == 3 && \
supported_subsampling((d)->log2_chroma_w, (d)->log2_chroma_h))
#define NULL
Definition: coverity.c:32
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
Definition: pixdesc.h:148
int depth
Definition: v4l.c:62
#define supported_depth(d)
static int flags
Definition: cpu.c:47
#define supported_subsampling(lcw, lch)
static void comp(unsigned char *dst, int dst_stride, unsigned char *src, int src_stride, int add)
Definition: eamad.c:83

Referenced by create_filtergraph().

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

Definition at line 1024 of file vf_colorspace.c.

Definition at line 1025 of file vf_colorspace.c.

#define ENUM (   x,
  y,
 
)    { x, "", 0, AV_OPT_TYPE_CONST, { .i64 = y }, INT_MIN, INT_MAX, FLAGS, z }

Definition at line 1026 of file vf_colorspace.c.

Enumeration Type Documentation

enum DitherMode
Enumerator
DITHER_NONE 
DITHER_FSB 
DITHER_NB 

Definition at line 37 of file vf_colorspace.c.

enum Colorspace
Enumerator
CS_UNSPECIFIED 
CS_BT470M 
CS_BT470BG 
CS_BT601_6_525 
CS_BT601_6_625 
CS_BT709 
CS_SMPTE170M 
CS_SMPTE240M 
CS_BT2020 
CS_NB 

Definition at line 43 of file vf_colorspace.c.

enum Whitepoint
Enumerator
WP_D65 
WP_C 
WP_NB 

Definition at line 56 of file vf_colorspace.c.

Enumerator
WP_ADAPT_BRADFORD 
WP_ADAPT_VON_KRIES 
NB_WP_ADAPT_NON_IDENTITY 
WP_ADAPT_IDENTITY 
NB_WP_ADAPT 

Definition at line 62 of file vf_colorspace.c.

Function Documentation

static const struct LumaCoefficients* get_luma_coefficients ( enum AVColorSpace  csp)
static

Definition at line 194 of file vf_colorspace.c.

Referenced by create_filtergraph().

static void fill_rgb2yuv_table ( const struct LumaCoefficients coeffs,
double  rgb2yuv[3][3] 
)
static

Definition at line 207 of file vf_colorspace.c.

Referenced by create_filtergraph().

static const struct TransferCharacteristics* get_transfer_characteristics ( enum AVColorTransferCharacteristic  trc)
static

Definition at line 240 of file vf_colorspace.c.

Referenced by create_filtergraph().

static const struct ColorPrimaries* get_color_primaries ( enum AVColorPrimaries  prm)
static

Definition at line 267 of file vf_colorspace.c.

Referenced by create_filtergraph().

static void invert_matrix3x3 ( const double  in[3][3],
double  out[3][3] 
)
static
static int fill_gamma_table ( ColorSpaceContext s)
static

Definition at line 307 of file vf_colorspace.c.

Referenced by create_filtergraph().

static void fill_rgb2xyz_table ( const struct ColorPrimaries coeffs,
double  rgb2xyz[3][3] 
)
static

Definition at line 350 of file vf_colorspace.c.

Referenced by create_filtergraph().

static void mul3x3 ( double  dst[3][3],
const double  src1[3][3],
const double  src2[3][3] 
)
static

Definition at line 379 of file vf_colorspace.c.

Referenced by create_filtergraph(), and fill_whitepoint_conv_table().

static void fill_whitepoint_conv_table ( double  out[3][3],
enum WhitepointAdaptation  wp_adapt,
enum Whitepoint  src,
enum Whitepoint  dst 
)
static

Definition at line 394 of file vf_colorspace.c.

Referenced by create_filtergraph().

static void apply_lut ( int16_t *  buf[3],
ptrdiff_t  stride,
int  w,
int  h,
const int16_t *  lut 
)
static

Definition at line 431 of file vf_colorspace.c.

Referenced by convert().

static int convert ( AVFilterContext ctx,
void data,
int  job_nr,
int  n_jobs 
)
static

Definition at line 454 of file vf_colorspace.c.

Referenced by filter_frame().

static int get_range_off ( AVFilterContext ctx,
int *  off,
int *  y_rng,
int *  uv_rng,
enum AVColorRange  rng,
int  depth 
)
static

Definition at line 524 of file vf_colorspace.c.

Referenced by create_filtergraph().

static int create_filtergraph ( AVFilterContext ctx,
const AVFrame in,
const AVFrame out 
)
static

Definition at line 554 of file vf_colorspace.c.

Referenced by filter_frame().

static int init ( AVFilterContext ctx)
static

Definition at line 846 of file vf_colorspace.c.

static void uninit ( AVFilterContext ctx)
static

Definition at line 855 of file vf_colorspace.c.

Referenced by filter_frame().

static int filter_frame ( AVFilterLink link,
AVFrame in 
)
static

Definition at line 873 of file vf_colorspace.c.

static int query_formats ( AVFilterContext ctx)
static

Definition at line 984 of file vf_colorspace.c.

static int config_props ( AVFilterLink outlink)
static

Definition at line 1012 of file vf_colorspace.c.

AVFILTER_DEFINE_CLASS ( colorspace  )

Variable Documentation

enum AVColorTransferCharacteristic default_trc[CS_NB+1]
static
enum AVColorPrimaries default_prm[CS_NB+1]
static
Initial value:
= {
}
also FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
Definition: pixfmt.h:394
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP177 Annex B
Definition: pixfmt.h:391
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM
Definition: pixfmt.h:396
functionally identical to above
Definition: pixfmt.h:398
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
Definition: pixfmt.h:397
ITU-R BT2020.
Definition: pixfmt.h:400

Definition at line 83 of file vf_colorspace.c.

Referenced by create_filtergraph(), and filter_frame().

enum AVColorSpace default_csp[CS_NB+1]
static
Initial value:
= {
}
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / SMPTE RP177 Annex B
Definition: pixfmt.h:438
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601 ...
Definition: pixfmt.h:442
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
Definition: pixfmt.h:443
functionally identical to above
Definition: pixfmt.h:444
ITU-R BT2020 non-constant luminance system.
Definition: pixfmt.h:446

Definition at line 96 of file vf_colorspace.c.

Referenced by create_filtergraph(), and filter_frame().

const struct LumaCoefficients luma_coefficients[AVCOL_SPC_NB]
static
Initial value:
= {
[AVCOL_SPC_FCC] = { 0.30, 0.59, 0.11 },
[AVCOL_SPC_BT470BG] = { 0.299, 0.587, 0.114 },
[AVCOL_SPC_SMPTE170M] = { 0.299, 0.587, 0.114 },
[AVCOL_SPC_BT709] = { 0.2126, 0.7152, 0.0722 },
[AVCOL_SPC_SMPTE240M] = { 0.212, 0.701, 0.087 },
[AVCOL_SPC_BT2020_NCL] = { 0.2627, 0.6780, 0.0593 },
[AVCOL_SPC_BT2020_CL] = { 0.2627, 0.6780, 0.0593 },
}
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / SMPTE RP177 Annex B
Definition: pixfmt.h:438
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601 ...
Definition: pixfmt.h:442
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
Definition: pixfmt.h:443
functionally identical to above
Definition: pixfmt.h:444
ITU-R BT2020 non-constant luminance system.
Definition: pixfmt.h:446
FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
Definition: pixfmt.h:441
ITU-R BT2020 constant luminance system.
Definition: pixfmt.h:447

Definition at line 184 of file vf_colorspace.c.

const struct TransferCharacteristics transfer_characteristics[AVCOL_TRC_NB]
static
Initial value:
= {
[AVCOL_TRC_BT709] = { 1.099, 0.018, 0.45, 4.5 },
[AVCOL_TRC_GAMMA22] = { 1.0, 0.0, 1.0 / 2.2, 0.0 },
[AVCOL_TRC_GAMMA28] = { 1.0, 0.0, 1.0 / 2.8, 0.0 },
[AVCOL_TRC_SMPTE170M] = { 1.099, 0.018, 0.45, 4.5 },
[AVCOL_TRC_SMPTE240M] = { 1.1115, 0.0228, 0.45, 4.0 },
[AVCOL_TRC_IEC61966_2_1] = { 1.055, 0.0031308, 1.0 / 2.4, 12.92 },
[AVCOL_TRC_BT2020_10] = { 1.099, 0.018, 0.45, 4.5 },
[AVCOL_TRC_BT2020_12] = { 1.0993, 0.0181, 0.45, 4.5 },
}
ITU-R BT2020 for 12-bit system.
Definition: pixfmt.h:426
also ITU-R BT470M / ITU-R BT1700 625 PAL & SECAM
Definition: pixfmt.h:415
also ITU-R BT1361
Definition: pixfmt.h:412
also ITU-R BT601-6 525 or 625 / ITU-R BT1358 525 or 625 / ITU-R BT1700 NTSC
Definition: pixfmt.h:417
IEC 61966-2-1 (sRGB or sYCC)
Definition: pixfmt.h:424
also ITU-R BT470BG
Definition: pixfmt.h:416
ITU-R BT2020 for 10-bit system.
Definition: pixfmt.h:425

Definition at line 228 of file vf_colorspace.c.

Referenced by vaapi_encode_h264_write_vui(), and vaapi_encode_h265_write_vui_parameters().

const struct WhitepointCoefficients whitepoint_coefficients[WP_NB]
static
Initial value:
= {
[WP_D65] = { 0.3127, 0.3290 },
[WP_C] = { 0.3100, 0.3160 },
}

Definition at line 253 of file vf_colorspace.c.

const struct ColorPrimaries color_primaries[AVCOL_PRI_NB]
static
Initial value:
= {
[AVCOL_PRI_BT709] = { WP_D65, 0.640, 0.330, 0.300, 0.600, 0.150, 0.060 },
[AVCOL_PRI_BT470M] = { WP_C, 0.670, 0.330, 0.210, 0.710, 0.140, 0.080 },
[AVCOL_PRI_BT470BG] = { WP_D65, 0.640, 0.330, 0.290, 0.600, 0.150, 0.060,},
[AVCOL_PRI_SMPTE170M] = { WP_D65, 0.630, 0.340, 0.310, 0.595, 0.155, 0.070 },
[AVCOL_PRI_SMPTE240M] = { WP_D65, 0.630, 0.340, 0.310, 0.595, 0.155, 0.070 },
[AVCOL_PRI_BT2020] = { WP_D65, 0.708, 0.292, 0.170, 0.797, 0.131, 0.046 },
}
also FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
Definition: pixfmt.h:394
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP177 Annex B
Definition: pixfmt.h:391
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM
Definition: pixfmt.h:396
functionally identical to above
Definition: pixfmt.h:398
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
Definition: pixfmt.h:397
ITU-R BT2020.
Definition: pixfmt.h:400

Definition at line 258 of file vf_colorspace.c.

Referenced by mov_read_colr().

const AVOption colorspace_options[]
static

Definition at line 1028 of file vf_colorspace.c.

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

Definition at line 1135 of file vf_colorspace.c.

const AVFilterPad outputs[]
static
Initial value:
= {
{
.name = "default",
.config_props = config_props,
},
{ NULL }
}
#define NULL
Definition: coverity.c:32
static int config_props(AVFilterLink *outlink)

Definition at line 1144 of file vf_colorspace.c.

AVFilter ff_vf_colorspace
Initial value:
= {
.name = "colorspace",
.description = NULL_IF_CONFIG_SMALL("Convert between colorspaces."),
.init = init,
.uninit = uninit,
.query_formats = query_formats,
.priv_size = sizeof(ColorSpaceContext),
.priv_class = &colorspace_class,
}
static int init(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:125
static void uninit(AVFilterContext *ctx)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:176
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:116
static const AVFilterPad inputs[]
static const AVFilterPad outputs[]
static int query_formats(AVFilterContext *ctx)
static int flags
Definition: cpu.c:47

Definition at line 1153 of file vf_colorspace.c.