65 char *comp_expr_str[4];
83 #define OFFSET(x) offsetof(LutContext, x)
86 {
"c0",
"set component #0 expression",
OFFSET(comp_expr_str[0]),
FF_OPT_TYPE_STRING, {.str=
"val"}, CHAR_MIN, CHAR_MAX},
87 {
"c1",
"set component #1 expression",
OFFSET(comp_expr_str[1]),
FF_OPT_TYPE_STRING, {.str=
"val"}, CHAR_MIN, CHAR_MAX},
88 {
"c2",
"set component #2 expression",
OFFSET(comp_expr_str[2]),
FF_OPT_TYPE_STRING, {.str=
"val"}, CHAR_MIN, CHAR_MAX},
89 {
"c3",
"set component #3 expression",
OFFSET(comp_expr_str[3]),
FF_OPT_TYPE_STRING, {.str=
"val"}, CHAR_MIN, CHAR_MAX},
136 for (i = 0; i < 4; i++) {
143 #define YUV_FORMATS \
144 PIX_FMT_YUV444P, PIX_FMT_YUV422P, PIX_FMT_YUV420P, \
145 PIX_FMT_YUV411P, PIX_FMT_YUV410P, PIX_FMT_YUV440P, \
147 PIX_FMT_YUVJ444P, PIX_FMT_YUVJ422P, PIX_FMT_YUVJ420P, \
150 #define RGB_FORMATS \
151 PIX_FMT_ARGB, PIX_FMT_RGBA, \
152 PIX_FMT_ABGR, PIX_FMT_BGRA, \
153 PIX_FMT_RGB24, PIX_FMT_BGR24
173 static double clip(
void *opaque,
double val)
179 return av_clip(val, minval, maxval);
193 return pow((val-minval)/(maxval-minval), gamma) * (maxval-minval)+minval;
196 static double (*
const funcs1[])(
void *, double) = {
230 min[
Y] = min[
U] = min[
V] = 16;
232 max[
U] = max[
V] = 240;
233 min[
A] = 0; max[
A] = 255;
236 min[0] = min[1] = min[2] = min[3] = 0;
237 max[0] = max[1] = max[2] = max[3] = 255;
264 "Error when parsing the expression '%s' for the component %d.\n",
273 for (val = 0; val < 256; val++) {
278 min[comp], max[comp]);
283 "Error when evaluating the expression '%s' for the value %d for the component #%d.\n",
287 lut->
lut[
comp][val] = av_clip((
int)res, min[comp], max[comp]);
302 uint8_t *inrow, *outrow, *inrow0, *outrow0;
310 for (i = 0; i < h; i ++) {
313 for (j = 0; j < inlink->
w; j++) {
314 for (k = 0; k < lut->
step; k++)
324 for (plane = 0; plane < 4 && inpic->
data[plane]; plane++) {
325 int vsub = plane == 1 || plane == 2 ? lut->
vsub : 0;
326 int hsub = plane == 1 || plane == 2 ? lut->
hsub : 0;
328 inrow = inpic ->
data[plane] + (y>>vsub) * inpic ->linesize[plane];
329 outrow = outpic->
data[plane] + (y>>vsub) * outpic->
linesize[plane];
331 for (i = 0; i < h>>vsub; i ++) {
332 for (j = 0; j < inlink->
w>>hsub; j++)
333 outrow[j] = lut->
lut[plane][inrow[j]];
343 #define DEFINE_LUT_FILTER(name_, description_, init_) \
344 AVFilter avfilter_vf_##name_ = { \
346 .description = NULL_IF_CONFIG_SMALL(description_), \
347 .priv_size = sizeof(LutContext), \
351 .query_formats = query_formats, \
353 .inputs = (AVFilterPad[]) {{ .name = "default", \
354 .type = AVMEDIA_TYPE_VIDEO, \
355 .draw_slice = draw_slice, \
356 .config_props = config_props, \
357 .min_perms = AV_PERM_READ, }, \
359 .outputs = (AVFilterPad[]) {{ .name = "default", \
360 .type = AVMEDIA_TYPE_VIDEO, }, \
364 #if CONFIG_LUT_FILTER
367 #if CONFIG_LUTYUV_FILTER
370 #if CONFIG_LUTRGB_FILTER
374 #if CONFIG_NEGATE_FILTER
376 static int negate_init(
AVFilterContext *ctx,
const char *args,
void *opaque)
386 snprintf(lut_params,
sizeof(lut_params),
"c0=negval:c1=negval:c2=negval:a=%s",
389 return init(ctx, lut_params, opaque);
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
static const char * lut_get_name(void *ctx)
int linesize[8]
number of bytes per line
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
AVFilterBufferRef * out_buf
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_)
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
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.
static int init(AVFilterContext *ctx, const char *args, void *opaque)
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
static const AVClass lut_class
static double(*const funcs1[])(void *, double)
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
A link between two filters.
static enum PixelFormat yuv_pix_fmts[]
void avfilter_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
void * priv
private data for use by the filter
void av_log(void *avcl, int level, const char *fmt,...)
AVFilterFormats * avfilter_make_format_list(const int *fmts)
Create a list of supported formats.
const AVPixFmtDescriptor av_pix_fmt_descriptors[PIX_FMT_NB]
The array of all the pixel format descriptors.
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 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)
static const char * var_names[]
void avfilter_draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
Send a slice to the next filter.
int format
agreed upon media format
A reference to an AVFilterBuffer.
static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static const AVOption lut_options[]
static int query_formats(AVFilterContext *ctx)
Describe the class of an AVClass context structure.
const char * name
filter name
packed RGB 8:8:8, 24bpp, BGRBGR...
AVFilterLink ** outputs
array of pointers to output links
static int config_props(AVFilterLink *inlink)
static enum PixelFormat rgb_pix_fmts[]
static av_cold void uninit(AVFilterContext *ctx)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static double clip(void *opaque, double val)
Clip value val in the minval - maxval range.
packed RGB 8:8:8, 24bpp, RGBRGB...
static enum PixelFormat all_pix_fmts[]
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
AVFilterBufferRef * cur_buf
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
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)
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
simple arithmetic expression evaluator
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)