Go to the documentation of this file.
63 uint16_t
lut[4][256 * 256];
82 #define OFFSET(x) offsetof(LutContext, x)
83 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
105 for (
i = 0;
i < 4;
i++) {
112 #define YUV_FORMATS \
113 AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P, \
114 AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV440P, \
115 AV_PIX_FMT_YUVA420P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA444P, \
116 AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ420P, \
117 AV_PIX_FMT_YUVJ440P, \
118 AV_PIX_FMT_YUV444P9LE, AV_PIX_FMT_YUV422P9LE, AV_PIX_FMT_YUV420P9LE, \
119 AV_PIX_FMT_YUV444P10LE, AV_PIX_FMT_YUV422P10LE, AV_PIX_FMT_YUV420P10LE, AV_PIX_FMT_YUV440P10LE, \
120 AV_PIX_FMT_YUV444P12LE, AV_PIX_FMT_YUV422P12LE, AV_PIX_FMT_YUV420P12LE, AV_PIX_FMT_YUV440P12LE, \
121 AV_PIX_FMT_YUV444P14LE, AV_PIX_FMT_YUV422P14LE, AV_PIX_FMT_YUV420P14LE, \
122 AV_PIX_FMT_YUV444P16LE, AV_PIX_FMT_YUV422P16LE, AV_PIX_FMT_YUV420P16LE, \
123 AV_PIX_FMT_YUVA444P16LE, AV_PIX_FMT_YUVA422P16LE, AV_PIX_FMT_YUVA420P16LE
125 #define RGB_FORMATS \
126 AV_PIX_FMT_ARGB, AV_PIX_FMT_RGBA, \
127 AV_PIX_FMT_ABGR, AV_PIX_FMT_BGRA, \
128 AV_PIX_FMT_RGB24, AV_PIX_FMT_BGR24, \
129 AV_PIX_FMT_RGB48LE, AV_PIX_FMT_RGBA64LE, \
130 AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP, \
131 AV_PIX_FMT_GBRP9LE, AV_PIX_FMT_GBRP10LE, \
132 AV_PIX_FMT_GBRAP10LE, \
133 AV_PIX_FMT_GBRP12LE, AV_PIX_FMT_GBRP14LE, \
134 AV_PIX_FMT_GBRP16LE, AV_PIX_FMT_GBRAP12LE, \
137 #define GRAY_FORMATS \
138 AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY9LE, AV_PIX_FMT_GRAY10LE, \
139 AV_PIX_FMT_GRAY12LE, AV_PIX_FMT_GRAY14LE, AV_PIX_FMT_GRAY16LE
178 return pow((
val-minval)/(maxval-minval), gamma) * (maxval-minval)+minval;
190 double level = (
val - minval) / (maxval - minval);
192 : 1.099 * pow(
level, 1.0 / gamma) - 0.099;
193 return level * (maxval - minval) + minval;
196 static double (*
const funcs1[])(
void *, double) = {
219 s->hsub =
desc->log2_chroma_w;
220 s->vsub =
desc->log2_chroma_h;
224 s->is_16bit =
desc->comp[0].depth > 8;
262 min[
Y] = 16 * (1 << (
desc->comp[0].depth - 8));
263 min[
U] = 16 * (1 << (
desc->comp[1].depth - 8));
264 min[
V] = 16 * (1 << (
desc->comp[2].depth - 8));
266 max[
Y] = 235 * (1 << (
desc->comp[0].depth - 8));
267 max[
U] = 240 * (1 << (
desc->comp[1].depth - 8));
268 max[
V] = 240 * (1 << (
desc->comp[2].depth - 8));
269 max[
A] = (1 <<
desc->comp[0].depth) - 1;
281 s->is_yuv =
s->is_rgb = 0;
290 s->step =
s->step >> 1;
305 "Error when parsing the expression '%s' for the component %d and color %d.\n",
324 "Error when evaluating the expression '%s' for the value %d for the component %d.\n",
344 #define LOAD_PACKED_COMMON\
345 LutContext *s = ctx->priv;\
346 const struct thread_data *td = arg;\
349 const int w = td->w;\
350 const int h = td->h;\
351 AVFrame *in = td->in;\
352 AVFrame *out = td->out;\
353 const uint16_t (*tab)[256*256] = (const uint16_t (*)[256*256])s->lut;\
354 const int step = s->step;\
356 const int slice_start = (h * jobnr ) / nb_jobs;\
357 const int slice_end = (h * (jobnr+1)) / nb_jobs;\
364 uint16_t *inrow, *outrow, *inrow0, *outrow0;
365 const int in_linesize = in->linesize[0] / 2;
366 const int out_linesize =
out->linesize[0] / 2;
367 inrow0 = (uint16_t *)in ->
data[0];
368 outrow0 = (uint16_t *)
out->data[0];
371 inrow = inrow0 +
i * in_linesize;
372 outrow = outrow0 +
i * out_linesize;
373 for (j = 0; j <
w; j++) {
382 case 4: outrow[3] =
tab[3][inrow[3]];
383 case 3: outrow[2] =
tab[2][inrow[2]];
384 case 2: outrow[1] =
tab[1][inrow[1]];
385 default: outrow[0] =
tab[0][inrow[0]];
401 uint8_t *inrow, *outrow, *inrow0, *outrow0;
402 const int in_linesize = in->linesize[0];
403 const int out_linesize =
out->linesize[0];
404 inrow0 = in ->data[0];
405 outrow0 =
out->data[0];
408 inrow = inrow0 +
i * in_linesize;
409 outrow = outrow0 +
i * out_linesize;
410 for (j = 0; j <
w; j++) {
412 case 4: outrow[3] =
tab[3][inrow[3]];
413 case 3: outrow[2] =
tab[2][inrow[2]];
414 case 2: outrow[1] =
tab[1][inrow[1]];
415 default: outrow[0] =
tab[0][inrow[0]];
425 #define LOAD_PLANAR_COMMON\
426 LutContext *s = ctx->priv;\
427 const struct thread_data *td = arg;\
429 AVFrame *in = td->in;\
430 AVFrame *out = td->out;\
432 #define PLANAR_COMMON\
433 int vsub = plane == 1 || plane == 2 ? s->vsub : 0;\
434 int hsub = plane == 1 || plane == 2 ? s->hsub : 0;\
435 int h = AV_CEIL_RSHIFT(td->h, vsub);\
436 int w = AV_CEIL_RSHIFT(td->w, hsub);\
437 const uint16_t *tab = s->lut[plane];\
439 const int slice_start = (h * jobnr ) / nb_jobs;\
440 const int slice_end = (h * (jobnr+1)) / nb_jobs;\
447 uint16_t *inrow, *outrow;
449 for (plane = 0; plane < 4 && in->data[plane] && in->linesize[plane]; plane++) {
452 const int in_linesize = in->linesize[plane] / 2;
453 const int out_linesize =
out->linesize[plane] / 2;
455 inrow = (uint16_t *)in ->
data[plane] + slice_start * in_linesize;
456 outrow = (uint16_t *)
out->data[plane] + slice_start * out_linesize;
459 for (j = 0; j <
w; j++) {
463 outrow[j] =
tab[inrow[j]];
466 inrow += in_linesize;
467 outrow += out_linesize;
479 uint8_t *inrow, *outrow;
481 for (plane = 0; plane < 4 && in->data[plane] && in->linesize[plane]; plane++) {
484 const int in_linesize = in->linesize[plane];
485 const int out_linesize =
out->linesize[plane];
487 inrow = in ->data[plane] + slice_start * in_linesize;
488 outrow =
out->data[plane] + slice_start * out_linesize;
491 for (j = 0; j <
w; j++)
492 outrow[j] =
tab[inrow[j]];
493 inrow += in_linesize;
494 outrow += out_linesize;
501 #define PACKED_THREAD_DATA\
502 struct thread_data td = {\
509 #define PLANAR_THREAD_DATA\
510 struct thread_data td = {\
537 if (
s->is_rgb &&
s->is_16bit && !
s->is_planar) {
542 }
else if (
s->is_rgb && !
s->is_planar) {
547 }
else if (
s->is_16bit) {
566 char *res,
int res_len,
int flags)
589 #define DEFINE_LUT_FILTER(name_, description_, priv_class_) \
590 const AVFilter ff_vf_##name_ = { \
592 .description = NULL_IF_CONFIG_SMALL(description_), \
593 .priv_class = &priv_class_ ## _class, \
594 .priv_size = sizeof(LutContext), \
595 .init = name_##_init, \
597 FILTER_INPUTS(inputs), \
598 FILTER_OUTPUTS(outputs), \
599 FILTER_QUERY_FUNC(query_formats), \
600 .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | \
601 AVFILTER_FLAG_SLICE_THREADS, \
602 .process_command = process_command, \
607 #if CONFIG_LUT_FILTER
609 #define lut_init NULL
610 DEFINE_LUT_FILTER(lut,
"Compute and apply a lookup table to the RGB/YUV input video.",
615 #if CONFIG_LUTYUV_FILTER
626 DEFINE_LUT_FILTER(lutyuv,
"Compute and apply a lookup table to the YUV input video.",
630 #if CONFIG_LUTRGB_FILTER
641 DEFINE_LUT_FILTER(lutrgb,
"Compute and apply a lookup table to the RGB input video.",
AVFILTER_DEFINE_CLASS_EXT(lut, "lut/lutyuv/lutrgb", options)
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
@ AV_PIX_FMT_YUV420P9LE
planar YUV 4:2:0, 13.5bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
static void direct(const float *in, const FFTComplex *ir, int len, float *out)
AVPixelFormat
Pixel format.
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 double compute_gammaval709(void *opaque, double gamma)
Compute ITU Rec.709 gamma correction of value val.
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
@ AV_PIX_FMT_YUV422P14LE
planar YUV 4:2:2,28bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
static const AVOption options[]
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
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
This structure describes decoded (raw) audio or video data.
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But a word about which is also called distortion Distortion can be quantified by almost any quality measurement one chooses the sum of squared differences is used but more complex methods that consider psychovisual effects can be used as well It makes no difference in this discussion First step
@ AV_PIX_FMT_YUV420P16LE
planar YUV 4:2:0, 24bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
Return the number of bits per pixel used by the pixel format described by pixdesc.
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
A link between two filters.
@ AV_PIX_FMT_YUV444P16LE
planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
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 enum AVPixelFormat yuv_pix_fmts[]
@ AV_PIX_FMT_YUV420P12LE
planar YUV 4:2:0,18bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
static const char *const var_names[]
static const struct twinvq_data tab
#define PACKED_THREAD_DATA
static double val(void *priv, double ch)
#define LOAD_PACKED_COMMON
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
static const char *const funcs1_names[]
A filter pad used for either input or output.
@ AV_PIX_FMT_YUV420P10LE
planar YUV 4:2:0, 15bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
uint16_t lut[4][256 *256]
lookup table for each component
@ AV_PIX_FMT_YUV444P12LE
planar YUV 4:4:4,36bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
@ AV_PIX_FMT_YUV444P14LE
planar YUV 4:4:4,42bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
static double(*const funcs1[])(void *, double)
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
static enum AVPixelFormat pix_fmts[]
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
static enum AVPixelFormat all_pix_fmts[]
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
#define PLANAR_THREAD_DATA
@ AV_PIX_FMT_YUV444P10LE
planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
@ AV_PIX_FMT_YUVA422P10LE
planar YUV 4:2:2 30bpp, (1 Cr & Cb sample per 2x1 Y & A samples, little-endian)
@ AV_PIX_FMT_YUV422P16LE
planar YUV 4:2:2, 32bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
Describe the class of an AVClass context structure.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
@ AV_PIX_FMT_RGB48LE
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as lit...
@ AV_PIX_FMT_RGBA64LE
packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is st...
@ AV_PIX_FMT_YUVA444P9LE
planar YUV 4:4:4 36bpp, (1 Cr & Cb sample per 1x1 Y & A samples), little-endian
@ AV_PIX_FMT_YUVA420P16LE
planar YUV 4:2:0 40bpp, (1 Cr & Cb sample per 2x2 Y & A samples, little-endian)
@ AV_PIX_FMT_YUV440P10LE
planar YUV 4:4:0,20bpp, (1 Cr & Cb sample per 1x2 Y samples), little-endian
@ AV_PIX_FMT_YUVA420P9LE
planar YUV 4:2:0 22.5bpp, (1 Cr & Cb sample per 2x2 Y & A samples), little-endian
static int lut_packed_8bits(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
@ AV_PIX_FMT_YUV420P14LE
planar YUV 4:2:0,21bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
@ AV_PIX_FMT_YUV440P12LE
planar YUV 4:4:0,24bpp, (1 Cr & Cb sample per 1x2 Y samples), little-endian
static int lut_planar_8bits(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
double var_values[VAR_VARS_NB]
@ AV_PIX_FMT_YUV422P10LE
planar YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
static const uint32_t color[16+AV_CLASS_CATEGORY_NB]
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
#define LOAD_PLANAR_COMMON
int ff_filter_process_command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Generic processing of user supplied commands that are set in the same way as the filter options.
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
static int lut_packed_16bits(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static enum AVPixelFormat rgb_pix_fmts[]
@ AV_PIX_FMT_YUVA420P10LE
planar YUV 4:2:0 25bpp, (1 Cr & Cb sample per 2x2 Y & A samples, little-endian)
#define i(width, name, range_min, range_max)
int w
agreed upon image width
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
static const AVFilterPad outputs[]
const char * name
Pad name.
static const AVFilterPad inputs[]
int h
agreed upon image height
@ AV_PIX_FMT_YUV444P9LE
planar YUV 4:4:4, 27bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
#define AV_PIX_FMT_FLAG_PLANAR
At least one pixel component is not in the first data plane.
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
static int query_formats(AVFilterContext *ctx)
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_YUVA444P10LE
planar YUV 4:4:4 40bpp, (1 Cr & Cb sample per 1x1 Y & A samples, little-endian)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt)
@ AV_PIX_FMT_YUV422P9LE
planar YUV 4:2:2, 18bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
@ AV_PIX_FMT_YUVA422P16LE
planar YUV 4:2:2 48bpp, (1 Cr & Cb sample per 2x1 Y & A samples, little-endian)
#define flags(name, subs,...)
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
static int config_props(AVFilterLink *inlink)
@ AV_PIX_FMT_YUVA444P16LE
planar YUV 4:4:4 64bpp, (1 Cr & Cb sample per 1x1 Y & A samples, little-endian)
static av_always_inline int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
static int lut_planar_16bits(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
@ AV_PIX_FMT_YUV422P12LE
planar YUV 4:2:2,24bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
static av_cold void uninit(AVFilterContext *ctx)
static double clip(void *opaque, double val)
Clip value val in the minval - maxval range.
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...
#define DEFINE_LUT_FILTER(name_, description_, priv_class_)
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
@ AV_PIX_FMT_YUVA422P9LE
planar YUV 4:2:2 27bpp, (1 Cr & Cb sample per 2x1 Y & A samples), little-endian