FFmpeg
vf_hue.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2003 Michael Niedermayer
3  * Copyright (c) 2012 Jeremy Tran
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 /**
23  * @file
24  * Apply a hue/saturation filter to the input video
25  * Ported from MPlayer libmpcodecs/vf_hue.c.
26  */
27 
28 #include <float.h>
29 #include "libavutil/eval.h"
30 #include "libavutil/imgutils.h"
31 #include "libavutil/opt.h"
32 #include "libavutil/pixdesc.h"
33 
34 #include "avfilter.h"
35 #include "formats.h"
36 #include "internal.h"
37 #include "video.h"
38 
39 #define SAT_MIN_VAL -10
40 #define SAT_MAX_VAL 10
41 
42 static const char *const var_names[] = {
43  "n", // frame count
44  "pts", // presentation timestamp expressed in AV_TIME_BASE units
45  "r", // frame rate
46  "t", // timestamp expressed in seconds
47  "tb", // timebase
48  NULL
49 };
50 
51 enum var_name {
58 };
59 
60 typedef struct HueContext {
61  const AVClass *class;
62  float hue_deg; /* hue expressed in degrees */
63  float hue; /* hue expressed in radians */
64  char *hue_deg_expr;
65  char *hue_expr;
68  float saturation;
71  float brightness;
74  int hsub;
75  int vsub;
76  int is_first;
79  double var_values[VAR_NB];
80  uint8_t lut_l[256];
81  uint8_t lut_u[256][256];
82  uint8_t lut_v[256][256];
83  uint16_t lut_l16[65536];
84  uint16_t lut_u10[1024][1024];
85  uint16_t lut_v10[1024][1024];
86 } HueContext;
87 
88 #define OFFSET(x) offsetof(HueContext, x)
89 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
90 static const AVOption hue_options[] = {
91  { "h", "set the hue angle degrees expression", OFFSET(hue_deg_expr), AV_OPT_TYPE_STRING,
92  { .str = NULL }, .flags = FLAGS },
93  { "s", "set the saturation expression", OFFSET(saturation_expr), AV_OPT_TYPE_STRING,
94  { .str = "1" }, .flags = FLAGS },
95  { "H", "set the hue angle radians expression", OFFSET(hue_expr), AV_OPT_TYPE_STRING,
96  { .str = NULL }, .flags = FLAGS },
97  { "b", "set the brightness expression", OFFSET(brightness_expr), AV_OPT_TYPE_STRING,
98  { .str = "0" }, .flags = FLAGS },
99  { NULL }
100 };
101 
103 
104 static inline void compute_sin_and_cos(HueContext *hue)
105 {
106  /*
107  * Scale the value to the norm of the resulting (U,V) vector, that is
108  * the saturation.
109  * This will be useful in the apply_lut function.
110  */
111  hue->hue_sin = lrint(sin(hue->hue) * (1 << 16) * hue->saturation);
112  hue->hue_cos = lrint(cos(hue->hue) * (1 << 16) * hue->saturation);
113 }
114 
115 static inline void create_luma_lut(HueContext *h)
116 {
117  const float b = h->brightness;
118  int i;
119 
120  for (i = 0; i < 256; i++) {
121  h->lut_l[i] = av_clip_uint8(i + b * 25.5);
122  }
123  for (i = 0; i < 65536; i++) {
124  h->lut_l16[i] = av_clip_uintp2(i + b * 102.4, 10);
125  }
126 }
127 
128 static inline void create_chrominance_lut(HueContext *h, const int32_t c,
129  const int32_t s)
130 {
131  int32_t i, j, u, v, new_u, new_v;
132 
133  /*
134  * If we consider U and V as the components of a 2D vector then its angle
135  * is the hue and the norm is the saturation
136  */
137  for (i = 0; i < 256; i++) {
138  for (j = 0; j < 256; j++) {
139  /* Normalize the components from range [16;240] to [-112;112] */
140  u = i - 128;
141  v = j - 128;
142  /*
143  * Apply the rotation of the vector : (c * u) - (s * v)
144  * (s * u) + (c * v)
145  * De-normalize the components (without forgetting to scale 128
146  * by << 16)
147  * Finally scale back the result by >> 16
148  */
149  new_u = ((c * u) - (s * v) + (1 << 15) + (128 << 16)) >> 16;
150  new_v = ((s * u) + (c * v) + (1 << 15) + (128 << 16)) >> 16;
151 
152  /* Prevent a potential overflow */
153  h->lut_u[i][j] = av_clip_uint8(new_u);
154  h->lut_v[i][j] = av_clip_uint8(new_v);
155  }
156  }
157  for (i = 0; i < 1024; i++) {
158  for (j = 0; j < 1024; j++) {
159  u = i - 512;
160  v = j - 512;
161  /*
162  * Apply the rotation of the vector : (c * u) - (s * v)
163  * (s * u) + (c * v)
164  * De-normalize the components (without forgetting to scale 512
165  * by << 16)
166  * Finally scale back the result by >> 16
167  */
168  new_u = ((c * u) - (s * v) + (1 << 15) + (512 << 16)) >> 16;
169  new_v = ((s * u) + (c * v) + (1 << 15) + (512 << 16)) >> 16;
170 
171  /* Prevent a potential overflow */
172  h->lut_u10[i][j] = av_clip_uintp2(new_u, 10);
173  h->lut_v10[i][j] = av_clip_uintp2(new_v, 10);
174  }
175  }
176 }
177 
178 static int set_expr(AVExpr **pexpr_ptr, char **expr_ptr,
179  const char *expr, const char *option, void *log_ctx)
180 {
181  int ret;
182  AVExpr *new_pexpr;
183  char *new_expr;
184 
185  new_expr = av_strdup(expr);
186  if (!new_expr)
187  return AVERROR(ENOMEM);
188  ret = av_expr_parse(&new_pexpr, expr, var_names,
189  NULL, NULL, NULL, NULL, 0, log_ctx);
190  if (ret < 0) {
191  av_log(log_ctx, AV_LOG_ERROR,
192  "Error when evaluating the expression '%s' for %s\n",
193  expr, option);
194  av_free(new_expr);
195  return ret;
196  }
197 
198  if (*pexpr_ptr)
199  av_expr_free(*pexpr_ptr);
200  *pexpr_ptr = new_pexpr;
201  av_freep(expr_ptr);
202  *expr_ptr = new_expr;
203 
204  return 0;
205 }
206 
208 {
209  HueContext *hue = ctx->priv;
210  int ret;
211 
212  if (hue->hue_expr && hue->hue_deg_expr) {
213  av_log(ctx, AV_LOG_ERROR,
214  "H and h options are incompatible and cannot be specified "
215  "at the same time\n");
216  return AVERROR(EINVAL);
217  }
218 
219 #define SET_EXPR(expr, option) \
220  if (hue->expr##_expr) do { \
221  ret = set_expr(&hue->expr##_pexpr, &hue->expr##_expr, \
222  hue->expr##_expr, option, ctx); \
223  if (ret < 0) \
224  return ret; \
225  } while (0)
226  SET_EXPR(brightness, "b");
227  SET_EXPR(saturation, "s");
228  SET_EXPR(hue_deg, "h");
229  SET_EXPR(hue, "H");
230 #undef SET_EXPR
231 
232  av_log(ctx, AV_LOG_VERBOSE,
233  "H_expr:%s h_deg_expr:%s s_expr:%s b_expr:%s\n",
234  hue->hue_expr, hue->hue_deg_expr, hue->saturation_expr, hue->brightness_expr);
235  compute_sin_and_cos(hue);
236  hue->is_first = 1;
237 
238  return 0;
239 }
240 
242 {
243  HueContext *hue = ctx->priv;
244 
247  av_expr_free(hue->hue_pexpr);
249 }
250 
252 {
253  static const enum AVPixelFormat pix_fmts[] = {
265  };
266  AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
267  if (!fmts_list)
268  return AVERROR(ENOMEM);
269  return ff_set_common_formats(ctx, fmts_list);
270 }
271 
273 {
274  HueContext *hue = inlink->dst->priv;
276 
277  hue->hsub = desc->log2_chroma_w;
278  hue->vsub = desc->log2_chroma_h;
279 
280  hue->var_values[VAR_N] = 0;
281  hue->var_values[VAR_TB] = av_q2d(inlink->time_base);
282  hue->var_values[VAR_R] = inlink->frame_rate.num == 0 || inlink->frame_rate.den == 0 ?
283  NAN : av_q2d(inlink->frame_rate);
284 
285  return 0;
286 }
287 
289  uint8_t *ldst, const int dst_linesize,
290  uint8_t *lsrc, const int src_linesize,
291  int w, int h)
292 {
293  int i;
294 
295  while (h--) {
296  for (i = 0; i < w; i++)
297  ldst[i] = s->lut_l[lsrc[i]];
298 
299  lsrc += src_linesize;
300  ldst += dst_linesize;
301  }
302 }
303 
305  uint16_t *ldst, const int dst_linesize,
306  uint16_t *lsrc, const int src_linesize,
307  int w, int h)
308 {
309  int i;
310 
311  while (h--) {
312  for (i = 0; i < w; i++)
313  ldst[i] = s->lut_l16[lsrc[i]];
314 
315  lsrc += src_linesize;
316  ldst += dst_linesize;
317  }
318 }
319 
320 static void apply_lut(HueContext *s,
321  uint8_t *udst, uint8_t *vdst, const int dst_linesize,
322  uint8_t *usrc, uint8_t *vsrc, const int src_linesize,
323  int w, int h)
324 {
325  int i;
326 
327  while (h--) {
328  for (i = 0; i < w; i++) {
329  const int u = usrc[i];
330  const int v = vsrc[i];
331 
332  udst[i] = s->lut_u[u][v];
333  vdst[i] = s->lut_v[u][v];
334  }
335 
336  usrc += src_linesize;
337  vsrc += src_linesize;
338  udst += dst_linesize;
339  vdst += dst_linesize;
340  }
341 }
342 
343 static void apply_lut10(HueContext *s,
344  uint16_t *udst, uint16_t *vdst, const int dst_linesize,
345  uint16_t *usrc, uint16_t *vsrc, const int src_linesize,
346  int w, int h)
347 {
348  int i;
349 
350  while (h--) {
351  for (i = 0; i < w; i++) {
352  const int u = av_clip_uintp2(usrc[i], 10);
353  const int v = av_clip_uintp2(vsrc[i], 10);
354 
355  udst[i] = s->lut_u10[u][v];
356  vdst[i] = s->lut_v10[u][v];
357  }
358 
359  usrc += src_linesize;
360  vsrc += src_linesize;
361  udst += dst_linesize;
362  vdst += dst_linesize;
363  }
364 }
365 
367 {
368  HueContext *hue = inlink->dst->priv;
369  AVFilterLink *outlink = inlink->dst->outputs[0];
370  AVFrame *outpic;
371  const int32_t old_hue_sin = hue->hue_sin, old_hue_cos = hue->hue_cos;
372  const float old_brightness = hue->brightness;
373  int direct = 0;
375  const int bps = desc->comp[0].depth > 8 ? 2 : 1;
376 
377  if (av_frame_is_writable(inpic)) {
378  direct = 1;
379  outpic = inpic;
380  } else {
381  outpic = ff_get_video_buffer(outlink, outlink->w, outlink->h);
382  if (!outpic) {
383  av_frame_free(&inpic);
384  return AVERROR(ENOMEM);
385  }
386  av_frame_copy_props(outpic, inpic);
387  }
388 
389  hue->var_values[VAR_N] = inlink->frame_count_out;
390  hue->var_values[VAR_T] = TS2T(inpic->pts, inlink->time_base);
391  hue->var_values[VAR_PTS] = TS2D(inpic->pts);
392 
393  if (hue->saturation_expr) {
395 
396  if (hue->saturation < SAT_MIN_VAL || hue->saturation > SAT_MAX_VAL) {
397  hue->saturation = av_clip(hue->saturation, SAT_MIN_VAL, SAT_MAX_VAL);
398  av_log(inlink->dst, AV_LOG_WARNING,
399  "Saturation value not in range [%d,%d]: clipping value to %0.1f\n",
401  }
402  }
403 
404  if (hue->brightness_expr) {
406 
407  if (hue->brightness < -10 || hue->brightness > 10) {
408  hue->brightness = av_clipf(hue->brightness, -10, 10);
409  av_log(inlink->dst, AV_LOG_WARNING,
410  "Brightness value not in range [%d,%d]: clipping value to %0.1f\n",
411  -10, 10, hue->brightness);
412  }
413  }
414 
415  if (hue->hue_deg_expr) {
416  hue->hue_deg = av_expr_eval(hue->hue_deg_pexpr, hue->var_values, NULL);
417  hue->hue = hue->hue_deg * M_PI / 180;
418  } else if (hue->hue_expr) {
419  hue->hue = av_expr_eval(hue->hue_pexpr, hue->var_values, NULL);
420  hue->hue_deg = hue->hue * 180 / M_PI;
421  }
422 
423  av_log(inlink->dst, AV_LOG_DEBUG,
424  "H:%0.1f*PI h:%0.1f s:%0.1f b:%0.f t:%0.1f n:%d\n",
425  hue->hue/M_PI, hue->hue_deg, hue->saturation, hue->brightness,
426  hue->var_values[VAR_T], (int)hue->var_values[VAR_N]);
427 
428  compute_sin_and_cos(hue);
429  if (hue->is_first || (old_hue_sin != hue->hue_sin || old_hue_cos != hue->hue_cos))
430  create_chrominance_lut(hue, hue->hue_cos, hue->hue_sin);
431 
432  if (hue->is_first || (old_brightness != hue->brightness && hue->brightness))
433  create_luma_lut(hue);
434 
435  if (!direct) {
436  if (!hue->brightness)
437  av_image_copy_plane(outpic->data[0], outpic->linesize[0],
438  inpic->data[0], inpic->linesize[0],
439  inlink->w * bps, inlink->h);
440  if (inpic->data[3])
441  av_image_copy_plane(outpic->data[3], outpic->linesize[3],
442  inpic->data[3], inpic->linesize[3],
443  inlink->w * bps, inlink->h);
444  }
445 
446  if (bps > 1) {
447  apply_lut10(hue, (uint16_t*)outpic->data[1], (uint16_t*)outpic->data[2], outpic->linesize[1]/2,
448  (uint16_t*) inpic->data[1], (uint16_t*) inpic->data[2], inpic->linesize[1]/2,
449  AV_CEIL_RSHIFT(inlink->w, hue->hsub),
450  AV_CEIL_RSHIFT(inlink->h, hue->vsub));
451  if (hue->brightness)
452  apply_luma_lut10(hue, (uint16_t*)outpic->data[0], outpic->linesize[0]/2,
453  (uint16_t*) inpic->data[0], inpic->linesize[0]/2, inlink->w, inlink->h);
454  } else {
455  apply_lut(hue, outpic->data[1], outpic->data[2], outpic->linesize[1],
456  inpic->data[1], inpic->data[2], inpic->linesize[1],
457  AV_CEIL_RSHIFT(inlink->w, hue->hsub),
458  AV_CEIL_RSHIFT(inlink->h, hue->vsub));
459  if (hue->brightness)
460  apply_luma_lut(hue, outpic->data[0], outpic->linesize[0],
461  inpic->data[0], inpic->linesize[0], inlink->w, inlink->h);
462  }
463 
464  if (!direct)
465  av_frame_free(&inpic);
466 
467  hue->is_first = 0;
468  return ff_filter_frame(outlink, outpic);
469 }
470 
471 static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
472  char *res, int res_len, int flags)
473 {
474  HueContext *hue = ctx->priv;
475  int ret;
476 
477 #define SET_EXPR(expr, option) \
478  do { \
479  ret = set_expr(&hue->expr##_pexpr, &hue->expr##_expr, \
480  args, option, ctx); \
481  if (ret < 0) \
482  return ret; \
483  } while (0)
484 
485  if (!strcmp(cmd, "h")) {
486  SET_EXPR(hue_deg, "h");
487  av_freep(&hue->hue_expr);
488  } else if (!strcmp(cmd, "H")) {
489  SET_EXPR(hue, "H");
490  av_freep(&hue->hue_deg_expr);
491  } else if (!strcmp(cmd, "s")) {
492  SET_EXPR(saturation, "s");
493  } else if (!strcmp(cmd, "b")) {
494  SET_EXPR(brightness, "b");
495  } else
496  return AVERROR(ENOSYS);
497 
498  return 0;
499 }
500 
501 static const AVFilterPad hue_inputs[] = {
502  {
503  .name = "default",
504  .type = AVMEDIA_TYPE_VIDEO,
505  .filter_frame = filter_frame,
506  .config_props = config_props,
507  },
508  { NULL }
509 };
510 
511 static const AVFilterPad hue_outputs[] = {
512  {
513  .name = "default",
514  .type = AVMEDIA_TYPE_VIDEO,
515  },
516  { NULL }
517 };
518 
520  .name = "hue",
521  .description = NULL_IF_CONFIG_SMALL("Adjust the hue and saturation of the input video."),
522  .priv_size = sizeof(HueContext),
523  .init = init,
524  .uninit = uninit,
527  .inputs = hue_inputs,
528  .outputs = hue_outputs,
529  .priv_class = &hue_class,
531 };
Definition: vf_hue.c:55
#define NULL
Definition: coverity.c:32
#define AV_PIX_FMT_YUV440P10
Definition: pixfmt.h:401
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2573
This structure describes decoded (raw) audio or video data.
Definition: frame.h:308
double var_values[VAR_NB]
Definition: vf_hue.c:79
AVOption.
Definition: opt.h:248
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:436
#define AV_PIX_FMT_YUVA422P10
Definition: pixfmt.h:437
const char * desc
Definition: libsvtav1.c:79
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
misc image utilities
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:200
Main libavfilter public API header.
AVFilter ff_vf_hue
Definition: vf_hue.c:519
uint8_t lut_u[256][256]
Definition: vf_hue.c:81
#define TS2T(ts, tb)
Definition: internal.h:209
#define SAT_MAX_VAL
Definition: vf_hue.c:40
int num
Numerator.
Definition: rational.h:59
static int query_formats(AVFilterContext *ctx)
Definition: vf_hue.c:251
int32_t hue_sin
Definition: vf_hue.c:77
static void create_chrominance_lut(HueContext *h, const int32_t c, const int32_t s)
Definition: vf_hue.c:128
static const AVFilterPad hue_inputs[]
Definition: vf_hue.c:501
#define FLAGS
Definition: vf_hue.c:89
int av_expr_parse(AVExpr **expr, const char *s, const char *const *const_names, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), int log_offset, void *log_ctx)
Parse an expression.
Definition: eval.c:685
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
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:92
Definition: vf_hue.c:56
char * saturation_expr
Definition: vf_hue.c:69
uint8_t lut_v[256][256]
Definition: vf_hue.c:82
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:287
#define SET_EXPR(expr, option)
int hsub
Definition: vf_hue.c:74
#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
const char * name
Pad name.
Definition: internal.h:60
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1091
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:101
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:117
static void compute_sin_and_cos(HueContext *hue)
Definition: vf_hue.c:104
uint8_t
#define av_cold
Definition: attributes.h:88
AVOptions.
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
av_frame_free & inpic
Definition: vf_mcdeint.c:278
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:401
Definition: eval.c:157
#define u(width, name, range_min, range_max)
Definition: cbs_h2645.c:262
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition: rational.h:104
float brightness
Definition: vf_hue.c:71
char * hue_deg_expr
Definition: vf_hue.c:64
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:210
static void apply_luma_lut10(HueContext *s, uint16_t *ldst, const int dst_linesize, uint16_t *lsrc, const int src_linesize, int w, int h)
Definition: vf_hue.c:304
float hue_deg
Definition: vf_hue.c:62
static void create_luma_lut(HueContext *h)
Definition: vf_hue.c:115
#define av_log(a,...)
Definition: vf_hue.c:52
A filter pad used for either input or output.
Definition: internal.h:54
uint8_t lut_l[256]
Definition: vf_hue.c:80
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Definition: vf_hue.c:471
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:176
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
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:588
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:101
static av_cold int init(AVFilterContext *ctx)
Definition: vf_hue.c:207
#define SAT_MIN_VAL
Definition: vf_hue.c:39
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:203
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:153
void * priv
private data for use by the filter
Definition: avfilter.h:356
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:215
AVExpr * saturation_pexpr
Definition: vf_hue.c:70
static void direct(const float *in, const FFTComplex *ir, int len, float *out)
Definition: af_afir.c:60
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:402
static void apply_lut10(HueContext *s, uint16_t *udst, uint16_t *vdst, const int dst_linesize, uint16_t *usrc, uint16_t *vsrc, const int src_linesize, int w, int h)
Definition: vf_hue.c:343
float saturation
Definition: vf_hue.c:68
float hue
Definition: vf_hue.c:63
AVExpr * brightness_pexpr
Definition: vf_hue.c:73
static int filter_frame(AVFilterLink *inlink, AVFrame *inpic)
Definition: vf_hue.c:366
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
var_name
Definition: aeval.c:46
int is_first
Definition: vf_hue.c:76
#define b
Definition: input.c:41
static void apply_lut(HueContext *s, uint8_t *udst, uint8_t *vdst, const int dst_linesize, uint8_t *usrc, uint8_t *vsrc, const int src_linesize, int w, int h)
Definition: vf_hue.c:320
#define NAN
Definition: mathematics.h:64
uint16_t lut_l16[65536]
Definition: vf_hue.c:83
Definition: vf_hue.c:54
uint8_t w
Definition: llviddspenc.c:38
int32_t
AVFormatContext * ctx
Definition: movenc.c:48
#define s(width, name)
Definition: cbs_vp9.c:257
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:438
AVFILTER_DEFINE_CLASS(hue)
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
uint16_t lut_v10[1024][1024]
Definition: vf_hue.c:85
AVExpr * hue_pexpr
Definition: vf_hue.c:67
int32_t hue_cos
Definition: vf_hue.c:78
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:253
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
Definition: eval.c:336
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_hue.c:241
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:607
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:339
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:177
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
AVExpr * hue_deg_pexpr
Definition: vf_hue.c:66
#define TS2D(ts)
Definition: internal.h:208
Definition: vf_hue.c:53
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
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:399
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:72
Describe the class of an AVClass context structure.
Definition: log.h:67
Filter definition.
Definition: avfilter.h:145
option
Definition: libkvazaar.c:316
static int set_expr(AVExpr **pexpr_ptr, char **expr_ptr, const char *expr, const char *option, void *log_ctx)
Definition: vf_hue.c:178
const char * name
Filter name.
Definition: avfilter.h:149
static const AVOption hue_options[]
Definition: vf_hue.c:90
static const AVFilterPad hue_outputs[]
Definition: vf_hue.c:511
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:353
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:300
#define flags(name, subs,...)
Definition: cbs_av1.c:560
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:400
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:322
char * hue_expr
Definition: vf_hue.c:65
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: vf_hue.c:57
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
char * brightness_expr
Definition: vf_hue.c:72
static void apply_luma_lut(HueContext *s, uint8_t *ldst, const int dst_linesize, uint8_t *lsrc, const int src_linesize, int w, int h)
Definition: vf_hue.c:288
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:73
int vsub
Definition: vf_hue.c:75
int den
Denominator.
Definition: rational.h:60
unsigned bps
Definition: movenc.c:1598
#define av_free(p)
#define OFFSET(x)
Definition: vf_hue.c:88
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
Definition: eval.c:766
A list of supported formats for one end of a filter link.
Definition: formats.h:65
#define lrint
Definition: tablegen.h:53
An instance of a filter.
Definition: avfilter.h:341
#define av_freep(p)
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:99
uint16_t lut_u10[1024][1024]
Definition: vf_hue.c:84
#define M_PI
Definition: mathematics.h:52
void av_image_copy_plane(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, int bytewidth, int height)
Copy image plane from src to dst.
Definition: imgutils.c:373
internal API functions
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
static int config_props(AVFilterLink *inlink)
Definition: vf_hue.c:272
int depth
Number of bits in the component.
Definition: pixdesc.h:58
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
static const char *const var_names[]
Definition: vf_hue.c:42
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:671
int i
Definition: input.c:407
simple arithmetic expression evaluator
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:58