FFmpeg
Data Structures | Macros | Enumerations | Functions | Variables
vf_colorspace.c File Reference
#include "libavutil/avassert.h"
#include "libavutil/csp.h"
#include "libavutil/mem_internal.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"
#include "colorspace.h"

Go to the source code of this file.

Data Structures

struct  TransferCharacteristics
 
struct  ColorSpaceContext
 
struct  ThreadData
 Used for passing data between threads. More...
 

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, .unit = 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  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 TransferCharacteristicsget_transfer_characteristics (enum AVColorTransferCharacteristic trc)
 
static int fill_gamma_table (ColorSpaceContext *s)
 
static void fill_whitepoint_conv_table (double out[3][3], enum WhitepointAdaptation wp_adapt, const AVWhitepointCoefficients *wp_src, const AVWhitepointCoefficients *wp_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 av_cold 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 TransferCharacteristics transfer_characteristics [AVCOL_TRC_NB]
 
static const AVOption colorspace_options []
 
static const AVFilterPad inputs []
 
static const AVFilterPad outputs []
 
const AVFilter ff_vf_colorspace
 

Macro Definition Documentation

◆ supported_depth

#define supported_depth (   d)    ((d) == 8 || (d) == 10 || (d) == 12)

◆ supported_subsampling

#define supported_subsampling (   lcw,
  lch 
)    (((lcw) == 0 && (lch) == 0) || ((lcw) == 1 && (lch) == 0) || ((lcw) == 1 && (lch) == 1))

◆ supported_format

#define supported_format (   d)
Value:
((d) != NULL && (d)->nb_components == 3 && \
supported_depth((d)->comp[0].depth) && \
supported_subsampling((d)->log2_chroma_w, (d)->log2_chroma_h))

◆ OFFSET

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

Definition at line 879 of file vf_colorspace.c.

◆ FLAGS

Definition at line 880 of file vf_colorspace.c.

◆ ENUM

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

Definition at line 881 of file vf_colorspace.c.

Enumeration Type Documentation

◆ DitherMode

enum DitherMode
Enumerator
DITHER_NONE 
DITHER_FSB 
DITHER_NB 

Definition at line 40 of file vf_colorspace.c.

◆ Colorspace

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 46 of file vf_colorspace.c.

◆ WhitepointAdaptation

Enumerator
WP_ADAPT_BRADFORD 
WP_ADAPT_VON_KRIES 
NB_WP_ADAPT_NON_IDENTITY 
WP_ADAPT_IDENTITY 
NB_WP_ADAPT 

Definition at line 59 of file vf_colorspace.c.

Function Documentation

◆ get_transfer_characteristics()

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

Definition at line 179 of file vf_colorspace.c.

Referenced by create_filtergraph().

◆ fill_gamma_table()

static int fill_gamma_table ( ColorSpaceContext s)
static

Definition at line 192 of file vf_colorspace.c.

Referenced by create_filtergraph().

◆ fill_whitepoint_conv_table()

static void fill_whitepoint_conv_table ( double  out[3][3],
enum WhitepointAdaptation  wp_adapt,
const AVWhitepointCoefficients wp_src,
const AVWhitepointCoefficients wp_dst 
)
static

Definition at line 236 of file vf_colorspace.c.

Referenced by create_filtergraph().

◆ apply_lut()

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

Definition at line 274 of file vf_colorspace.c.

Referenced by convert().

◆ convert()

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

Definition at line 297 of file vf_colorspace.c.

Referenced by filter_frame().

◆ get_range_off()

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

Definition at line 367 of file vf_colorspace.c.

Referenced by create_filtergraph().

◆ create_filtergraph()

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

Definition at line 397 of file vf_colorspace.c.

Referenced by filter_frame().

◆ init()

static av_cold int init ( AVFilterContext ctx)
static

Definition at line 685 of file vf_colorspace.c.

◆ uninit()

static void uninit ( AVFilterContext ctx)
static

Definition at line 694 of file vf_colorspace.c.

Referenced by filter_frame().

◆ filter_frame()

static int filter_frame ( AVFilterLink link,
AVFrame in 
)
static

Definition at line 712 of file vf_colorspace.c.

◆ query_formats()

static int query_formats ( AVFilterContext ctx)
static

Definition at line 832 of file vf_colorspace.c.

◆ config_props()

static int config_props ( AVFilterLink outlink)
static

Definition at line 860 of file vf_colorspace.c.

◆ AVFILTER_DEFINE_CLASS()

AVFILTER_DEFINE_CLASS ( colorspace  )

Variable Documentation

◆ default_trc

enum AVColorTransferCharacteristic default_trc[CS_NB+1]
static

◆ default_prm

enum AVColorPrimaries default_prm[CS_NB+1]
static

◆ default_csp

enum AVColorSpace default_csp[CS_NB+1]
static

◆ transfer_characteristics

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_LINEAR] = { 1.0, 0.0, 1.0, 0.0 },
[AVCOL_TRC_IEC61966_2_1] = { 1.055, 0.0031308, 1.0 / 2.4, 12.92 },
[AVCOL_TRC_IEC61966_2_4] = { 1.099, 0.018, 0.45, 4.5 },
[AVCOL_TRC_BT2020_10] = { 1.099, 0.018, 0.45, 4.5 },
[AVCOL_TRC_BT2020_12] = { 1.0993, 0.0181, 0.45, 4.5 },
}

Definition at line 165 of file vf_colorspace.c.

Referenced by color_config(), get_transfer_characteristics(), h264_metadata_update_sps(), mpeg2_metadata_init(), sequence_display_extension(), vui_parameters(), and vui_parameters_default().

◆ colorspace_options

const AVOption colorspace_options[]
static

Definition at line 883 of file vf_colorspace.c.

◆ inputs

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

Definition at line 1002 of file vf_colorspace.c.

◆ outputs

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

Definition at line 1010 of file vf_colorspace.c.

◆ ff_vf_colorspace

const AVFilter ff_vf_colorspace
Initial value:
= {
.name = "colorspace",
.description = NULL_IF_CONFIG_SMALL("Convert between colorspaces."),
.init = init,
.uninit = uninit,
.priv_size = sizeof(ColorSpaceContext),
.priv_class = &colorspace_class,
}

Definition at line 1018 of file vf_colorspace.c.

comp
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
Definition: eamad.c:80
AVCOL_TRC_LINEAR
@ AVCOL_TRC_LINEAR
"Linear transfer characteristics"
Definition: pixfmt.h:589
CS_SMPTE240M
@ CS_SMPTE240M
Definition: vf_colorspace.c:54
AVCOL_TRC_UNSPECIFIED
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:583
FILTER_QUERY_FUNC
#define FILTER_QUERY_FUNC(func)
Definition: internal.h:159
AVCOL_TRC_BT2020_12
@ AVCOL_TRC_BT2020_12
ITU-R BT2020 for 12-bit system.
Definition: pixfmt.h:596
CS_BT709
@ CS_BT709
Definition: vf_colorspace.c:52
AVCOL_SPC_BT470BG
@ AVCOL_SPC_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601
Definition: pixfmt.h:615
AVCOL_TRC_IEC61966_2_1
@ AVCOL_TRC_IEC61966_2_1
IEC 61966-2-1 (sRGB or sYCC)
Definition: pixfmt.h:594
AVCOL_TRC_GAMMA28
@ AVCOL_TRC_GAMMA28
also ITU-R BT470BG
Definition: pixfmt.h:586
ColorSpaceContext
Definition: vf_colorspace.c:110
CS_BT2020
@ CS_BT2020
Definition: vf_colorspace.c:55
CS_BT601_6_525
@ CS_BT601_6_525
Definition: vf_colorspace.c:50
AVCOL_TRC_GAMMA22
@ AVCOL_TRC_GAMMA22
also ITU-R BT470M / ITU-R BT1700 625 PAL & SECAM
Definition: pixfmt.h:585
CS_BT470BG
@ CS_BT470BG
Definition: vf_colorspace.c:49
CS_UNSPECIFIED
@ CS_UNSPECIFIED
Definition: vf_colorspace.c:47
AVCOL_SPC_SMPTE170M
@ AVCOL_SPC_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC / functionally identical to above
Definition: pixfmt.h:616
filter_frame
static int filter_frame(AVFilterLink *link, AVFrame *in)
Definition: vf_colorspace.c:712
AVCOL_PRI_SMPTE240M
@ AVCOL_PRI_SMPTE240M
identical to above, also called "SMPTE C" even though it uses D65
Definition: pixfmt.h:564
AVCOL_PRI_UNSPECIFIED
@ AVCOL_PRI_UNSPECIFIED
Definition: pixfmt.h:558
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:182
AVCOL_PRI_BT470BG
@ AVCOL_PRI_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM
Definition: pixfmt.h:562
AVCOL_PRI_SMPTE170M
@ AVCOL_PRI_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
Definition: pixfmt.h:563
init
static av_cold int init(AVFilterContext *ctx)
Definition: vf_colorspace.c:685
config_props
static int config_props(AVFilterLink *outlink)
Definition: vf_colorspace.c:860
CS_NB
@ CS_NB
Definition: vf_colorspace.c:56
NULL
#define NULL
Definition: coverity.c:32
CS_SMPTE170M
@ CS_SMPTE170M
Definition: vf_colorspace.c:53
AVCOL_TRC_IEC61966_2_4
@ AVCOL_TRC_IEC61966_2_4
IEC 61966-2-4.
Definition: pixfmt.h:592
AVCOL_PRI_BT709
@ AVCOL_PRI_BT709
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP 177 Annex B
Definition: pixfmt.h:557
AVCOL_TRC_BT2020_10
@ AVCOL_TRC_BT2020_10
ITU-R BT2020 for 10-bit system.
Definition: pixfmt.h:595
AVCOL_PRI_BT2020
@ AVCOL_PRI_BT2020
ITU-R BT2020.
Definition: pixfmt.h:566
uninit
static void uninit(AVFilterContext *ctx)
Definition: vf_colorspace.c:694
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
AVCOL_TRC_SMPTE240M
@ AVCOL_TRC_SMPTE240M
Definition: pixfmt.h:588
AV_PIX_FMT_FLAG_RGB
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
Definition: pixdesc.h:136
AVCOL_TRC_BT709
@ AVCOL_TRC_BT709
also ITU-R BT1361
Definition: pixfmt.h:582
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
AVCOL_SPC_SMPTE240M
@ AVCOL_SPC_SMPTE240M
derived from 170M primaries and D65 white point, 170M is derived from BT470 System M's primaries
Definition: pixfmt.h:617
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: vf_colorspace.c:832
AVCOL_SPC_BT2020_NCL
@ AVCOL_SPC_BT2020_NCL
ITU-R BT2020 non-constant luminance system.
Definition: pixfmt.h:620
CS_BT601_6_625
@ CS_BT601_6_625
Definition: vf_colorspace.c:51
AVCOL_SPC_UNSPECIFIED
@ AVCOL_SPC_UNSPECIFIED
Definition: pixfmt.h:612
AVCOL_PRI_BT470M
@ AVCOL_PRI_BT470M
also FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
Definition: pixfmt.h:560
outputs
static const AVFilterPad outputs[]
Definition: vf_colorspace.c:1010
CS_BT470M
@ CS_BT470M
Definition: vf_colorspace.c:48
AVCOL_TRC_SMPTE170M
@ AVCOL_TRC_SMPTE170M
also ITU-R BT601-6 525 or 625 / ITU-R BT1358 525 or 625 / ITU-R BT1700 NTSC
Definition: pixfmt.h:587
inputs
static const AVFilterPad inputs[]
Definition: vf_colorspace.c:1002
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
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:183
d
d
Definition: ffmpeg_filter.c:425
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:474
AVCOL_SPC_BT709
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 Annex B
Definition: pixfmt.h:611