FFmpeg
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
vf_selectivecolor.c File Reference
#include "libavutil/avassert.h"
#include "libavutil/file.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "libavcodec/mathops.h"
#include "avfilter.h"
#include "drawutils.h"
#include "formats.h"
#include "internal.h"
#include "video.h"

Go to the source code of this file.

Data Structures

struct  process_range
 
struct  ThreadData
 Used for passing data between threads. More...
 
struct  SelectiveColorContext
 

Macros

#define R   0
 
#define G   1
 
#define B   2
 
#define A   3
 
#define OFFSET(x)   offsetof(SelectiveColorContext, x)
 
#define FLAGS   AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
 
#define RANGE_OPTION(color_name, range)   { color_name"s", "adjust "color_name" regions", OFFSET(opt_cmyk_adjust[range]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS }
 
#define DECLARE_RANGE_SCALE_FUNCS(nbits)
 
#define READ16(dst)
 
#define DECLARE_SELECTIVE_COLOR_FUNC(nbits)
 
#define DEF_SELECTIVE_COLOR_FUNC(name, direct, correction_method, nbits)
 
#define DEF_SELECTIVE_COLOR_FUNCS(nbits)
 

Typedefs

typedef int(* get_range_scale_func) (int r, int g, int b, int min_val, int max_val)
 
typedef int(* selective_color_func_type) (AVFilterContext *ctx, void *td, int jobnr, int nb_jobs)
 

Enumerations

enum  color_range {
  RANGE_REDS, RANGE_YELLOWS, RANGE_GREENS, RANGE_CYANS,
  RANGE_BLUES, RANGE_MAGENTAS, RANGE_WHITES, RANGE_NEUTRALS,
  RANGE_BLACKS, NB_RANGES
}
 
enum  correction_method { CORRECTION_METHOD_ABSOLUTE, CORRECTION_METHOD_RELATIVE, NB_CORRECTION_METHODS }
 

Functions

 AVFILTER_DEFINE_CLASS (selectivecolor)
 
static int get_rgb_scale (int r, int g, int b, int min_val, int max_val)
 
static int get_cmy_scale (int r, int g, int b, int min_val, int max_val)
 
static int register_range (SelectiveColorContext *s, int range_id)
 
static int parse_psfile (AVFilterContext *ctx, const char *fname)
 
static int config_input (AVFilterLink *inlink)
 
static int comp_adjust (int scale, float value, float adjust, float k, int correction_method)
 
static int filter_frame (AVFilterLink *inlink, AVFrame *in)
 

Variables

static const char *const color_names [NB_RANGES]
 
static const AVOption selectivecolor_options []
 
static enum AVPixelFormat pix_fmts []
 
static const AVFilterPad selectivecolor_inputs []
 
static const AVFilterPad selectivecolor_outputs []
 
const AVFilter ff_vf_selectivecolor
 

Macro Definition Documentation

◆ R

#define R   0
See also
http://blog.pkh.me/p/22-understanding-selective-coloring-in-adobe-photoshop.html
Todo:
  • use integers so it can be made bitexact and a FATE test can be added

Definition at line 39 of file vf_selectivecolor.c.

◆ G

#define G   1

Definition at line 40 of file vf_selectivecolor.c.

◆ B

#define B   2

Definition at line 41 of file vf_selectivecolor.c.

◆ A

#define A   3

Definition at line 42 of file vf_selectivecolor.c.

◆ OFFSET

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

Definition at line 93 of file vf_selectivecolor.c.

◆ FLAGS

Definition at line 94 of file vf_selectivecolor.c.

◆ RANGE_OPTION

#define RANGE_OPTION (   color_name,
  range 
)    { color_name"s", "adjust "color_name" regions", OFFSET(opt_cmyk_adjust[range]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS }

Definition at line 95 of file vf_selectivecolor.c.

◆ DECLARE_RANGE_SCALE_FUNCS

#define DECLARE_RANGE_SCALE_FUNCS (   nbits)
Value:
static int get_neutrals_scale##nbits(int r, int g, int b, int min_val, int max_val) \
{ \
/* 1 - (|max-0.5| + |min-0.5|) */ \
return (((1<<nbits)-1)*2 - ( abs((max_val<<1) - ((1<<nbits)-1)) \
+ abs((min_val<<1) - ((1<<nbits)-1))) + 1) >> 1; \
} \
\
static int get_whites_scale##nbits(int r, int g, int b, int min_val, int max_val) \
{ \
/* (min - 0.5) * 2 */ \
return (min_val<<1) - ((1<<nbits)-1); \
} \
\
static int get_blacks_scale##nbits(int r, int g, int b, int min_val, int max_val) \
{ \
/* (0.5 - max) * 2 */ \
return ((1<<nbits)-1) - (max_val<<1); \
} \

Definition at line 127 of file vf_selectivecolor.c.

◆ READ16

#define READ16 (   dst)
Value:
do { \
if (size < 2) { \
goto end; \
} \
dst = AV_RB16(buf); \
buf += 2; \
size -= 2; \
} while (0)

◆ DECLARE_SELECTIVE_COLOR_FUNC

#define DECLARE_SELECTIVE_COLOR_FUNC (   nbits)

Definition at line 309 of file vf_selectivecolor.c.

◆ DEF_SELECTIVE_COLOR_FUNC

#define DEF_SELECTIVE_COLOR_FUNC (   name,
  direct,
  correction_method,
  nbits 
)
Value:
static int selective_color_##name##_##nbits(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) \
{ \
return selective_color_##nbits(ctx, arg, jobnr, nb_jobs, direct, correction_method); \
}

Definition at line 409 of file vf_selectivecolor.c.

◆ DEF_SELECTIVE_COLOR_FUNCS

#define DEF_SELECTIVE_COLOR_FUNCS (   nbits)
Value:
DEF_SELECTIVE_COLOR_FUNC(indirect_absolute, 0, CORRECTION_METHOD_ABSOLUTE, nbits) \
DEF_SELECTIVE_COLOR_FUNC(indirect_relative, 0, CORRECTION_METHOD_RELATIVE, nbits) \
DEF_SELECTIVE_COLOR_FUNC( direct_absolute, 1, CORRECTION_METHOD_ABSOLUTE, nbits) \
DEF_SELECTIVE_COLOR_FUNC( direct_relative, 1, CORRECTION_METHOD_RELATIVE, nbits)

Definition at line 415 of file vf_selectivecolor.c.

Typedef Documentation

◆ get_range_scale_func

typedef int(* get_range_scale_func) (int r, int g, int b, int min_val, int max_val)

Definition at line 68 of file vf_selectivecolor.c.

◆ selective_color_func_type

typedef int(* selective_color_func_type) (AVFilterContext *ctx, void *td, int jobnr, int nb_jobs)

Definition at line 425 of file vf_selectivecolor.c.

Enumeration Type Documentation

◆ color_range

Enumerator
RANGE_REDS 
RANGE_YELLOWS 
RANGE_GREENS 
RANGE_CYANS 
RANGE_BLUES 
RANGE_MAGENTAS 
RANGE_WHITES 
RANGE_NEUTRALS 
RANGE_BLACKS 
NB_RANGES 

Definition at line 44 of file vf_selectivecolor.c.

◆ correction_method

Enumerator
CORRECTION_METHOD_ABSOLUTE 
CORRECTION_METHOD_RELATIVE 
NB_CORRECTION_METHODS 

Definition at line 58 of file vf_selectivecolor.c.

Function Documentation

◆ AVFILTER_DEFINE_CLASS()

AVFILTER_DEFINE_CLASS ( selectivecolor  )

◆ get_rgb_scale()

static int get_rgb_scale ( int  r,
int  g,
int  b,
int  min_val,
int  max_val 
)
static

Definition at line 117 of file vf_selectivecolor.c.

Referenced by register_range().

◆ get_cmy_scale()

static int get_cmy_scale ( int  r,
int  g,
int  b,
int  min_val,
int  max_val 
)
static

Definition at line 122 of file vf_selectivecolor.c.

Referenced by register_range().

◆ register_range()

static int register_range ( SelectiveColorContext s,
int  range_id 
)
static

Definition at line 150 of file vf_selectivecolor.c.

Referenced by config_input(), and parse_psfile().

◆ parse_psfile()

static int parse_psfile ( AVFilterContext ctx,
const char *  fname 
)
static

Definition at line 185 of file vf_selectivecolor.c.

Referenced by config_input().

◆ config_input()

static int config_input ( AVFilterLink inlink)
static

Definition at line 238 of file vf_selectivecolor.c.

◆ comp_adjust()

static int comp_adjust ( int  scale,
float  value,
float  adjust,
float  k,
int  correction_method 
)
inlinestatic

Definition at line 299 of file vf_selectivecolor.c.

◆ filter_frame()

static int filter_frame ( AVFilterLink inlink,
AVFrame in 
)
static

Definition at line 427 of file vf_selectivecolor.c.

Variable Documentation

◆ color_names

const char* const color_names[NB_RANGES]
static
Initial value:
= {
"red", "yellow", "green", "cyan", "blue", "magenta", "white", "neutral", "black"
}

Definition at line 64 of file vf_selectivecolor.c.

Referenced by config_input(), register_range(), and test_av_parse_color().

◆ selectivecolor_options

const AVOption selectivecolor_options[]
static
Initial value:
= {
{ "correction_method", "select correction method", OFFSET(correction_method), AV_OPT_TYPE_INT, {.i64 = CORRECTION_METHOD_ABSOLUTE}, 0, NB_CORRECTION_METHODS-1, FLAGS, "correction_method" },
{ "absolute", NULL, 0, AV_OPT_TYPE_CONST, {.i64=CORRECTION_METHOD_ABSOLUTE}, INT_MIN, INT_MAX, FLAGS, "correction_method" },
{ "relative", NULL, 0, AV_OPT_TYPE_CONST, {.i64=CORRECTION_METHOD_RELATIVE}, INT_MIN, INT_MAX, FLAGS, "correction_method" },
{ "psfile", "set Photoshop selectivecolor file name", OFFSET(psfile), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
{ NULL }
}

Definition at line 98 of file vf_selectivecolor.c.

◆ pix_fmts

enum AVPixelFormat pix_fmts[]
static

◆ selectivecolor_inputs

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

Definition at line 468 of file vf_selectivecolor.c.

◆ selectivecolor_outputs

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

Definition at line 477 of file vf_selectivecolor.c.

◆ ff_vf_selectivecolor

const AVFilter ff_vf_selectivecolor
Initial value:
= {
.name = "selectivecolor",
.description = NULL_IF_CONFIG_SMALL("Apply CMYK adjustments to specific color ranges."),
.priv_size = sizeof(SelectiveColorContext),
.priv_class = &selectivecolor_class,
}

Definition at line 484 of file vf_selectivecolor.c.

OFFSET
#define OFFSET(x)
Definition: vf_selectivecolor.c:93
SelectiveColorContext
Definition: vf_selectivecolor.c:80
name
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
r
const char * r
Definition: vf_curves.c:126
FILTER_PIXFMTS_ARRAY
#define FILTER_PIXFMTS_ARRAY(array)
Definition: internal.h:174
b
#define b
Definition: input.c:41
AV_PIX_FMT_BGR24
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:69
AV_PIX_FMT_BGRA
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:95
RANGE_NEUTRALS
@ RANGE_NEUTRALS
Definition: vf_selectivecolor.c:53
RANGE_GREENS
@ RANGE_GREENS
Definition: vf_selectivecolor.c:48
FLAGS
#define FLAGS
Definition: vf_selectivecolor.c:94
RANGE_CYANS
@ RANGE_CYANS
Definition: vf_selectivecolor.c:49
g
const char * g
Definition: vf_curves.c:127
RANGE_WHITES
@ RANGE_WHITES
Definition: vf_selectivecolor.c:52
ctx
AVFormatContext * ctx
Definition: movenc.c:48
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:194
AV_PIX_FMT_RGBA
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:93
arg
const char * arg
Definition: jacosubdec.c:67
AV_PIX_FMT_RGBA64
#define AV_PIX_FMT_RGBA64
Definition: pixfmt.h:449
AV_PIX_FMT_BGR48
#define AV_PIX_FMT_BGR48
Definition: pixfmt.h:450
NULL
#define NULL
Definition: coverity.c:32
AV_PIX_FMT_BGR0
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
Definition: pixfmt.h:258
RANGE_MAGENTAS
@ RANGE_MAGENTAS
Definition: vf_selectivecolor.c:51
abs
#define abs(x)
Definition: cuda_runtime.h:35
AV_PIX_FMT_ABGR
@ AV_PIX_FMT_ABGR
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition: pixfmt.h:94
CORRECTION_METHOD_ABSOLUTE
@ CORRECTION_METHOD_ABSOLUTE
Definition: vf_selectivecolor.c:59
AV_PIX_FMT_RGB24
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:68
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:115
AV_PIX_FMT_RGB48
#define AV_PIX_FMT_RGB48
Definition: pixfmt.h:445
size
int size
Definition: twinvq_data.h:10344
RANGE_BLACKS
@ RANGE_BLACKS
Definition: vf_selectivecolor.c:54
RANGE_YELLOWS
@ RANGE_YELLOWS
Definition: vf_selectivecolor.c:47
AV_PIX_FMT_RGB0
@ AV_PIX_FMT_RGB0
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
Definition: pixfmt.h:256
config_input
static int config_input(AVFilterLink *inlink)
Definition: vf_selectivecolor.c:238
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:142
AV_PIX_FMT_ARGB
@ AV_PIX_FMT_ARGB
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: pixfmt.h:92
AV_PIX_FMT_BGRA64
#define AV_PIX_FMT_BGRA64
Definition: pixfmt.h:454
NB_CORRECTION_METHODS
@ NB_CORRECTION_METHODS
Definition: vf_selectivecolor.c:61
RANGE_BLUES
@ RANGE_BLUES
Definition: vf_selectivecolor.c:50
DECLARE_SELECTIVE_COLOR_FUNC
#define DECLARE_SELECTIVE_COLOR_FUNC(nbits)
Definition: vf_selectivecolor.c:309
AV_PIX_FMT_0BGR
@ AV_PIX_FMT_0BGR
packed BGR 8:8:8, 32bpp, XBGRXBGR... X=unused/undefined
Definition: pixfmt.h:257
RANGE_OPTION
#define RANGE_OPTION(color_name, range)
Definition: vf_selectivecolor.c:95
correction_method
correction_method
Definition: vf_selectivecolor.c:58
RANGE_REDS
@ RANGE_REDS
Definition: vf_selectivecolor.c:46
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
selectivecolor_outputs
static const AVFilterPad selectivecolor_outputs[]
Definition: vf_selectivecolor.c:477
selectivecolor_inputs
static const AVFilterPad selectivecolor_inputs[]
Definition: vf_selectivecolor.c:468
AVFilterContext
An instance of a filter.
Definition: avfilter.h:392
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
_
#define _
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: vf_selectivecolor.c:288
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:195
AV_PIX_FMT_0RGB
@ AV_PIX_FMT_0RGB
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
Definition: pixfmt.h:255
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_selectivecolor.c:427
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:229
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
CORRECTION_METHOD_RELATIVE
@ CORRECTION_METHOD_RELATIVE
Definition: vf_selectivecolor.c:60
AV_RB16
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_RB16
Definition: bytestream.h:98