Libav
vf_lut.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011 Stefano Sabatini
3  *
4  * This file is part of Libav.
5  *
6  * Libav 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  * Libav 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 Libav; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
27 #include "libavutil/attributes.h"
28 #include "libavutil/common.h"
29 #include "libavutil/eval.h"
30 #include "libavutil/mathematics.h"
31 #include "libavutil/opt.h"
32 #include "libavutil/pixdesc.h"
33 #include "avfilter.h"
34 #include "formats.h"
35 #include "internal.h"
36 #include "video.h"
37 
38 static const char *const var_names[] = {
39  "E",
40  "PHI",
41  "PI",
42  "w",
43  "h",
44  "val",
45  "maxval",
46  "minval",
47  "negval",
48  "clipval",
49  NULL
50 };
51 
52 enum var_name {
64 };
65 
66 typedef struct LutContext {
67  const AVClass *class;
68  uint8_t lut[4][256];
69  char *comp_expr_str[4];
71  int hsub, vsub;
73  int is_rgb, is_yuv;
74  int rgba_map[4];
75  int step;
76  int negate_alpha; /* only used by negate */
77 } LutContext;
78 
79 #define Y 0
80 #define U 1
81 #define V 2
82 #define R 0
83 #define G 1
84 #define B 2
85 #define A 3
86 
87 #define OFFSET(x) offsetof(LutContext, x)
88 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM
89 
90 static const AVOption lut_options[] = {
91  { "c0", "set component #0 expression", OFFSET(comp_expr_str[0]), AV_OPT_TYPE_STRING, { .str = "val" }, .flags = FLAGS },
92  { "c1", "set component #1 expression", OFFSET(comp_expr_str[1]), AV_OPT_TYPE_STRING, { .str = "val" }, .flags = FLAGS },
93  { "c2", "set component #2 expression", OFFSET(comp_expr_str[2]), AV_OPT_TYPE_STRING, { .str = "val" }, .flags = FLAGS },
94  { "c3", "set component #3 expression", OFFSET(comp_expr_str[3]), AV_OPT_TYPE_STRING, { .str = "val" }, .flags = FLAGS },
95  { "y", "set Y expression", OFFSET(comp_expr_str[Y]), AV_OPT_TYPE_STRING, { .str = "val" }, .flags = FLAGS },
96  { "u", "set U expression", OFFSET(comp_expr_str[U]), AV_OPT_TYPE_STRING, { .str = "val" }, .flags = FLAGS },
97  { "v", "set V expression", OFFSET(comp_expr_str[V]), AV_OPT_TYPE_STRING, { .str = "val" }, .flags = FLAGS },
98  { "r", "set R expression", OFFSET(comp_expr_str[R]), AV_OPT_TYPE_STRING, { .str = "val" }, .flags = FLAGS },
99  { "g", "set G expression", OFFSET(comp_expr_str[G]), AV_OPT_TYPE_STRING, { .str = "val" }, .flags = FLAGS },
100  { "b", "set B expression", OFFSET(comp_expr_str[B]), AV_OPT_TYPE_STRING, { .str = "val" }, .flags = FLAGS },
101  { "a", "set A expression", OFFSET(comp_expr_str[A]), AV_OPT_TYPE_STRING, { .str = "val" }, .flags = FLAGS },
102  { NULL },
103 };
104 
105 static av_cold int init(AVFilterContext *ctx)
106 {
107  LutContext *s = ctx->priv;
108 
109  s->var_values[VAR_PHI] = M_PHI;
110  s->var_values[VAR_PI] = M_PI;
111  s->var_values[VAR_E ] = M_E;
112 
113  s->is_rgb = !strcmp(ctx->filter->name, "lutrgb");
114  s->is_yuv = !strcmp(ctx->filter->name, "lutyuv");
115 
116  return 0;
117 }
118 
119 static av_cold void uninit(AVFilterContext *ctx)
120 {
121  LutContext *s = ctx->priv;
122  int i;
123 
124  for (i = 0; i < 4; i++) {
125  av_expr_free(s->comp_expr[i]);
126  s->comp_expr[i] = NULL;
127  av_freep(&s->comp_expr_str[i]);
128  }
129 }
130 
131 #define YUV_FORMATS \
132  AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P, \
133  AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV440P, \
134  AV_PIX_FMT_YUVA420P, \
135  AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ420P, \
136  AV_PIX_FMT_YUVJ440P
137 
138 #define RGB_FORMATS \
139  AV_PIX_FMT_ARGB, AV_PIX_FMT_RGBA, \
140  AV_PIX_FMT_ABGR, AV_PIX_FMT_BGRA, \
141  AV_PIX_FMT_RGB24, AV_PIX_FMT_BGR24
142 
146 
148 {
149  LutContext *s = ctx->priv;
150 
151  const enum AVPixelFormat *pix_fmts = s->is_rgb ? rgb_pix_fmts :
152  s->is_yuv ? yuv_pix_fmts :
153  all_pix_fmts;
154 
156  return 0;
157 }
158 
162 static double clip(void *opaque, double val)
163 {
164  LutContext *s = opaque;
165  double minval = s->var_values[VAR_MINVAL];
166  double maxval = s->var_values[VAR_MAXVAL];
167 
168  return av_clip(val, minval, maxval);
169 }
170 
175 static double compute_gammaval(void *opaque, double gamma)
176 {
177  LutContext *s = opaque;
178  double val = s->var_values[VAR_CLIPVAL];
179  double minval = s->var_values[VAR_MINVAL];
180  double maxval = s->var_values[VAR_MAXVAL];
181 
182  return pow((val-minval)/(maxval-minval), gamma) * (maxval-minval)+minval;
183 }
184 
185 static double (* const funcs1[])(void *, double) = {
186  clip,
188  NULL
189 };
190 
191 static const char * const funcs1_names[] = {
192  "clip",
193  "gammaval",
194  NULL
195 };
196 
197 static int config_props(AVFilterLink *inlink)
198 {
199  AVFilterContext *ctx = inlink->dst;
200  LutContext *s = ctx->priv;
201  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
202  int min[4], max[4];
203  int val, comp, ret;
204 
205  s->hsub = desc->log2_chroma_w;
206  s->vsub = desc->log2_chroma_h;
207 
208  s->var_values[VAR_W] = inlink->w;
209  s->var_values[VAR_H] = inlink->h;
210 
211  switch (inlink->format) {
212  case AV_PIX_FMT_YUV410P:
213  case AV_PIX_FMT_YUV411P:
214  case AV_PIX_FMT_YUV420P:
215  case AV_PIX_FMT_YUV422P:
216  case AV_PIX_FMT_YUV440P:
217  case AV_PIX_FMT_YUV444P:
218  case AV_PIX_FMT_YUVA420P:
219  min[Y] = min[U] = min[V] = 16;
220  max[Y] = 235;
221  max[U] = max[V] = 240;
222  min[A] = 0; max[A] = 255;
223  break;
224  default:
225  min[0] = min[1] = min[2] = min[3] = 0;
226  max[0] = max[1] = max[2] = max[3] = 255;
227  }
228 
229  s->is_yuv = s->is_rgb = 0;
230  if (ff_fmt_is_in(inlink->format, yuv_pix_fmts)) s->is_yuv = 1;
231  else if (ff_fmt_is_in(inlink->format, rgb_pix_fmts)) s->is_rgb = 1;
232 
233  if (s->is_rgb) {
234  switch (inlink->format) {
235  case AV_PIX_FMT_ARGB: s->rgba_map[A] = 0; s->rgba_map[R] = 1; s->rgba_map[G] = 2; s->rgba_map[B] = 3; break;
236  case AV_PIX_FMT_ABGR: s->rgba_map[A] = 0; s->rgba_map[B] = 1; s->rgba_map[G] = 2; s->rgba_map[R] = 3; break;
237  case AV_PIX_FMT_RGBA:
238  case AV_PIX_FMT_RGB24: s->rgba_map[R] = 0; s->rgba_map[G] = 1; s->rgba_map[B] = 2; s->rgba_map[A] = 3; break;
239  case AV_PIX_FMT_BGRA:
240  case AV_PIX_FMT_BGR24: s->rgba_map[B] = 0; s->rgba_map[G] = 1; s->rgba_map[R] = 2; s->rgba_map[A] = 3; break;
241  }
242  s->step = av_get_bits_per_pixel(desc) >> 3;
243  }
244 
245  for (comp = 0; comp < desc->nb_components; comp++) {
246  double res;
247 
248  /* create the parsed expression */
249  av_expr_free(s->comp_expr[comp]);
250  s->comp_expr[comp] = NULL;
251  ret = av_expr_parse(&s->comp_expr[comp], s->comp_expr_str[comp],
252  var_names, funcs1_names, funcs1, NULL, NULL, 0, ctx);
253  if (ret < 0) {
254  av_log(ctx, AV_LOG_ERROR,
255  "Error when parsing the expression '%s' for the component %d.\n",
256  s->comp_expr_str[comp], comp);
257  return AVERROR(EINVAL);
258  }
259 
260  /* compute the s */
261  s->var_values[VAR_MAXVAL] = max[comp];
262  s->var_values[VAR_MINVAL] = min[comp];
263 
264  for (val = 0; val < 256; val++) {
265  s->var_values[VAR_VAL] = val;
266  s->var_values[VAR_CLIPVAL] = av_clip(val, min[comp], max[comp]);
267  s->var_values[VAR_NEGVAL] =
268  av_clip(min[comp] + max[comp] - s->var_values[VAR_VAL],
269  min[comp], max[comp]);
270 
271  res = av_expr_eval(s->comp_expr[comp], s->var_values, s);
272  if (isnan(res)) {
273  av_log(ctx, AV_LOG_ERROR,
274  "Error when evaluating the expression '%s' for the value %d for the component #%d.\n",
275  s->comp_expr_str[comp], val, comp);
276  return AVERROR(EINVAL);
277  }
278  s->lut[comp][val] = av_clip((int)res, min[comp], max[comp]);
279  av_log(ctx, AV_LOG_DEBUG, "val[%d][%d] = %d\n", comp, val, s->lut[comp][val]);
280  }
281  }
282 
283  return 0;
284 }
285 
286 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
287 {
288  AVFilterContext *ctx = inlink->dst;
289  LutContext *s = ctx->priv;
290  AVFilterLink *outlink = ctx->outputs[0];
291  AVFrame *out;
292  uint8_t *inrow, *outrow, *inrow0, *outrow0;
293  int i, j, k, plane;
294 
295  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
296  if (!out) {
297  av_frame_free(&in);
298  return AVERROR(ENOMEM);
299  }
300  av_frame_copy_props(out, in);
301 
302  if (s->is_rgb) {
303  /* packed */
304  inrow0 = in ->data[0];
305  outrow0 = out->data[0];
306 
307  for (i = 0; i < in->height; i ++) {
308  inrow = inrow0;
309  outrow = outrow0;
310  for (j = 0; j < inlink->w; j++) {
311  for (k = 0; k < s->step; k++)
312  outrow[k] = s->lut[s->rgba_map[k]][inrow[k]];
313  outrow += s->step;
314  inrow += s->step;
315  }
316  inrow0 += in ->linesize[0];
317  outrow0 += out->linesize[0];
318  }
319  } else {
320  /* planar */
321  for (plane = 0; plane < 4 && in->data[plane]; plane++) {
322  int vsub = plane == 1 || plane == 2 ? s->vsub : 0;
323  int hsub = plane == 1 || plane == 2 ? s->hsub : 0;
324 
325  inrow = in ->data[plane];
326  outrow = out->data[plane];
327 
328  for (i = 0; i < in->height >> vsub; i ++) {
329  for (j = 0; j < inlink->w>>hsub; j++)
330  outrow[j] = s->lut[plane][inrow[j]];
331  inrow += in ->linesize[plane];
332  outrow += out->linesize[plane];
333  }
334  }
335  }
336 
337  av_frame_free(&in);
338  return ff_filter_frame(outlink, out);
339 }
340 
341 static const AVFilterPad inputs[] = {
342  { .name = "default",
343  .type = AVMEDIA_TYPE_VIDEO,
344  .filter_frame = filter_frame,
345  .config_props = config_props,
346  },
347  { .name = NULL}
348 };
349 static const AVFilterPad outputs[] = {
350  { .name = "default",
351  .type = AVMEDIA_TYPE_VIDEO, },
352  { .name = NULL}
353 };
354 #define DEFINE_LUT_FILTER(name_, description_, init_, options) \
355  static const AVClass name_ ## _class = { \
356  .class_name = #name_, \
357  .item_name = av_default_item_name, \
358  .option = options, \
359  .version = LIBAVUTIL_VERSION_INT, \
360  }; \
361  AVFilter ff_vf_##name_ = { \
362  .name = #name_, \
363  .description = NULL_IF_CONFIG_SMALL(description_), \
364  .priv_size = sizeof(LutContext), \
365  .priv_class = &name_ ## _class, \
366  \
367  .init = init_, \
368  .uninit = uninit, \
369  .query_formats = query_formats, \
370  \
371  .inputs = inputs, \
372  .outputs = outputs, \
373  }
374 
375 #if CONFIG_LUT_FILTER
376 DEFINE_LUT_FILTER(lut, "Compute and apply a lookup table to the RGB/YUV input video.", init, lut_options);
377 #endif
378 #if CONFIG_LUTYUV_FILTER
379 DEFINE_LUT_FILTER(lutyuv, "Compute and apply a lookup table to the YUV input video.", init, lut_options);
380 #endif
381 #if CONFIG_LUTRGB_FILTER
382 DEFINE_LUT_FILTER(lutrgb, "Compute and apply a lookup table to the RGB input video.", init, lut_options);
383 #endif
384 
385 #if CONFIG_NEGATE_FILTER
386 
387 static const AVOption negate_options[] = {
388  { "negate_alpha", NULL, OFFSET(negate_alpha), AV_OPT_TYPE_INT, { .i64 = 0 }, .flags = FLAGS },
389  { NULL },
390 };
391 
392 static av_cold int negate_init(AVFilterContext *ctx)
393 {
394  LutContext *s = ctx->priv;
395  int i;
396 
397  av_log(ctx, AV_LOG_DEBUG, "negate_alpha:%d\n", s->negate_alpha);
398 
399  for (i = 0; i < 4; i++) {
400  s->comp_expr_str[i] = av_strdup((i == 3 && s->negate_alpha) ?
401  "val" : "negval");
402  if (!s->comp_expr_str[i]) {
403  uninit(ctx);
404  return AVERROR(ENOMEM);
405  }
406  }
407 
408  return init(ctx);
409 }
410 
411 DEFINE_LUT_FILTER(negate, "Negate input video.", negate_init, negate_options);
412 
413 #endif
char * comp_expr_str[4]
Definition: vf_lut.c:69
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1599
This structure describes decoded (raw) audio or video data.
Definition: frame.h:135
AVOption.
Definition: opt.h:234
#define G
Definition: vf_lut.c:83
#define A
Definition: vf_lut.c:85
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:70
Main libavfilter public API header.
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:67
int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
Return the number of bits per pixel used by the pixel format described by pixdesc.
Definition: pixdesc.c:1571
uint8_t lut[4][256]
lookup table for each component
Definition: vf_lut.c:68
#define RGB_FORMATS
Definition: vf_lut.c:138
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_lut.c:286
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;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);returnNULL;}returnac;}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;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->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);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
static const char *const funcs1_names[]
Definition: vf_lut.c:191
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:492
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
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:80
static enum AVPixelFormat yuv_pix_fmts[]
Definition: vf_lut.c:143
Macro definitions for various function/variable attributes.
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:198
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:165
const char * name
Pad name.
Definition: internal.h:42
static const char *const var_names[]
Definition: vf_lut.c:38
#define R
Definition: vf_lut.c:82
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:728
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:104
uint8_t
#define av_cold
Definition: attributes.h:66
AVOptions.
static av_always_inline av_const int isnan(float x)
Definition: libm.h:85
#define DEFINE_LUT_FILTER(name_, description_, init_, options)
Definition: vf_lut.c:354
static double(*const funcs1[])(void *, double)
Definition: vf_lut.c:185
Definition: eval.c:128
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition: pixfmt.h:97
int rgba_map[4]
Definition: vf_lut.c:74
void 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:379
int ff_fmt_is_in(int fmt, const int *fmts)
Tell is a format is contained in the provided list terminated by -1.
Definition: formats.c:154
Definition: vf_lut.c:53
A filter pad used for either input or output.
Definition: internal.h:36
#define YUV_FORMATS
Definition: vf_lut.c:131
static enum AVPixelFormat all_pix_fmts[]
Definition: vf_lut.c:145
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:123
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:89
Definition: vf_lut.c:54
#define AVERROR(e)
Definition: error.h:43
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:69
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:98
void * priv
private data for use by the filter
Definition: avfilter.h:584
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:144
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:168
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: pixfmt.h:95
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:96
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:69
double var_values[VAR_VARS_NB]
Definition: vf_lut.c:72
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:71
int hsub
Definition: vf_lut.c:71
#define OFFSET(x)
Definition: vf_lut.c:87
#define M_E
Definition: ratecontrol.c:39
static av_cold int init(AVFilterContext *ctx)
Definition: vf_lut.c:105
#define U
Definition: vf_lut.c:80
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:68
NULL
Definition: eval.c:55
Definition: vf_lut.c:58
int is_rgb
Definition: vf_lut.c:73
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
Definition: eval.c:195
char * av_strdup(const char *s)
Duplicate the string s.
Definition: mem.c:213
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:153
static const AVFilterPad outputs[]
Definition: vf_lut.c:349
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
static const AVOption lut_options[]
Definition: vf_lut.c:90
static int query_formats(AVFilterContext *ctx)
Definition: vf_lut.c:147
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:71
Describe the class of an AVClass context structure.
Definition: log.h:33
Definition: vf_lut.c:56
#define M_PHI
Definition: mathematics.h:34
const char * name
Filter name.
Definition: avfilter.h:425
int step
Definition: vf_lut.c:75
AVExpr * comp_expr[4]
Definition: vf_lut.c:70
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:578
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:141
static enum AVPixelFormat rgb_pix_fmts[]
Definition: vf_lut.c:144
static const AVFilterPad inputs[]
Definition: vf_lut.c:341
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;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);returnNULL;}returnac;}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;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->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);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
static int config_props(AVFilterLink *inlink)
Definition: vf_lut.c:197
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:65
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_lut.c:119
#define V
Definition: vf_lut.c:81
common internal and external API header
static double clip(void *opaque, double val)
Clip value val in the minval - maxval range.
Definition: vf_lut.c:162
#define Y
Definition: vf_lut.c:79
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:72
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
Definition: eval.c:542
#define FLAGS
Definition: vf_lut.c:88
int negate_alpha
Definition: vf_lut.c:76
int vsub
Definition: vf_lut.c:71
An instance of a filter.
Definition: avfilter.h:563
static double compute_gammaval(void *opaque, double gamma)
Compute gamma correction for value val, assuming the minval-maxval range, val is clipped to a value c...
Definition: vf_lut.c:175
int height
Definition: frame.h:174
static void comp(unsigned char *dst, int dst_stride, unsigned char *src, int src_stride, int add)
Definition: eamad.c:83
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:102
Definition: vf_lut.c:55
internal API functions
#define B
Definition: vf_lut.c:84
float min
AVPixelFormat
Pixel format.
Definition: pixfmt.h:63
int is_yuv
Definition: vf_lut.c:73
const AVFilter * filter
the AVFilter of which this is an instance
Definition: avfilter.h:566
Definition: vf_lut.c:57
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:367
var_name
Definition: setpts.c:58
simple arithmetic expression evaluator