68 char *comp_expr_str[4];
86 #define OFFSET(x) offsetof(LutContext, x)
89 {
"c0",
"set component #0 expression",
OFFSET(comp_expr_str[0]),
AV_OPT_TYPE_STRING, {.str=
"val"}, CHAR_MIN, CHAR_MAX},
90 {
"c1",
"set component #1 expression",
OFFSET(comp_expr_str[1]),
AV_OPT_TYPE_STRING, {.str=
"val"}, CHAR_MIN, CHAR_MAX},
91 {
"c2",
"set component #2 expression",
OFFSET(comp_expr_str[2]),
AV_OPT_TYPE_STRING, {.str=
"val"}, CHAR_MIN, CHAR_MAX},
92 {
"c3",
"set component #3 expression",
OFFSET(comp_expr_str[3]),
AV_OPT_TYPE_STRING, {.str=
"val"}, CHAR_MIN, CHAR_MAX},
139 for (i = 0; i < 4; i++) {
146 #define YUV_FORMATS \
147 AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P, \
148 AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV440P, \
149 AV_PIX_FMT_YUVA420P, \
150 AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ420P, \
153 #define RGB_FORMATS \
154 AV_PIX_FMT_ARGB, AV_PIX_FMT_RGBA, \
155 AV_PIX_FMT_ABGR, AV_PIX_FMT_BGRA, \
156 AV_PIX_FMT_RGB24, AV_PIX_FMT_BGR24
176 static double clip(
void *opaque,
double val)
182 return av_clip(val, minval, maxval);
196 return pow((val-minval)/(maxval-minval), gamma) * (maxval-minval)+minval;
199 static double (*
const funcs1[])(
void *, double) = {
233 min[
Y] = min[
U] = min[
V] = 16;
235 max[
U] = max[
V] = 240;
236 min[
A] = 0; max[
A] = 255;
239 min[0] = min[1] = min[2] = min[3] = 0;
240 max[0] = max[1] = max[2] = max[3] = 255;
267 "Error when parsing the expression '%s' for the component %d.\n",
276 for (val = 0; val < 256; val++) {
281 min[comp], max[comp]);
286 "Error when evaluating the expression '%s' for the value %d for the component #%d.\n",
290 lut->
lut[
comp][val] = av_clip((
int)res, min[comp], max[comp]);
304 uint8_t *inrow, *outrow, *inrow0, *outrow0;
316 inrow0 = in ->
data[0];
317 outrow0 = out->
data[0];
319 for (i = 0; i < in->
video->
h; i ++) {
322 for (j = 0; j < inlink->
w; j++) {
323 for (k = 0; k < lut->
step; k++)
333 for (plane = 0; plane < 4 && in->
data[plane]; plane++) {
334 int vsub = plane == 1 || plane == 2 ? lut->
vsub : 0;
335 int hsub = plane == 1 || plane == 2 ? lut->
hsub : 0;
337 inrow = in ->
data[plane];
338 outrow = out->
data[plane];
340 for (i = 0; i < in->
video->
h >> vsub; i ++) {
341 for (j = 0; j < inlink->
w>>hsub; j++)
342 outrow[j] = lut->
lut[plane][inrow[j]];
366 #define DEFINE_LUT_FILTER(name_, description_, init_) \
367 AVFilter avfilter_vf_##name_ = { \
369 .description = NULL_IF_CONFIG_SMALL(description_), \
370 .priv_size = sizeof(LutContext), \
374 .query_formats = query_formats, \
377 .outputs = outputs, \
380 #if CONFIG_LUT_FILTER
383 #if CONFIG_LUTYUV_FILTER
386 #if CONFIG_LUTRGB_FILTER
390 #if CONFIG_NEGATE_FILTER
402 snprintf(lut_params,
sizeof(lut_params),
"c0=negval:c1=negval:c2=negval:a=%s",
405 return init(ctx, lut_params);
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
AVFilterBufferRefVideoProps * video
video buffer specific properties
static const char * lut_get_name(void *ctx)
int linesize[8]
number of bytes per line
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
packed RGB 8:8:8, 24bpp, RGBRGB...
int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
Return the number of bits per pixel used by the pixel format described by pixdesc.
int h
agreed upon image height
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
uint8_t lut[4][256]
lookup table for each component
int ff_filter_frame(AVFilterLink *link, AVFilterBufferRef *frame)
Send a frame of data to the next filter.
int av_set_options_string(void *ctx, const char *opts, const char *key_val_sep, const char *pairs_sep)
Parse the key/value pairs list in opts.
#define DEFINE_LUT_FILTER(name_, description_, init_)
static const char *const funcs1_names[]
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.
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
static enum AVPixelFormat yuv_pix_fmts[]
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
#define AV_PERM_READ
can read from the buffer
const char * name
Pad name.
static const char *const var_names[]
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
static const AVClass lut_class
static av_always_inline av_const int isnan(float x)
static double(*const funcs1[])(void *, double)
void avfilter_unref_bufferp(AVFilterBufferRef **ref)
Remove a reference to a buffer and set the pointer to NULL.
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
A filter pad used for either input or output.
A link between two filters.
static enum AVPixelFormat all_pix_fmts[]
AVFilterBufferRef * ff_get_video_buffer(AVFilterLink *link, int perms, int w, int h)
Request a picture buffer with a specific set of permissions.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
void * priv
private data for use by the filter
void av_log(void *avcl, int level, const char *fmt,...)
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
int w
agreed upon image width
double var_values[VAR_VARS_NB]
uint8_t nb_components
The number of components each pixel has, (1-4)
packed RGB 8:8:8, 24bpp, BGRBGR...
int format
agreed upon media format
A reference to an AVFilterBuffer.
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
static const AVFilterPad outputs[]
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
static const AVOption lut_options[]
static int query_formats(AVFilterContext *ctx)
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Describe the class of an AVClass context structure.
const char * name
filter name
static int init(AVFilterContext *ctx, const char *args)
AVFilterLink ** outputs
array of pointers to output links
static enum AVPixelFormat rgb_pix_fmts[]
static const AVFilterPad inputs[]
static int config_props(AVFilterLink *inlink)
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
static av_cold void uninit(AVFilterContext *ctx)
common internal and external API header
static double clip(void *opaque, double val)
Clip value val in the minval - maxval range.
void avfilter_copy_buffer_ref_props(AVFilterBufferRef *dst, AVFilterBufferRef *src)
Copy properties of src to dst, without copying the actual data.
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
#define AV_PERM_WRITE
can write to the buffer
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
AVFilterContext * dst
dest filter
AVFilter * filter
the AVFilter of which this is an instance
uint8_t * data[8]
picture/audio data for each plane
static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *in)
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...
static void comp(unsigned char *dst, int dst_stride, unsigned char *src, int src_stride, int add)
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
AVPixelFormat
Pixel format.
simple arithmetic expression evaluator