FFmpeg
vf_selectivecolor.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2016 Clément Bœsch <u pkh me>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /**
22  * @see http://blog.pkh.me/p/22-understanding-selective-coloring-in-adobe-photoshop.html
23  * @todo
24  * - use integers so it can be made bitexact and a FATE test can be added
25  */
26 
27 #include "libavutil/avassert.h"
28 #include "libavutil/file.h"
29 #include "libavutil/intreadwrite.h"
30 #include "libavutil/opt.h"
31 #include "libavutil/pixdesc.h"
32 #include "libavcodec/mathops.h" // for mid_pred(), which is a macro so no link dependency
33 #include "avfilter.h"
34 #include "drawutils.h"
35 #include "formats.h"
36 #include "internal.h"
37 #include "video.h"
38 
39 #define R 0
40 #define G 1
41 #define B 2
42 #define A 3
43 
45  // WARNING: do NOT reorder (see parse_psfile())
56 };
57 
62 };
63 
64 static const char *const color_names[NB_RANGES] = {
65  "red", "yellow", "green", "cyan", "blue", "magenta", "white", "neutral", "black"
66 };
67 
68 typedef int (*get_range_scale_func)(int r, int g, int b, int min_val, int max_val);
69 
70 struct process_range {
71  int range_id;
72  uint32_t mask;
74 };
75 
76 typedef struct ThreadData {
77  AVFrame *in, *out;
78 } ThreadData;
79 
80 typedef struct SelectiveColorContext {
81  const AVClass *class;
85  struct process_range process_ranges[NB_RANGES]; // color ranges to process
87  char *psfile;
88  uint8_t rgba_map[4];
89  int is_16bit;
90  int step;
92 
93 #define OFFSET(x) offsetof(SelectiveColorContext, x)
94 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
95 #define RANGE_OPTION(color_name, range) \
96  { color_name"s", "adjust "color_name" regions", OFFSET(opt_cmyk_adjust[range]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS }
97 
98 static const AVOption selectivecolor_options[] = {
99  { "correction_method", "select correction method", OFFSET(correction_method), AV_OPT_TYPE_INT, {.i64 = CORRECTION_METHOD_ABSOLUTE}, 0, NB_CORRECTION_METHODS-1, FLAGS, "correction_method" },
100  { "absolute", NULL, 0, AV_OPT_TYPE_CONST, {.i64=CORRECTION_METHOD_ABSOLUTE}, INT_MIN, INT_MAX, FLAGS, "correction_method" },
101  { "relative", NULL, 0, AV_OPT_TYPE_CONST, {.i64=CORRECTION_METHOD_RELATIVE}, INT_MIN, INT_MAX, FLAGS, "correction_method" },
102  RANGE_OPTION("red", RANGE_REDS),
103  RANGE_OPTION("yellow", RANGE_YELLOWS),
104  RANGE_OPTION("green", RANGE_GREENS),
105  RANGE_OPTION("cyan", RANGE_CYANS),
106  RANGE_OPTION("blue", RANGE_BLUES),
107  RANGE_OPTION("magenta", RANGE_MAGENTAS),
108  RANGE_OPTION("white", RANGE_WHITES),
109  RANGE_OPTION("neutral", RANGE_NEUTRALS),
110  RANGE_OPTION("black", RANGE_BLACKS),
111  { "psfile", "set Photoshop selectivecolor file name", OFFSET(psfile), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
112  { NULL }
113 };
114 
115 AVFILTER_DEFINE_CLASS(selectivecolor);
116 
117 static int get_rgb_scale(int r, int g, int b, int min_val, int max_val)
118 {
119  return max_val - mid_pred(r, g, b);
120 }
121 
122 static int get_cmy_scale(int r, int g, int b, int min_val, int max_val)
123 {
124  return mid_pred(r, g, b) - min_val;
125 }
126 
127 #define DECLARE_RANGE_SCALE_FUNCS(nbits) \
128 static int get_neutrals_scale##nbits(int r, int g, int b, int min_val, int max_val) \
129 { \
130  /* 1 - (|max-0.5| + |min-0.5|) */ \
131  return (((1<<nbits)-1)*2 - ( abs((max_val<<1) - ((1<<nbits)-1)) \
132  + abs((min_val<<1) - ((1<<nbits)-1))) + 1) >> 1; \
133 } \
134  \
135 static int get_whites_scale##nbits(int r, int g, int b, int min_val, int max_val) \
136 { \
137  /* (min - 0.5) * 2 */ \
138  return (min_val<<1) - ((1<<nbits)-1); \
139 } \
140  \
141 static int get_blacks_scale##nbits(int r, int g, int b, int min_val, int max_val) \
142 { \
143  /* (0.5 - max) * 2 */ \
144  return ((1<<nbits)-1) - (max_val<<1); \
145 } \
146 
149 
151 {
152  const float *cmyk = s->cmyk_adjust[range_id];
153 
154  /* If the color range has user settings, register the color range
155  * as "to be processed" */
156  if (cmyk[0] || cmyk[1] || cmyk[2] || cmyk[3]) {
157  struct process_range *pr = &s->process_ranges[s->nb_process_ranges++];
158 
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) {
163  av_log(s, AV_LOG_ERROR, "Invalid %s adjustments (%g %g %g %g). "
164  "Settings must be set in [-1;1] range\n",
165  color_names[range_id], cmyk[0], cmyk[1], cmyk[2], cmyk[3]);
166  return AVERROR(EINVAL);
167  }
168 
169  pr->range_id = range_id;
170  pr->mask = 1 << range_id;
171  if (pr->mask & (1<<RANGE_REDS | 1<<RANGE_GREENS | 1<<RANGE_BLUES)) pr->get_scale = get_rgb_scale;
172  else if (pr->mask & (1<<RANGE_CYANS | 1<<RANGE_MAGENTAS | 1<<RANGE_YELLOWS)) pr->get_scale = get_cmy_scale;
173  else if (!s->is_16bit && (pr->mask & 1<<RANGE_WHITES)) pr->get_scale = get_whites_scale8;
174  else if (!s->is_16bit && (pr->mask & 1<<RANGE_NEUTRALS)) pr->get_scale = get_neutrals_scale8;
175  else if (!s->is_16bit && (pr->mask & 1<<RANGE_BLACKS)) pr->get_scale = get_blacks_scale8;
176  else if ( s->is_16bit && (pr->mask & 1<<RANGE_WHITES)) pr->get_scale = get_whites_scale16;
177  else if ( s->is_16bit && (pr->mask & 1<<RANGE_NEUTRALS)) pr->get_scale = get_neutrals_scale16;
178  else if ( s->is_16bit && (pr->mask & 1<<RANGE_BLACKS)) pr->get_scale = get_blacks_scale16;
179  else
180  av_assert0(0);
181  }
182  return 0;
183 }
184 
185 static int parse_psfile(AVFilterContext *ctx, const char *fname)
186 {
187  int16_t val;
188  int ret, i, version;
189  uint8_t *buf;
190  size_t size;
191  SelectiveColorContext *s = ctx->priv;
192 
193  ret = av_file_map(fname, &buf, &size, 0, NULL);
194  if (ret < 0)
195  return ret;
196 
197 #define READ16(dst) do { \
198  if (size < 2) { \
199  ret = AVERROR_INVALIDDATA; \
200  goto end; \
201  } \
202  dst = AV_RB16(buf); \
203  buf += 2; \
204  size -= 2; \
205 } while (0)
206 
207  READ16(version);
208  if (version != 1)
209  av_log(s, AV_LOG_WARNING, "Unsupported selective color file version %d, "
210  "the settings might not be loaded properly\n", version);
211 
212  READ16(s->correction_method);
213 
214  // 1st CMYK entry is reserved/unused
215  for (i = 0; i < FF_ARRAY_ELEMS(s->cmyk_adjust[0]); i++) {
216  READ16(val);
217  if (val)
218  av_log(s, AV_LOG_WARNING, "%c value of first CMYK entry is not 0 "
219  "but %d\n", "CMYK"[i], val);
220  }
221 
222  for (i = 0; i < FF_ARRAY_ELEMS(s->cmyk_adjust); i++) {
223  int k;
224  for (k = 0; k < FF_ARRAY_ELEMS(s->cmyk_adjust[0]); k++) {
225  READ16(val);
226  s->cmyk_adjust[i][k] = val / 100.;
227  }
228  ret = register_range(s, i);
229  if (ret < 0)
230  goto end;
231  }
232 
233 end:
234  av_file_unmap(buf, size);
235  return ret;
236 }
237 
239 {
240  int i, ret;
241  AVFilterContext *ctx = inlink->dst;
242  SelectiveColorContext *s = ctx->priv;
244 
245  s->is_16bit = desc->comp[0].depth > 8;
246  s->step = av_get_padded_bits_per_pixel(desc) >> (3 + s->is_16bit);
247 
248  ret = ff_fill_rgba_map(s->rgba_map, inlink->format);
249  if (ret < 0)
250  return ret;
251 
252  /* If the following conditions are not met, it will cause trouble while
253  * parsing the PS file */
254  av_assert0(FF_ARRAY_ELEMS(s->cmyk_adjust) == 10 - 1);
255  av_assert0(FF_ARRAY_ELEMS(s->cmyk_adjust[0]) == 4);
256 
257  if (s->psfile) {
258  ret = parse_psfile(ctx, s->psfile);
259  if (ret < 0)
260  return ret;
261  } else {
262  for (i = 0; i < FF_ARRAY_ELEMS(s->opt_cmyk_adjust); i++) {
263  const char *opt_cmyk_adjust = s->opt_cmyk_adjust[i];
264 
265  if (opt_cmyk_adjust) {
266  float *cmyk = s->cmyk_adjust[i];
267 
268  sscanf(s->opt_cmyk_adjust[i], "%f %f %f %f", cmyk, cmyk+1, cmyk+2, cmyk+3);
269  ret = register_range(s, i);
270  if (ret < 0)
271  return ret;
272  }
273  }
274  }
275 
276  av_log(s, AV_LOG_VERBOSE, "Adjustments:%s\n", s->nb_process_ranges ? "" : " none");
277  for (i = 0; i < s->nb_process_ranges; i++) {
278  const struct process_range *pr = &s->process_ranges[i];
279  const float *cmyk = s->cmyk_adjust[pr->range_id];
280 
281  av_log(s, AV_LOG_VERBOSE, "%8ss: C=%6g M=%6g Y=%6g K=%6g\n",
282  color_names[pr->range_id], cmyk[0], cmyk[1], cmyk[2], cmyk[3]);
283  }
284 
285  return 0;
286 }
287 
289 {
290  static const enum AVPixelFormat pix_fmts[] = {
299  };
301  if (!fmts_list)
302  return AVERROR(ENOMEM);
303  return ff_set_common_formats(ctx, fmts_list);
304 }
305 
306 static inline int comp_adjust(int scale, float value, float adjust, float k, int correction_method)
307 {
308  const float min = -value;
309  const float max = 1. - value;
310  float res = (-1. - adjust) * k - adjust;
312  res *= max;
313  return lrint(av_clipf(res, min, max) * scale);
314 }
315 
316 #define DECLARE_SELECTIVE_COLOR_FUNC(nbits) \
317 static inline int selective_color_##nbits(AVFilterContext *ctx, ThreadData *td, \
318  int jobnr, int nb_jobs, int direct, int correction_method) \
319 { \
320  int i, x, y; \
321  const AVFrame *in = td->in; \
322  AVFrame *out = td->out; \
323  const SelectiveColorContext *s = ctx->priv; \
324  const int height = in->height; \
325  const int width = in->width; \
326  const int slice_start = (height * jobnr ) / nb_jobs; \
327  const int slice_end = (height * (jobnr+1)) / nb_jobs; \
328  const int dst_linesize = out->linesize[0]; \
329  const int src_linesize = in->linesize[0]; \
330  const uint8_t roffset = s->rgba_map[R]; \
331  const uint8_t goffset = s->rgba_map[G]; \
332  const uint8_t boffset = s->rgba_map[B]; \
333  const uint8_t aoffset = s->rgba_map[A]; \
334  \
335  for (y = slice_start; y < slice_end; y++) { \
336  uint##nbits##_t *dst = ( uint##nbits##_t *)(out->data[0] + y * dst_linesize); \
337  const uint##nbits##_t *src = (const uint##nbits##_t *)( in->data[0] + y * src_linesize); \
338  \
339  for (x = 0; x < width * s->step; x += s->step) { \
340  const int r = src[x + roffset]; \
341  const int g = src[x + goffset]; \
342  const int b = src[x + boffset]; \
343  const int min_color = FFMIN3(r, g, b); \
344  const int max_color = FFMAX3(r, g, b); \
345  const int is_white = (r > 1<<(nbits-1) && g > 1<<(nbits-1) && b > 1<<(nbits-1)); \
346  const int is_neutral = (r || g || b) && \
347  (r != (1<<nbits)-1 || g != (1<<nbits)-1 || b != (1<<nbits)-1); \
348  const int is_black = (r < 1<<(nbits-1) && g < 1<<(nbits-1) && b < 1<<(nbits-1)); \
349  const uint32_t range_flag = (r == max_color) << RANGE_REDS \
350  | (r == min_color) << RANGE_CYANS \
351  | (g == max_color) << RANGE_GREENS \
352  | (g == min_color) << RANGE_MAGENTAS \
353  | (b == max_color) << RANGE_BLUES \
354  | (b == min_color) << RANGE_YELLOWS \
355  | is_white << RANGE_WHITES \
356  | is_neutral << RANGE_NEUTRALS \
357  | is_black << RANGE_BLACKS; \
358  \
359  const float rnorm = r * (1.f / ((1<<nbits)-1)); \
360  const float gnorm = g * (1.f / ((1<<nbits)-1)); \
361  const float bnorm = b * (1.f / ((1<<nbits)-1)); \
362  int adjust_r = 0, adjust_g = 0, adjust_b = 0; \
363  \
364  for (i = 0; i < s->nb_process_ranges; i++) { \
365  const struct process_range *pr = &s->process_ranges[i]; \
366  \
367  if (range_flag & pr->mask) { \
368  const int scale = pr->get_scale(r, g, b, min_color, max_color); \
369  \
370  if (scale > 0) { \
371  const float *cmyk_adjust = s->cmyk_adjust[pr->range_id]; \
372  const float adj_c = cmyk_adjust[0]; \
373  const float adj_m = cmyk_adjust[1]; \
374  const float adj_y = cmyk_adjust[2]; \
375  const float k = cmyk_adjust[3]; \
376  \
377  adjust_r += comp_adjust(scale, rnorm, adj_c, k, correction_method); \
378  adjust_g += comp_adjust(scale, gnorm, adj_m, k, correction_method); \
379  adjust_b += comp_adjust(scale, bnorm, adj_y, k, correction_method); \
380  } \
381  } \
382  } \
383  \
384  if (!direct || adjust_r || adjust_g || adjust_b) { \
385  dst[x + roffset] = av_clip_uint##nbits(r + adjust_r); \
386  dst[x + goffset] = av_clip_uint##nbits(g + adjust_g); \
387  dst[x + boffset] = av_clip_uint##nbits(b + adjust_b); \
388  if (!direct && s->step == 4) \
389  dst[x + aoffset] = src[x + aoffset]; \
390  } \
391  } \
392  } \
393  return 0; \
394 }
395 
396 #define DEF_SELECTIVE_COLOR_FUNC(name, direct, correction_method, nbits) \
397 static int selective_color_##name##_##nbits(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) \
398 { \
399  return selective_color_##nbits(ctx, arg, jobnr, nb_jobs, direct, correction_method); \
400 }
401 
402 #define DEF_SELECTIVE_COLOR_FUNCS(nbits) \
403 DECLARE_SELECTIVE_COLOR_FUNC(nbits) \
404 DEF_SELECTIVE_COLOR_FUNC(indirect_absolute, 0, CORRECTION_METHOD_ABSOLUTE, nbits) \
405 DEF_SELECTIVE_COLOR_FUNC(indirect_relative, 0, CORRECTION_METHOD_RELATIVE, nbits) \
406 DEF_SELECTIVE_COLOR_FUNC( direct_absolute, 1, CORRECTION_METHOD_ABSOLUTE, nbits) \
407 DEF_SELECTIVE_COLOR_FUNC( direct_relative, 1, CORRECTION_METHOD_RELATIVE, nbits)
408 
411 
412 typedef int (*selective_color_func_type)(AVFilterContext *ctx, void *td, int jobnr, int nb_jobs);
413 
415 {
416  AVFilterContext *ctx = inlink->dst;
417  AVFilterLink *outlink = ctx->outputs[0];
418  int direct;
419  AVFrame *out;
420  ThreadData td;
421  const SelectiveColorContext *s = ctx->priv;
422  static const selective_color_func_type funcs[2][2][2] = {
423  {
424  {selective_color_indirect_absolute_8, selective_color_indirect_relative_8},
425  {selective_color_direct_absolute_8, selective_color_direct_relative_8},
426  },{
427  {selective_color_indirect_absolute_16, selective_color_indirect_relative_16},
428  {selective_color_direct_absolute_16, selective_color_direct_relative_16},
429  }
430  };
431 
432  if (av_frame_is_writable(in)) {
433  direct = 1;
434  out = in;
435  } else {
436  direct = 0;
437  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
438  if (!out) {
439  av_frame_free(&in);
440  return AVERROR(ENOMEM);
441  }
443  }
444 
445  td.in = in;
446  td.out = out;
447  ctx->internal->execute(ctx, funcs[s->is_16bit][direct][s->correction_method],
449 
450  if (!direct)
451  av_frame_free(&in);
452  return ff_filter_frame(outlink, out);
453 }
454 
456  {
457  .name = "default",
458  .type = AVMEDIA_TYPE_VIDEO,
459  .filter_frame = filter_frame,
460  .config_props = config_input,
461  },
462  { NULL }
463 };
464 
466  {
467  .name = "default",
468  .type = AVMEDIA_TYPE_VIDEO,
469  },
470  { NULL }
471 };
472 
474  .name = "selectivecolor",
475  .description = NULL_IF_CONFIG_SMALL("Apply CMYK adjustments to specific color ranges."),
476  .priv_size = sizeof(SelectiveColorContext),
480  .priv_class = &selectivecolor_class,
482 };
register_range
static int register_range(SelectiveColorContext *s, int range_id)
Definition: vf_selectivecolor.c:150
selective_color_func_type
int(* selective_color_func_type)(AVFilterContext *ctx, void *td, int jobnr, int nb_jobs)
Definition: vf_selectivecolor.c:412
ff_get_video_buffer
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:99
OFFSET
#define OFFSET(x)
Definition: vf_selectivecolor.c:93
SelectiveColorContext
Definition: vf_selectivecolor.c:80
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:187
direct
static void direct(const float *in, const FFTComplex *ir, int len, float *out)
Definition: af_afir.c:60
td
#define td
Definition: regdef.h:70
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
r
const char * r
Definition: vf_curves.c:116
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
ff_make_format_list
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:286
out
FILE * out
Definition: movenc.c:54
SelectiveColorContext::correction_method
int correction_method
Definition: vf_selectivecolor.c:82
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:978
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2541
inlink
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
Definition: filter_design.txt:212
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:111
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:303
pixdesc.h
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(selectivecolor)
AVOption
AVOption.
Definition: opt.h:248
b
#define b
Definition: input.c:41
SelectiveColorContext::step
int step
Definition: vf_selectivecolor.c:90
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:197
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
max
#define max(a, b)
Definition: cuda_runtime.h:33
SelectiveColorContext::rgba_map
uint8_t rgba_map[4]
Definition: vf_selectivecolor.c:88
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:149
ThreadData::out
AVFrame * out
Definition: af_adeclick.c:502
RANGE_NEUTRALS
@ RANGE_NEUTRALS
Definition: vf_selectivecolor.c:53
video.h
AVFormatContext::internal
AVFormatInternal * internal
An opaque field for libavformat internal usage.
Definition: avformat.h:1554
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: vf_selectivecolor.c:288
DECLARE_RANGE_SCALE_FUNCS
#define DECLARE_RANGE_SCALE_FUNCS(nbits)
Definition: vf_selectivecolor.c:127
AVFilterFormats
A list of supported formats for one end of a filter link.
Definition: formats.h:65
formats.h
DEF_SELECTIVE_COLOR_FUNCS
#define DEF_SELECTIVE_COLOR_FUNCS(nbits)
Definition: vf_selectivecolor.c:402
RANGE_GREENS
@ RANGE_GREENS
Definition: vf_selectivecolor.c:48
SelectiveColorContext::nb_process_ranges
int nb_process_ranges
Definition: vf_selectivecolor.c:86
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...
Definition: file.c:53
FLAGS
#define FLAGS
Definition: vf_selectivecolor.c:94
val
static double val(void *priv, double ch)
Definition: aeval.c:76
SelectiveColorContext::process_ranges
struct process_range process_ranges[NB_RANGES]
Definition: vf_selectivecolor.c:85
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:54
avassert.h
color_names
static const char *const color_names[NB_RANGES]
Definition: vf_selectivecolor.c:64
lrint
#define lrint
Definition: tablegen.h:53
get_cmy_scale
static int get_cmy_scale(int r, int g, int b, int min_val, int max_val)
Definition: vf_selectivecolor.c:122
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:181
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
inputs
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs
Definition: filter_design.txt:243
ff_set_common_formats
int ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
Definition: formats.c:580
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:257
RANGE_CYANS
@ RANGE_CYANS
Definition: vf_selectivecolor.c:49
SelectiveColorContext::opt_cmyk_adjust
char * opt_cmyk_adjust[NB_RANGES]
Definition: vf_selectivecolor.c:83
adjust
static int adjust(int x, int size)
Definition: mobiclip.c:515
g
const char * g
Definition: vf_curves.c:117
RANGE_WHITES
@ RANGE_WHITES
Definition: vf_selectivecolor.c:52
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
outputs
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:289
ctx
AVFormatContext * ctx
Definition: movenc.c:48
get_rgb_scale
static int get_rgb_scale(int r, int g, int b, int min_val, int max_val)
Definition: vf_selectivecolor.c:117
process_range::mask
uint32_t mask
Definition: vf_selectivecolor.c:72
color_range
color_range
Definition: vf_selectivecolor.c:44
av_file_unmap
void av_file_unmap(uint8_t *bufptr, size_t size)
Unmap or free the buffer bufptr created by av_file_map().
Definition: file.c:144
AV_PIX_FMT_RGBA
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:93
AV_PIX_FMT_RGBA64
#define AV_PIX_FMT_RGBA64
Definition: pixfmt.h:379
selectivecolor_options
static const AVOption selectivecolor_options[]
Definition: vf_selectivecolor.c:98
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
AV_PIX_FMT_BGR48
#define AV_PIX_FMT_BGR48
Definition: pixfmt.h:380
NULL
#define NULL
Definition: coverity.c:32
av_frame_copy_props
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:536
av_clipf
#define av_clipf
Definition: common.h:170
parse_psfile
static int parse_psfile(AVFilterContext *ctx, const char *fname)
Definition: vf_selectivecolor.c:185
mathops.h
AV_PIX_FMT_BGR0
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
Definition: pixfmt.h:230
RANGE_MAGENTAS
@ RANGE_MAGENTAS
Definition: vf_selectivecolor.c:51
ff_vf_selectivecolor
const AVFilter ff_vf_selectivecolor
Definition: vf_selectivecolor.c:473
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
SelectiveColorContext::psfile
char * psfile
Definition: vf_selectivecolor.c:87
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:117
av_get_padded_bits_per_pixel
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 ...
Definition: pixdesc.c:2506
SelectiveColorContext::is_16bit
int is_16bit
Definition: vf_selectivecolor.c:89
comp_adjust
static int comp_adjust(int scale, float value, float adjust, float k, int correction_method)
Definition: vf_selectivecolor.c:306
NB_RANGES
@ NB_RANGES
Definition: vf_selectivecolor.c:55
AV_PIX_FMT_RGB48
#define AV_PIX_FMT_RGB48
Definition: pixfmt.h:375
size
int size
Definition: twinvq_data.h:10344
process_range::get_scale
get_range_scale_func get_scale
Definition: vf_selectivecolor.c:73
av_frame_is_writable
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:472
RANGE_BLACKS
@ RANGE_BLACKS
Definition: vf_selectivecolor.c:54
FFMIN
#define FFMIN(a, b)
Definition: common.h:105
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:228
version
version
Definition: libkvazaar.c:306
config_input
static int config_input(AVFilterLink *inlink)
Definition: vf_selectivecolor.c:238
internal.h
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:126
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:384
i
int i
Definition: input.c:407
NB_CORRECTION_METHODS
@ NB_CORRECTION_METHODS
Definition: vf_selectivecolor.c:61
RANGE_BLUES
@ RANGE_BLUES
Definition: vf_selectivecolor.c:50
ff_filter_get_nb_threads
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Definition: avfilter.c:762
ThreadData
Used for passing data between threads.
Definition: dsddec.c:67
value
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 value
Definition: writing_filters.txt:86
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:60
process_range::range_id
int range_id
Definition: vf_selectivecolor.c:71
AVFilter
Filter definition.
Definition: avfilter.h:145
mid_pred
#define mid_pred
Definition: mathops.h:97
ret
ret
Definition: filter_design.txt:187
AV_PIX_FMT_0BGR
@ AV_PIX_FMT_0BGR
packed BGR 8:8:8, 32bpp, XBGRXBGR... X=unused/undefined
Definition: pixfmt.h:229
SelectiveColorContext::cmyk_adjust
float cmyk_adjust[NB_RANGES][4]
Definition: vf_selectivecolor.c:84
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
get_range_scale_func
int(* get_range_scale_func)(int r, int g, int b, int min_val, int max_val)
Definition: vf_selectivecolor.c:68
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
process_range
Definition: vf_selectivecolor.c:70
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
avfilter.h
selectivecolor_outputs
static const AVFilterPad selectivecolor_outputs[]
Definition: vf_selectivecolor.c:465
file.h
selectivecolor_inputs
static const AVFilterPad selectivecolor_inputs[]
Definition: vf_selectivecolor.c:455
AVFilterContext
An instance of a filter.
Definition: avfilter.h:333
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
desc
const char * desc
Definition: libsvtav1.c:79
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
ThreadData::in
AVFrame * in
Definition: af_adenorm.c:223
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:70
ff_fill_rgba_map
int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt)
Definition: drawutils.c:35
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
AV_PIX_FMT_0RGB
@ AV_PIX_FMT_0RGB
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
Definition: pixfmt.h:227
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
READ16
#define READ16(dst)
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_selectivecolor.c:414
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:229
drawutils.h
int
int
Definition: ffmpeg_filter.c:156
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
CORRECTION_METHOD_RELATIVE
@ CORRECTION_METHOD_RELATIVE
Definition: vf_selectivecolor.c:60
funcs
CheckasmFunc * funcs
Definition: checkasm.c:270
min
float min
Definition: vorbis_enc_data.h:429