FFmpeg  4.4.9
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 "filters.h"
35 #include "drawutils.h"
36 #include "formats.h"
37 #include "internal.h"
38 #include "video.h"
39 
40 #define R 0
41 #define G 1
42 #define B 2
43 #define A 3
44 
46  // WARNING: do NOT reorder (see parse_psfile())
56  NB_RANGES
57 };
58 
63 };
64 
65 static const char *const color_names[NB_RANGES] = {
66  "red", "yellow", "green", "cyan", "blue", "magenta", "white", "neutral", "black"
67 };
68 
69 typedef int (*get_range_scale_func)(int r, int g, int b, int min_val, int max_val);
70 
71 struct process_range {
72  int range_id;
73  uint32_t mask;
75 };
76 
77 typedef struct ThreadData {
78  AVFrame *in, *out;
79 } ThreadData;
80 
81 typedef struct SelectiveColorContext {
82  const AVClass *class;
86  struct process_range process_ranges[NB_RANGES]; // color ranges to process
88  char *psfile;
90  int is_16bit;
91  int step;
93 
94 #define OFFSET(x) offsetof(SelectiveColorContext, x)
95 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
96 #define RANGE_OPTION(color_name, range) \
97  { color_name"s", "adjust "color_name" regions", OFFSET(opt_cmyk_adjust[range]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS }
98 
99 static const AVOption selectivecolor_options[] = {
100  { "correction_method", "select correction method", OFFSET(correction_method), AV_OPT_TYPE_INT, {.i64 = CORRECTION_METHOD_ABSOLUTE}, 0, NB_CORRECTION_METHODS-1, FLAGS, "correction_method" },
101  { "absolute", NULL, 0, AV_OPT_TYPE_CONST, {.i64=CORRECTION_METHOD_ABSOLUTE}, INT_MIN, INT_MAX, FLAGS, "correction_method" },
102  { "relative", NULL, 0, AV_OPT_TYPE_CONST, {.i64=CORRECTION_METHOD_RELATIVE}, INT_MIN, INT_MAX, FLAGS, "correction_method" },
103  RANGE_OPTION("red", RANGE_REDS),
104  RANGE_OPTION("yellow", RANGE_YELLOWS),
105  RANGE_OPTION("green", RANGE_GREENS),
106  RANGE_OPTION("cyan", RANGE_CYANS),
107  RANGE_OPTION("blue", RANGE_BLUES),
108  RANGE_OPTION("magenta", RANGE_MAGENTAS),
109  RANGE_OPTION("white", RANGE_WHITES),
110  RANGE_OPTION("neutral", RANGE_NEUTRALS),
111  RANGE_OPTION("black", RANGE_BLACKS),
112  { "psfile", "set Photoshop selectivecolor file name", OFFSET(psfile), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
113  { NULL }
114 };
115 
116 AVFILTER_DEFINE_CLASS(selectivecolor);
117 
118 static int get_rgb_scale(int r, int g, int b, int min_val, int max_val)
119 {
120  return max_val - mid_pred(r, g, b);
121 }
122 
123 static int get_cmy_scale(int r, int g, int b, int min_val, int max_val)
124 {
125  return mid_pred(r, g, b) - min_val;
126 }
127 
128 #define DECLARE_RANGE_SCALE_FUNCS(nbits) \
129 static int get_neutrals_scale##nbits(int r, int g, int b, int min_val, int max_val) \
130 { \
131  /* 1 - (|max-0.5| + |min-0.5|) */ \
132  return (((1<<nbits)-1)*2 - ( abs((max_val<<1) - ((1<<nbits)-1)) \
133  + abs((min_val<<1) - ((1<<nbits)-1))) + 1) >> 1; \
134 } \
135  \
136 static int get_whites_scale##nbits(int r, int g, int b, int min_val, int max_val) \
137 { \
138  /* (min - 0.5) * 2 */ \
139  return (min_val<<1) - ((1<<nbits)-1); \
140 } \
141  \
142 static int get_blacks_scale##nbits(int r, int g, int b, int min_val, int max_val) \
143 { \
144  /* (0.5 - max) * 2 */ \
145  return ((1<<nbits)-1) - (max_val<<1); \
146 } \
147 
150 
152 {
153  const float *cmyk = s->cmyk_adjust[range_id];
154 
155  /* If the color range has user settings, register the color range
156  * as "to be processed" */
157  if (cmyk[0] || cmyk[1] || cmyk[2] || cmyk[3]) {
158  struct process_range *pr = &s->process_ranges[s->nb_process_ranges++];
159 
160  if (cmyk[0] < -1.0 || cmyk[0] > 1.0 ||
161  cmyk[1] < -1.0 || cmyk[1] > 1.0 ||
162  cmyk[2] < -1.0 || cmyk[2] > 1.0 ||
163  cmyk[3] < -1.0 || cmyk[3] > 1.0) {
164  av_log(s, AV_LOG_ERROR, "Invalid %s adjustments (%g %g %g %g). "
165  "Settings must be set in [-1;1] range\n",
166  color_names[range_id], cmyk[0], cmyk[1], cmyk[2], cmyk[3]);
167  return AVERROR(EINVAL);
168  }
169 
170  pr->range_id = range_id;
171  pr->mask = 1 << range_id;
172  if (pr->mask & (1<<RANGE_REDS | 1<<RANGE_GREENS | 1<<RANGE_BLUES)) pr->get_scale = get_rgb_scale;
173  else if (pr->mask & (1<<RANGE_CYANS | 1<<RANGE_MAGENTAS | 1<<RANGE_YELLOWS)) pr->get_scale = get_cmy_scale;
174  else if (!s->is_16bit && (pr->mask & 1<<RANGE_WHITES)) pr->get_scale = get_whites_scale8;
175  else if (!s->is_16bit && (pr->mask & 1<<RANGE_NEUTRALS)) pr->get_scale = get_neutrals_scale8;
176  else if (!s->is_16bit && (pr->mask & 1<<RANGE_BLACKS)) pr->get_scale = get_blacks_scale8;
177  else if ( s->is_16bit && (pr->mask & 1<<RANGE_WHITES)) pr->get_scale = get_whites_scale16;
178  else if ( s->is_16bit && (pr->mask & 1<<RANGE_NEUTRALS)) pr->get_scale = get_neutrals_scale16;
179  else if ( s->is_16bit && (pr->mask & 1<<RANGE_BLACKS)) pr->get_scale = get_blacks_scale16;
180  else
181  av_assert0(0);
182  }
183  return 0;
184 }
185 
186 static int parse_psfile(AVFilterContext *ctx, const char *fname)
187 {
188  int16_t val;
189  int ret, i, version;
190  uint8_t *map, *buf;
191  size_t map_size, size;
192  SelectiveColorContext *s = ctx->priv;
193 
194  ret = av_file_map(fname, &map, &map_size, 0, NULL);
195  if (ret < 0)
196  return ret;
197  buf = map;
198  size = map_size;
199 
200 #define READ16(dst) do { \
201  if (size < 2) { \
202  ret = AVERROR_INVALIDDATA; \
203  goto end; \
204  } \
205  dst = AV_RB16(buf); \
206  buf += 2; \
207  size -= 2; \
208 } while (0)
209 
210  READ16(version);
211  if (version != 1)
212  av_log(s, AV_LOG_WARNING, "Unsupported selective color file version %d, "
213  "the settings might not be loaded properly\n", version);
214 
215  READ16(s->correction_method);
216  if (s->correction_method >= NB_CORRECTION_METHODS) {
217  ret = AVERROR_INVALIDDATA;
218  goto end;
219  }
220 
221  // 1st CMYK entry is reserved/unused
222  for (i = 0; i < FF_ARRAY_ELEMS(s->cmyk_adjust[0]); i++) {
223  READ16(val);
224  if (val)
225  av_log(s, AV_LOG_WARNING, "%c value of first CMYK entry is not 0 "
226  "but %d\n", "CMYK"[i], val);
227  }
228 
229  for (i = 0; i < FF_ARRAY_ELEMS(s->cmyk_adjust); i++) {
230  int k;
231  for (k = 0; k < FF_ARRAY_ELEMS(s->cmyk_adjust[0]); k++) {
232  READ16(val);
233  s->cmyk_adjust[i][k] = val / 100.;
234  }
235  ret = register_range(s, i);
236  if (ret < 0)
237  goto end;
238  }
239 
240 end:
241  av_file_unmap(map, map_size);
242  return ret;
243 }
244 
245 static int config_input(AVFilterLink *inlink)
246 {
247  int i, ret;
248  AVFilterContext *ctx = inlink->dst;
249  SelectiveColorContext *s = ctx->priv;
251 
252  s->is_16bit = desc->comp[0].depth > 8;
253  s->step = av_get_padded_bits_per_pixel(desc) >> (3 + s->is_16bit);
254 
255  ret = ff_fill_rgba_map(s->rgba_map, inlink->format);
256  if (ret < 0)
257  return ret;
258 
259  /* If the following conditions are not met, it will cause trouble while
260  * parsing the PS file */
261  av_assert0(FF_ARRAY_ELEMS(s->cmyk_adjust) == 10 - 1);
262  av_assert0(FF_ARRAY_ELEMS(s->cmyk_adjust[0]) == 4);
263 
264  if (s->psfile) {
265  ret = parse_psfile(ctx, s->psfile);
266  if (ret < 0)
267  return ret;
268  } else {
269  for (i = 0; i < FF_ARRAY_ELEMS(s->opt_cmyk_adjust); i++) {
270  const char *opt_cmyk_adjust = s->opt_cmyk_adjust[i];
271 
272  if (opt_cmyk_adjust) {
273  float *cmyk = s->cmyk_adjust[i];
274 
275  sscanf(s->opt_cmyk_adjust[i], "%f %f %f %f", cmyk, cmyk+1, cmyk+2, cmyk+3);
276  ret = register_range(s, i);
277  if (ret < 0)
278  return ret;
279  }
280  }
281  }
282 
283  av_log(s, AV_LOG_VERBOSE, "Adjustments:%s\n", s->nb_process_ranges ? "" : " none");
284  for (i = 0; i < s->nb_process_ranges; i++) {
285  const struct process_range *pr = &s->process_ranges[i];
286  const float *cmyk = s->cmyk_adjust[pr->range_id];
287 
288  av_log(s, AV_LOG_VERBOSE, "%8ss: C=%6g M=%6g Y=%6g K=%6g\n",
289  color_names[pr->range_id], cmyk[0], cmyk[1], cmyk[2], cmyk[3]);
290  }
291 
292  return 0;
293 }
294 
296 {
297  static const enum AVPixelFormat pix_fmts[] = {
306  };
308  if (!fmts_list)
309  return AVERROR(ENOMEM);
310  return ff_set_common_formats(ctx, fmts_list);
311 }
312 
313 static inline int comp_adjust(int scale, float value, float adjust, float k, int correction_method)
314 {
315  const float min = -value;
316  const float max = 1. - value;
317  float res = (-1. - adjust) * k - adjust;
319  res *= max;
320  return lrint(av_clipf(res, min, max) * scale);
321 }
322 
323 #define DECLARE_SELECTIVE_COLOR_FUNC(nbits) \
324 static inline int selective_color_##nbits(AVFilterContext *ctx, ThreadData *td, \
325  int jobnr, int nb_jobs, int direct, int correction_method) \
326 { \
327  int i, x, y; \
328  const AVFrame *in = td->in; \
329  AVFrame *out = td->out; \
330  const SelectiveColorContext *s = ctx->priv; \
331  const int height = in->height; \
332  const int width = in->width; \
333  const int slice_start = ff_slice_pos(height, jobnr, nb_jobs); \
334  const int slice_end = ff_slice_pos(height, jobnr + 1, nb_jobs); \
335  const int dst_linesize = out->linesize[0]; \
336  const int src_linesize = in->linesize[0]; \
337  const uint8_t roffset = s->rgba_map[R]; \
338  const uint8_t goffset = s->rgba_map[G]; \
339  const uint8_t boffset = s->rgba_map[B]; \
340  const uint8_t aoffset = s->rgba_map[A]; \
341  \
342  for (y = slice_start; y < slice_end; y++) { \
343  uint##nbits##_t *dst = ( uint##nbits##_t *)(out->data[0] + y * dst_linesize); \
344  const uint##nbits##_t *src = (const uint##nbits##_t *)( in->data[0] + y * src_linesize); \
345  \
346  for (x = 0; x < width * s->step; x += s->step) { \
347  const int r = src[x + roffset]; \
348  const int g = src[x + goffset]; \
349  const int b = src[x + boffset]; \
350  const int min_color = FFMIN3(r, g, b); \
351  const int max_color = FFMAX3(r, g, b); \
352  const int is_white = (r > 1<<(nbits-1) && g > 1<<(nbits-1) && b > 1<<(nbits-1)); \
353  const int is_neutral = (r || g || b) && \
354  (r != (1<<nbits)-1 || g != (1<<nbits)-1 || b != (1<<nbits)-1); \
355  const int is_black = (r < 1<<(nbits-1) && g < 1<<(nbits-1) && b < 1<<(nbits-1)); \
356  const uint32_t range_flag = (r == max_color) << RANGE_REDS \
357  | (r == min_color) << RANGE_CYANS \
358  | (g == max_color) << RANGE_GREENS \
359  | (g == min_color) << RANGE_MAGENTAS \
360  | (b == max_color) << RANGE_BLUES \
361  | (b == min_color) << RANGE_YELLOWS \
362  | is_white << RANGE_WHITES \
363  | is_neutral << RANGE_NEUTRALS \
364  | is_black << RANGE_BLACKS; \
365  \
366  const float rnorm = r * (1.f / ((1<<nbits)-1)); \
367  const float gnorm = g * (1.f / ((1<<nbits)-1)); \
368  const float bnorm = b * (1.f / ((1<<nbits)-1)); \
369  int adjust_r = 0, adjust_g = 0, adjust_b = 0; \
370  \
371  for (i = 0; i < s->nb_process_ranges; i++) { \
372  const struct process_range *pr = &s->process_ranges[i]; \
373  \
374  if (range_flag & pr->mask) { \
375  const int scale = pr->get_scale(r, g, b, min_color, max_color); \
376  \
377  if (scale > 0) { \
378  const float *cmyk_adjust = s->cmyk_adjust[pr->range_id]; \
379  const float adj_c = cmyk_adjust[0]; \
380  const float adj_m = cmyk_adjust[1]; \
381  const float adj_y = cmyk_adjust[2]; \
382  const float k = cmyk_adjust[3]; \
383  \
384  adjust_r += comp_adjust(scale, rnorm, adj_c, k, correction_method); \
385  adjust_g += comp_adjust(scale, gnorm, adj_m, k, correction_method); \
386  adjust_b += comp_adjust(scale, bnorm, adj_y, k, correction_method); \
387  } \
388  } \
389  } \
390  \
391  if (!direct || adjust_r || adjust_g || adjust_b) { \
392  dst[x + roffset] = av_clip_uint##nbits(r + adjust_r); \
393  dst[x + goffset] = av_clip_uint##nbits(g + adjust_g); \
394  dst[x + boffset] = av_clip_uint##nbits(b + adjust_b); \
395  if (!direct && s->step == 4) \
396  dst[x + aoffset] = src[x + aoffset]; \
397  } \
398  } \
399  } \
400  return 0; \
401 }
402 
403 #define DEF_SELECTIVE_COLOR_FUNC(name, direct, correction_method, nbits) \
404 static int selective_color_##name##_##nbits(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) \
405 { \
406  return selective_color_##nbits(ctx, arg, jobnr, nb_jobs, direct, correction_method); \
407 }
408 
409 #define DEF_SELECTIVE_COLOR_FUNCS(nbits) \
410 DECLARE_SELECTIVE_COLOR_FUNC(nbits) \
411 DEF_SELECTIVE_COLOR_FUNC(indirect_absolute, 0, CORRECTION_METHOD_ABSOLUTE, nbits) \
412 DEF_SELECTIVE_COLOR_FUNC(indirect_relative, 0, CORRECTION_METHOD_RELATIVE, nbits) \
413 DEF_SELECTIVE_COLOR_FUNC( direct_absolute, 1, CORRECTION_METHOD_ABSOLUTE, nbits) \
414 DEF_SELECTIVE_COLOR_FUNC( direct_relative, 1, CORRECTION_METHOD_RELATIVE, nbits)
415 
418 
419 typedef int (*selective_color_func_type)(AVFilterContext *ctx, void *td, int jobnr, int nb_jobs);
420 
421 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
422 {
423  AVFilterContext *ctx = inlink->dst;
424  AVFilterLink *outlink = ctx->outputs[0];
425  int direct;
426  AVFrame *out;
427  ThreadData td;
428  const SelectiveColorContext *s = ctx->priv;
429  static const selective_color_func_type funcs[2][2][2] = {
430  {
431  {selective_color_indirect_absolute_8, selective_color_indirect_relative_8},
432  {selective_color_direct_absolute_8, selective_color_direct_relative_8},
433  },{
434  {selective_color_indirect_absolute_16, selective_color_indirect_relative_16},
435  {selective_color_direct_absolute_16, selective_color_direct_relative_16},
436  }
437  };
438 
439  if (av_frame_is_writable(in)) {
440  direct = 1;
441  out = in;
442  } else {
443  direct = 0;
444  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
445  if (!out) {
446  av_frame_free(&in);
447  return AVERROR(ENOMEM);
448  }
450  }
451 
452  td.in = in;
453  td.out = out;
454  ctx->internal->execute(ctx, funcs[s->is_16bit][direct][s->correction_method],
455  &td, NULL, FFMIN(inlink->h, ff_filter_get_nb_threads(ctx)));
456 
457  if (!direct)
458  av_frame_free(&in);
459  return ff_filter_frame(outlink, out);
460 }
461 
463  {
464  .name = "default",
465  .type = AVMEDIA_TYPE_VIDEO,
466  .filter_frame = filter_frame,
467  .config_props = config_input,
468  },
469  { NULL }
470 };
471 
473  {
474  .name = "default",
475  .type = AVMEDIA_TYPE_VIDEO,
476  },
477  { NULL }
478 };
479 
481  .name = "selectivecolor",
482  .description = NULL_IF_CONFIG_SMALL("Apply CMYK adjustments to specific color ranges."),
483  .priv_size = sizeof(SelectiveColorContext),
487  .priv_class = &selectivecolor_class,
489 };
static double val(void *priv, double ch)
Definition: aeval.c:76
static const AVFilterPad inputs[]
Definition: af_acontrast.c:193
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
uint8_t
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1099
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Definition: avfilter.c:805
Main libavfilter public API header.
#define flags(name, subs,...)
Definition: cbs_av1.c:572
#define s(width, name)
Definition: cbs_vp9.c:257
CheckasmFunc * funcs
Definition: checkasm.c:269
#define FFMIN(a, b)
Definition: common.h:105
#define av_clipf
Definition: common.h:170
#define NULL
Definition: coverity.c:32
#define max(a, b)
Definition: cuda_runtime.h:33
int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt)
Definition: drawutils.c:35
misc drawing utilities
double value
Definition: eval.c:100
int
Misc file utilities.
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:587
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:286
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
@ AV_OPT_TYPE_INT
Definition: opt.h:225
@ AV_OPT_TYPE_STRING
Definition: opt.h:229
#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
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:117
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
#define AVERROR(e)
Definition: error.h:43
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:594
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:203
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:658
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:200
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:210
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
const VDPAUPixFmtMap * map
int i
Definition: input.c:407
static void direct(const float *in, const FFTComplex *ir, int len, float *out)
Definition: af_afir.c:60
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
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
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
version
Definition: libkvazaar.c:326
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:309
const char * desc
Definition: libsvtav1.c:83
#define mid_pred
Definition: mathops.h:97
static int adjust(int x, int size)
Definition: mobiclip.c:515
AVOptions.
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:2538
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2573
#define AV_PIX_FMT_BGR48
Definition: pixfmt.h:390
#define AV_PIX_FMT_RGBA64
Definition: pixfmt.h:389
#define AV_PIX_FMT_RGB48
Definition: pixfmt.h:385
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:68
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
Definition: pixfmt.h:240
@ AV_PIX_FMT_ARGB
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: pixfmt.h:92
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:95
@ AV_PIX_FMT_ABGR
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition: pixfmt.h:94
@ AV_PIX_FMT_0BGR
packed BGR 8:8:8, 32bpp, XBGRXBGR... X=unused/undefined
Definition: pixfmt.h:239
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:93
@ AV_PIX_FMT_RGB0
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
Definition: pixfmt.h:238
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:69
@ AV_PIX_FMT_0RGB
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
Definition: pixfmt.h:237
#define AV_PIX_FMT_BGRA64
Definition: pixfmt.h:394
#define td
Definition: regdef.h:70
#define FF_ARRAY_ELEMS(a)
Describe the class of an AVClass context structure.
Definition: log.h:67
An instance of a filter.
Definition: avfilter.h:341
A list of supported formats for one end of a filter link.
Definition: formats.h:65
A filter pad used for either input or output.
Definition: internal.h:54
const char * name
Pad name.
Definition: internal.h:60
Filter definition.
Definition: avfilter.h:145
const char * name
Filter name.
Definition: avfilter.h:149
AVFormatInternal * internal
An opaque field for libavformat internal usage.
Definition: avformat.h:1699
This structure describes decoded (raw) audio or video data.
Definition: frame.h:318
AVOption.
Definition: opt.h:248
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
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.
Definition: dsddec.c:67
AVFrame * out
Definition: af_adeclick.c:505
AVFrame * in
Definition: af_adenorm.c:223
get_range_scale_func get_scale
#define lrint
Definition: tablegen.h:53
#define av_log(a,...)
FILE * out
Definition: movenc.c:54
AVFormatContext * ctx
Definition: movenc.c:48
int size
const char * b
Definition: vf_curves.c:119
const char * g
Definition: vf_curves.c:118
const char * r
Definition: vf_curves.c:117
#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 AVFilterPad selectivecolor_outputs[]
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 int query_formats(AVFilterContext *ctx)
static const AVOption selectivecolor_options[]
static int config_input(AVFilterLink *inlink)
AVFILTER_DEFINE_CLASS(selectivecolor)
#define FLAGS
#define DECLARE_RANGE_SCALE_FUNCS(nbits)
#define READ16(dst)
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
static int parse_psfile(AVFilterContext *ctx, const char *fname)
color_range
@ RANGE_GREENS
@ NB_RANGES
@ RANGE_YELLOWS
@ RANGE_REDS
@ RANGE_MAGENTAS
@ RANGE_CYANS
@ RANGE_BLUES
@ RANGE_NEUTRALS
@ RANGE_WHITES
@ RANGE_BLACKS
AVFilter ff_vf_selectivecolor
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 OFFSET(x)
static int register_range(SelectiveColorContext *s, int range_id)
#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
@ CORRECTION_METHOD_ABSOLUTE
@ CORRECTION_METHOD_RELATIVE
@ NB_CORRECTION_METHODS
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:104
float min