64 "red",
"yellow",
"green",
"cyan",
"blue",
"magenta",
"white",
"neutral",
"black"
92#define OFFSET(x) offsetof(SelectiveColorContext, x)
93#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
94#define RANGE_OPTION(color_name, range) \
95 { color_name"s", "adjust "color_name" regions", OFFSET(opt_cmyk_adjust[range]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS }
126#define DECLARE_RANGE_SCALE_FUNCS(nbits) \
127static int get_neutrals_scale##nbits(int r, int g, int b, int min_val, int max_val) \
130 return (((1<<nbits)-1)*2 - ( abs((max_val<<1) - ((1<<nbits)-1)) \
131 + abs((min_val<<1) - ((1<<nbits)-1))) + 1) >> 1; \
134static int get_whites_scale##nbits(int r, int g, int b, int min_val, int max_val) \
137 return (min_val<<1) - ((1<<nbits)-1); \
140static int get_blacks_scale##nbits(int r, int g, int b, int min_val, int max_val) \
143 return ((1<<nbits)-1) - (max_val<<1); \
152 const float *cmyk =
s->cmyk_adjust[
range_id];
156 if (cmyk[0] || cmyk[1] || cmyk[2] || cmyk[3]) {
159 if (cmyk[0] < -1.0 || cmyk[0] > 1.0 ||
160 cmyk[1] < -1.0 || cmyk[1] > 1.0 ||
161 cmyk[2] < -1.0 || cmyk[2] > 1.0 ||
162 cmyk[3] < -1.0 || cmyk[3] > 1.0) {
164 "Settings must be set in [-1;1] range\n",
190 size_t map_size,
size;
199#define READ16(dst) do { \
201 ret = AVERROR_INVALIDDATA; \
204 dst = AV_RB16(buf); \
212 "the settings might not be loaded properly\n",
version);
225 "but %d\n",
"CMYK"[
i],
val);
232 s->cmyk_adjust[
i][k] =
val / 100.f;
251 s->is_16bit =
desc->comp[0].depth > 8;
269 const char *opt_cmyk_adjust =
s->opt_cmyk_adjust[
i];
271 if (opt_cmyk_adjust) {
272 float *cmyk =
s->cmyk_adjust[
i];
274 sscanf(
s->opt_cmyk_adjust[
i],
"%f %f %f %f", cmyk, cmyk+1, cmyk+2, cmyk+3);
283 for (
i = 0;
i <
s->nb_process_ranges;
i++) {
285 const float *cmyk =
s->cmyk_adjust[pr->
range_id];
315#define DECLARE_SELECTIVE_COLOR_FUNC(nbits) \
316static inline int selective_color_##nbits(AVFilterContext *ctx, ThreadData *td, \
317 int jobnr, int nb_jobs, int direct, int correction_method) \
320 const AVFrame *in = td->in; \
321 AVFrame *out = td->out; \
322 const SelectiveColorContext *s = ctx->priv; \
323 const int height = in->height; \
324 const int width = in->width; \
325 const int slice_start = ff_slice_pos(height, jobnr, nb_jobs); \
326 const int slice_end = ff_slice_pos(height, jobnr + 1, nb_jobs); \
327 const int dst_linesize = out->linesize[0] / ((nbits + 7) / 8); \
328 const int src_linesize = in->linesize[0] / ((nbits + 7) / 8); \
329 const uint8_t roffset = s->rgba_map[R]; \
330 const uint8_t goffset = s->rgba_map[G]; \
331 const uint8_t boffset = s->rgba_map[B]; \
332 const uint8_t aoffset = s->rgba_map[A]; \
333 uint##nbits##_t *dst = (uint##nbits##_t *)out->data[0] + slice_start * dst_linesize; \
334 const uint##nbits##_t *src = (const uint##nbits##_t *)in->data[0] + slice_start * src_linesize; \
335 const uint##nbits##_t *src_r = (const uint##nbits##_t *)src + roffset; \
336 const uint##nbits##_t *src_g = (const uint##nbits##_t *)src + goffset; \
337 const uint##nbits##_t *src_b = (const uint##nbits##_t *)src + boffset; \
338 const uint##nbits##_t *src_a = (const uint##nbits##_t *)src + aoffset; \
339 uint##nbits##_t *dst_r = (uint##nbits##_t *)dst + roffset; \
340 uint##nbits##_t *dst_g = (uint##nbits##_t *)dst + goffset; \
341 uint##nbits##_t *dst_b = (uint##nbits##_t *)dst + boffset; \
342 uint##nbits##_t *dst_a = (uint##nbits##_t *)dst + aoffset; \
343 const int mid = 1<<(nbits-1); \
344 const int max = (1<<nbits)-1; \
345 const float scale = 1.f / max; \
347 for (y = slice_start; y < slice_end; y++) { \
348 for (x = 0; x < width * s->step; x += s->step) { \
349 const int r = src_r[x]; \
350 const int g = src_g[x]; \
351 const int b = src_b[x]; \
352 const int min_color = FFMIN3(r, g, b); \
353 const int max_color = FFMAX3(r, g, b); \
354 const int is_white = (r > mid && g > mid && b > mid); \
355 const int is_neutral = (r || g || b) && \
356 (r != max || g != max || b != max); \
357 const int is_black = (r < mid && g < mid && b < mid); \
358 const uint32_t range_flag = (r == max_color) << RANGE_REDS \
359 | (r == min_color) << RANGE_CYANS \
360 | (g == max_color) << RANGE_GREENS \
361 | (g == min_color) << RANGE_MAGENTAS \
362 | (b == max_color) << RANGE_BLUES \
363 | (b == min_color) << RANGE_YELLOWS \
364 | is_white << RANGE_WHITES \
365 | is_neutral << RANGE_NEUTRALS \
366 | is_black << RANGE_BLACKS; \
368 const float rnorm = r * scale; \
369 const float gnorm = g * scale; \
370 const float bnorm = b * scale; \
371 int adjust_r = 0, adjust_g = 0, adjust_b = 0; \
373 for (i = 0; i < s->nb_process_ranges; i++) { \
374 const struct process_range *pr = &s->process_ranges[i]; \
376 if (range_flag & pr->mask) { \
377 const int scale = pr->get_scale(r, g, b, min_color, max_color); \
380 const float *cmyk_adjust = s->cmyk_adjust[pr->range_id]; \
381 const float adj_c = cmyk_adjust[0]; \
382 const float adj_m = cmyk_adjust[1]; \
383 const float adj_y = cmyk_adjust[2]; \
384 const float k = cmyk_adjust[3]; \
386 adjust_r += comp_adjust(scale, rnorm, adj_c, k, correction_method); \
387 adjust_g += comp_adjust(scale, gnorm, adj_m, k, correction_method); \
388 adjust_b += comp_adjust(scale, bnorm, adj_y, k, correction_method); \
393 if (!direct || adjust_r || adjust_g || adjust_b) { \
394 dst_r[x] = av_clip_uint##nbits(r + adjust_r); \
395 dst_g[x] = av_clip_uint##nbits(g + adjust_g); \
396 dst_b[x] = av_clip_uint##nbits(b + adjust_b); \
397 if (!direct && s->step == 4) \
398 dst_a[x] = src_a[x]; \
402 src_r += src_linesize; \
403 src_g += src_linesize; \
404 src_b += src_linesize; \
405 src_a += src_linesize; \
407 dst_r += dst_linesize; \
408 dst_g += dst_linesize; \
409 dst_b += dst_linesize; \
410 dst_a += dst_linesize; \
415#define DEF_SELECTIVE_COLOR_FUNC(name, direct, correction_method, nbits) \
416static int selective_color_##name##_##nbits(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) \
418 return selective_color_##nbits(ctx, arg, jobnr, nb_jobs, direct, correction_method); \
421#define DEF_SELECTIVE_COLOR_FUNCS(nbits) \
422DECLARE_SELECTIVE_COLOR_FUNC(nbits) \
423DEF_SELECTIVE_COLOR_FUNC(indirect_absolute, 0, CORRECTION_METHOD_ABSOLUTE, nbits) \
424DEF_SELECTIVE_COLOR_FUNC(indirect_relative, 0, CORRECTION_METHOD_RELATIVE, nbits) \
425DEF_SELECTIVE_COLOR_FUNC( direct_absolute, 1, CORRECTION_METHOD_ABSOLUTE, nbits) \
426DEF_SELECTIVE_COLOR_FUNC( direct_relative, 1, CORRECTION_METHOD_RELATIVE, nbits)
443 {selective_color_indirect_absolute_8, selective_color_indirect_relative_8},
444 {selective_color_direct_absolute_8, selective_color_direct_relative_8},
446 {selective_color_indirect_absolute_16, selective_color_indirect_relative_16},
447 {selective_color_direct_absolute_16, selective_color_direct_relative_16},
484 .p.name =
"selectivecolor",
486 .p.priv_class = &selectivecolor_class,
static double val(void *priv, double ch)
static int config_input(AVFilterLink *inlink)
const FFFilter ff_vf_selectivecolor
static AVFormatContext * ctx
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Main libavfilter public API header.
#define i(width, name, range_min, range_max)
static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt)
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static av_always_inline void scale(vec_s32 res[4], vec_s16 res_packed[2], const int shift)
const VDPAUPixFmtMap * map
#define FILTER_INPUTS(array)
#define FILTER_OUTPUTS(array)
#define FILTER_PIXFMTS_ARRAY(array)
#define AVFILTER_DEFINE_CLASS(fname)
void av_file_unmap(uint8_t *bufptr, size_t size)
Unmap or free the buffer bufptr created by av_file_map().
int av_file_map(const char *filename, uint8_t **bufptr, size_t *size, int log_offset, void *log_ctx)
Read the file with name filename, and put its content in a newly allocated buffer or map it with mmap...
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static enum AVPixelFormat pix_fmts[]
static int adjust(int x, int size)
int av_get_padded_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
Return the number of bits per pixel for the pixel format described by pixdesc, including any padding ...
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_RGBA64
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
@ AV_PIX_FMT_ARGB
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
@ AV_PIX_FMT_ABGR
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
@ AV_PIX_FMT_0BGR
packed BGR 8:8:8, 32bpp, XBGRXBGR... X=unused/undefined
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
@ AV_PIX_FMT_RGB0
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
@ AV_PIX_FMT_0RGB
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
#define AV_PIX_FMT_BGRA64
#define FF_ARRAY_ELEMS(a)
Describe the class of an AVClass context structure.
A link between two filters.
int w
agreed upon image width
int h
agreed upon image height
AVFilterContext * dst
dest filter
int format
agreed upon media format
A filter pad used for either input or output.
This structure describes decoded (raw) audio or video data.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
float cmyk_adjust[NB_RANGES][4]
struct process_range process_ranges[NB_RANGES]
char * opt_cmyk_adjust[NB_RANGES]
Used for passing data between threads.
get_range_scale_func get_scale
#define DEF_SELECTIVE_COLOR_FUNCS(nbits)
static int get_cmy_scale(int r, int g, int b, int min_val, int max_val)
static const char *const color_names[NB_RANGES]
static int get_rgb_scale(int r, int g, int b, int min_val, int max_val)
static const AVOption selectivecolor_options[]
static int config_input(AVFilterLink *inlink)
#define DECLARE_RANGE_SCALE_FUNCS(nbits)
static int parse_psfile(AVFilterContext *ctx, const char *fname)
int(* selective_color_func_type)(AVFilterContext *ctx, void *td, int jobnr, int nb_jobs)
static int comp_adjust(int scale, float value, float adjust, float k, int correction_method)
static const AVFilterPad selectivecolor_inputs[]
#define RANGE_OPTION(color_name, range)
int(* get_range_scale_func)(int r, int g, int b, int min_val, int max_val)
@ CORRECTION_METHOD_ABSOLUTE
@ CORRECTION_METHOD_RELATIVE
static int register_range(AVFilterContext *ctx, int range_id)
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.