2012-05-14 20:03:19 +03:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2006 Michael Niedermayer <michaelni@gmx.at>
|
2013-09-03 21:42:24 +03:00
|
|
|
* Copyright (C) 2012 Clément Bœsch <u pkh me>
|
2012-05-14 20:03:19 +03:00
|
|
|
*
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
2012-11-15 23:48:36 +03:00
|
|
|
* FFmpeg is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
2012-05-14 20:03:19 +03:00
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-11-15 23:48:36 +03:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2012-05-14 20:03:19 +03:00
|
|
|
*
|
2012-11-15 23:48:36 +03:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with FFmpeg; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2012-05-14 20:03:19 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Generic equation change filter
|
|
|
|
* Originally written by Michael Niedermayer for the MPlayer project, and
|
|
|
|
* ported by Clément Bœsch for FFmpeg.
|
|
|
|
*/
|
|
|
|
|
2015-06-13 20:49:32 +02:00
|
|
|
#include "libavutil/avassert.h"
|
2012-05-14 20:03:19 +03:00
|
|
|
#include "libavutil/avstring.h"
|
|
|
|
#include "libavutil/eval.h"
|
|
|
|
#include "libavutil/opt.h"
|
|
|
|
#include "libavutil/pixdesc.h"
|
|
|
|
#include "internal.h"
|
|
|
|
|
2019-10-11 18:26:22 +02:00
|
|
|
enum InterpolationMethods {
|
|
|
|
INTERP_NEAREST,
|
|
|
|
INTERP_BILINEAR,
|
|
|
|
NB_INTERP
|
|
|
|
};
|
|
|
|
|
2017-11-30 11:31:38 +02:00
|
|
|
static const char *const var_names[] = { "X", "Y", "W", "H", "N", "SW", "SH", "T", NULL };
|
|
|
|
enum { VAR_X, VAR_Y, VAR_W, VAR_H, VAR_N, VAR_SW, VAR_SH, VAR_T, VAR_VARS_NB };
|
|
|
|
|
2017-05-12 20:00:49 +02:00
|
|
|
typedef struct GEQContext {
|
2012-05-14 20:03:19 +03:00
|
|
|
const AVClass *class;
|
2013-02-25 12:14:24 +03:00
|
|
|
AVExpr *e[4]; ///< expressions for each plane
|
2013-04-23 16:46:51 +03:00
|
|
|
char *expr_str[4+3]; ///< expression strings for each plane
|
2013-03-10 03:30:30 +03:00
|
|
|
AVFrame *picref; ///< current input buffer
|
2018-01-04 09:49:55 +02:00
|
|
|
uint8_t *dst; ///< reference pointer to the 8bits output
|
|
|
|
uint16_t *dst16; ///< reference pointer to the 16bits output
|
|
|
|
double values[VAR_VARS_NB]; ///< expression values
|
2012-05-14 20:03:19 +03:00
|
|
|
int hsub, vsub; ///< chroma subsampling
|
2013-02-25 12:14:24 +03:00
|
|
|
int planes; ///< number of planes
|
2019-10-11 18:26:22 +02:00
|
|
|
int interpolation;
|
2013-04-23 16:46:51 +03:00
|
|
|
int is_rgb;
|
2017-06-30 12:16:04 +02:00
|
|
|
int bps;
|
2012-05-14 20:03:19 +03:00
|
|
|
} GEQContext;
|
|
|
|
|
2013-05-20 00:32:02 +03:00
|
|
|
enum { Y = 0, U, V, A, G, B, R };
|
|
|
|
|
2012-05-14 20:03:19 +03:00
|
|
|
#define OFFSET(x) offsetof(GEQContext, x)
|
|
|
|
#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
|
|
|
|
|
|
|
|
static const AVOption geq_options[] = {
|
2013-05-20 00:32:02 +03:00
|
|
|
{ "lum_expr", "set luminance expression", OFFSET(expr_str[Y]), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
|
|
|
|
{ "lum", "set luminance expression", OFFSET(expr_str[Y]), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
|
|
|
|
{ "cb_expr", "set chroma blue expression", OFFSET(expr_str[U]), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
|
|
|
|
{ "cb", "set chroma blue expression", OFFSET(expr_str[U]), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
|
|
|
|
{ "cr_expr", "set chroma red expression", OFFSET(expr_str[V]), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
|
|
|
|
{ "cr", "set chroma red expression", OFFSET(expr_str[V]), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
|
|
|
|
{ "alpha_expr", "set alpha expression", OFFSET(expr_str[A]), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
|
|
|
|
{ "a", "set alpha expression", OFFSET(expr_str[A]), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
|
|
|
|
{ "red_expr", "set red expression", OFFSET(expr_str[R]), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
|
|
|
|
{ "r", "set red expression", OFFSET(expr_str[R]), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
|
|
|
|
{ "green_expr", "set green expression", OFFSET(expr_str[G]), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
|
|
|
|
{ "g", "set green expression", OFFSET(expr_str[G]), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
|
|
|
|
{ "blue_expr", "set blue expression", OFFSET(expr_str[B]), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
|
|
|
|
{ "b", "set blue expression", OFFSET(expr_str[B]), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
|
2019-10-11 18:26:22 +02:00
|
|
|
{ "interpolation","set interpolation method", OFFSET(interpolation), AV_OPT_TYPE_INT, {.i64=INTERP_BILINEAR}, 0, NB_INTERP-1, FLAGS, "interp" },
|
|
|
|
{ "i", "set interpolation method", OFFSET(interpolation), AV_OPT_TYPE_INT, {.i64=INTERP_BILINEAR}, 0, NB_INTERP-1, FLAGS, "interp" },
|
|
|
|
{ "nearest", "nearest interpolation", 0, AV_OPT_TYPE_CONST, {.i64=INTERP_NEAREST}, 0, 0, FLAGS, "interp" },
|
|
|
|
{ "n", "nearest interpolation", 0, AV_OPT_TYPE_CONST, {.i64=INTERP_NEAREST}, 0, 0, FLAGS, "interp" },
|
|
|
|
{ "bilinear", "bilinear interpolation", 0, AV_OPT_TYPE_CONST, {.i64=INTERP_BILINEAR}, 0, 0, FLAGS, "interp" },
|
|
|
|
{ "b", "bilinear interpolation", 0, AV_OPT_TYPE_CONST, {.i64=INTERP_BILINEAR}, 0, 0, FLAGS, "interp" },
|
2012-05-14 20:03:19 +03:00
|
|
|
{NULL},
|
|
|
|
};
|
|
|
|
|
|
|
|
AVFILTER_DEFINE_CLASS(geq);
|
|
|
|
|
|
|
|
static inline double getpix(void *priv, double x, double y, int plane)
|
|
|
|
{
|
|
|
|
int xi, yi;
|
|
|
|
GEQContext *geq = priv;
|
2013-03-10 03:30:30 +03:00
|
|
|
AVFrame *picref = geq->picref;
|
2012-05-14 20:03:19 +03:00
|
|
|
const uint8_t *src = picref->data[plane];
|
2017-06-30 12:16:04 +02:00
|
|
|
int linesize = picref->linesize[plane];
|
2016-01-27 17:19:38 +02:00
|
|
|
const int w = (plane == 1 || plane == 2) ? AV_CEIL_RSHIFT(picref->width, geq->hsub) : picref->width;
|
|
|
|
const int h = (plane == 1 || plane == 2) ? AV_CEIL_RSHIFT(picref->height, geq->vsub) : picref->height;
|
2013-02-25 12:14:24 +03:00
|
|
|
|
|
|
|
if (!src)
|
|
|
|
return 0;
|
2012-05-14 20:03:19 +03:00
|
|
|
|
2019-10-11 18:26:22 +02:00
|
|
|
if (geq->interpolation == INTERP_BILINEAR) {
|
2019-10-11 18:29:03 +02:00
|
|
|
xi = x = av_clipd(x, 0, w - 2);
|
|
|
|
yi = y = av_clipd(y, 0, h - 2);
|
2012-05-14 20:03:19 +03:00
|
|
|
|
2019-10-11 18:29:03 +02:00
|
|
|
x -= xi;
|
|
|
|
y -= yi;
|
2012-05-14 20:03:19 +03:00
|
|
|
|
2019-10-11 18:29:03 +02:00
|
|
|
if (geq->bps > 8) {
|
|
|
|
const uint16_t *src16 = (const uint16_t*)src;
|
|
|
|
linesize /= 2;
|
2017-06-30 12:16:04 +02:00
|
|
|
|
2019-10-11 18:29:03 +02:00
|
|
|
return (1-y)*((1-x)*src16[xi + yi * linesize] + x*src16[xi + 1 + yi * linesize])
|
|
|
|
+ y *((1-x)*src16[xi + (yi+1) * linesize] + x*src16[xi + 1 + (yi+1) * linesize]);
|
|
|
|
} else {
|
|
|
|
return (1-y)*((1-x)*src[xi + yi * linesize] + x*src[xi + 1 + yi * linesize])
|
|
|
|
+ y *((1-x)*src[xi + (yi+1) * linesize] + x*src[xi + 1 + (yi+1) * linesize]);
|
|
|
|
}
|
2019-10-11 18:26:22 +02:00
|
|
|
} else {
|
|
|
|
xi = av_clipd(x, 0, w - 1);
|
|
|
|
yi = av_clipd(y, 0, h - 1);
|
|
|
|
|
|
|
|
if (geq->bps > 8) {
|
|
|
|
const uint16_t *src16 = (const uint16_t*)src;
|
|
|
|
linesize /= 2;
|
|
|
|
|
|
|
|
return src16[xi + yi * linesize];
|
|
|
|
} else {
|
|
|
|
return src[xi + yi * linesize];
|
|
|
|
}
|
|
|
|
}
|
2012-05-14 20:03:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//TODO: cubic interpolate
|
|
|
|
//TODO: keep the last few frames
|
|
|
|
static double lum(void *priv, double x, double y) { return getpix(priv, x, y, 0); }
|
|
|
|
static double cb(void *priv, double x, double y) { return getpix(priv, x, y, 1); }
|
|
|
|
static double cr(void *priv, double x, double y) { return getpix(priv, x, y, 2); }
|
2013-02-25 12:14:24 +03:00
|
|
|
static double alpha(void *priv, double x, double y) { return getpix(priv, x, y, 3); }
|
2012-05-14 20:03:19 +03:00
|
|
|
|
2013-04-12 12:13:33 +03:00
|
|
|
static av_cold int geq_init(AVFilterContext *ctx)
|
2012-05-14 20:03:19 +03:00
|
|
|
{
|
|
|
|
GEQContext *geq = ctx->priv;
|
|
|
|
int plane, ret = 0;
|
|
|
|
|
2013-05-20 00:32:02 +03:00
|
|
|
if (!geq->expr_str[Y] && !geq->expr_str[G] && !geq->expr_str[B] && !geq->expr_str[R]) {
|
2013-04-23 16:46:51 +03:00
|
|
|
av_log(ctx, AV_LOG_ERROR, "A luminance or RGB expression is mandatory\n");
|
|
|
|
ret = AVERROR(EINVAL);
|
|
|
|
goto end;
|
|
|
|
}
|
2013-05-20 00:32:02 +03:00
|
|
|
geq->is_rgb = !geq->expr_str[Y];
|
2013-04-23 16:46:51 +03:00
|
|
|
|
2013-05-20 00:32:02 +03:00
|
|
|
if ((geq->expr_str[Y] || geq->expr_str[U] || geq->expr_str[V]) && (geq->expr_str[G] || geq->expr_str[B] || geq->expr_str[R])) {
|
2013-04-23 16:46:51 +03:00
|
|
|
av_log(ctx, AV_LOG_ERROR, "Either YCbCr or RGB but not both must be specified\n");
|
2012-05-14 20:03:19 +03:00
|
|
|
ret = AVERROR(EINVAL);
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2013-05-20 00:32:02 +03:00
|
|
|
if (!geq->expr_str[U] && !geq->expr_str[V]) {
|
2012-05-14 20:03:19 +03:00
|
|
|
/* No chroma at all: fallback on luma */
|
2013-05-20 00:32:02 +03:00
|
|
|
geq->expr_str[U] = av_strdup(geq->expr_str[Y]);
|
|
|
|
geq->expr_str[V] = av_strdup(geq->expr_str[Y]);
|
2012-05-14 20:03:19 +03:00
|
|
|
} else {
|
|
|
|
/* One chroma unspecified, fallback on the other */
|
2013-05-20 00:32:02 +03:00
|
|
|
if (!geq->expr_str[U]) geq->expr_str[U] = av_strdup(geq->expr_str[V]);
|
|
|
|
if (!geq->expr_str[V]) geq->expr_str[V] = av_strdup(geq->expr_str[U]);
|
2012-05-14 20:03:19 +03:00
|
|
|
}
|
|
|
|
|
2017-06-30 12:16:04 +02:00
|
|
|
if (!geq->expr_str[A]) {
|
|
|
|
char bps_string[8];
|
|
|
|
snprintf(bps_string, sizeof(bps_string), "%d", (1<<geq->bps) - 1);
|
|
|
|
geq->expr_str[A] = av_strdup(bps_string);
|
|
|
|
}
|
2013-05-20 00:32:02 +03:00
|
|
|
if (!geq->expr_str[G])
|
|
|
|
geq->expr_str[G] = av_strdup("g(X,Y)");
|
|
|
|
if (!geq->expr_str[B])
|
|
|
|
geq->expr_str[B] = av_strdup("b(X,Y)");
|
|
|
|
if (!geq->expr_str[R])
|
|
|
|
geq->expr_str[R] = av_strdup("r(X,Y)");
|
2013-04-23 16:46:51 +03:00
|
|
|
|
|
|
|
if (geq->is_rgb ?
|
2013-05-20 00:32:02 +03:00
|
|
|
(!geq->expr_str[G] || !geq->expr_str[B] || !geq->expr_str[R])
|
2013-04-23 16:46:51 +03:00
|
|
|
:
|
2013-05-20 00:32:02 +03:00
|
|
|
(!geq->expr_str[U] || !geq->expr_str[V] || !geq->expr_str[A])) {
|
2012-05-14 20:03:19 +03:00
|
|
|
ret = AVERROR(ENOMEM);
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2013-02-25 12:14:24 +03:00
|
|
|
for (plane = 0; plane < 4; plane++) {
|
|
|
|
static double (*p[])(void *, double, double) = { lum, cb, cr, alpha };
|
2013-04-23 16:46:51 +03:00
|
|
|
static const char *const func2_yuv_names[] = { "lum", "cb", "cr", "alpha", "p", NULL };
|
|
|
|
static const char *const func2_rgb_names[] = { "g", "b", "r", "alpha", "p", NULL };
|
|
|
|
const char *const *func2_names = geq->is_rgb ? func2_rgb_names : func2_yuv_names;
|
2013-02-25 12:14:24 +03:00
|
|
|
double (*func2[])(void *, double, double) = { lum, cb, cr, alpha, p[plane], NULL };
|
2012-05-14 20:03:19 +03:00
|
|
|
|
2013-04-23 16:46:51 +03:00
|
|
|
ret = av_expr_parse(&geq->e[plane], geq->expr_str[plane < 3 && geq->is_rgb ? plane+4 : plane], var_names,
|
2012-05-14 20:03:19 +03:00
|
|
|
NULL, NULL, func2_names, func2, 0, ctx);
|
|
|
|
if (ret < 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
end:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int geq_query_formats(AVFilterContext *ctx)
|
|
|
|
{
|
2013-04-23 16:46:51 +03:00
|
|
|
GEQContext *geq = ctx->priv;
|
2015-03-18 02:18:40 +02:00
|
|
|
static const enum AVPixelFormat yuv_pix_fmts[] = {
|
2012-05-14 20:03:19 +03:00
|
|
|
AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P,
|
|
|
|
AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV440P,
|
2013-02-25 12:14:24 +03:00
|
|
|
AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA420P,
|
|
|
|
AV_PIX_FMT_GRAY8,
|
2017-06-30 12:16:04 +02:00
|
|
|
AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV420P9,
|
|
|
|
AV_PIX_FMT_YUVA444P9, AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA420P9,
|
|
|
|
AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV420P10,
|
|
|
|
AV_PIX_FMT_YUV440P10,
|
|
|
|
AV_PIX_FMT_YUVA444P10, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA420P10,
|
2018-09-09 19:05:56 +02:00
|
|
|
AV_PIX_FMT_GRAY9, AV_PIX_FMT_GRAY10,
|
2017-06-30 12:16:04 +02:00
|
|
|
AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV420P12,
|
2018-09-09 19:05:56 +02:00
|
|
|
AV_PIX_FMT_GRAY12, AV_PIX_FMT_GRAY14,
|
2017-06-30 12:16:04 +02:00
|
|
|
AV_PIX_FMT_YUV444P14, AV_PIX_FMT_YUV422P14, AV_PIX_FMT_YUV420P14,
|
|
|
|
AV_PIX_FMT_YUV444P16, AV_PIX_FMT_YUV422P16, AV_PIX_FMT_YUV420P16,
|
|
|
|
AV_PIX_FMT_YUVA444P16, AV_PIX_FMT_YUVA422P16, AV_PIX_FMT_YUVA420P16,
|
|
|
|
AV_PIX_FMT_GRAY16,
|
2012-05-14 20:03:19 +03:00
|
|
|
AV_PIX_FMT_NONE
|
|
|
|
};
|
2015-03-18 02:18:40 +02:00
|
|
|
static const enum AVPixelFormat rgb_pix_fmts[] = {
|
2013-05-06 18:36:20 +03:00
|
|
|
AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP,
|
2017-06-30 12:16:04 +02:00
|
|
|
AV_PIX_FMT_GBRP9,
|
|
|
|
AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRAP10,
|
|
|
|
AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRAP12,
|
|
|
|
AV_PIX_FMT_GBRP14,
|
|
|
|
AV_PIX_FMT_GBRP16, AV_PIX_FMT_GBRAP16,
|
2013-04-23 16:46:51 +03:00
|
|
|
AV_PIX_FMT_NONE
|
|
|
|
};
|
2015-04-03 19:55:18 +02:00
|
|
|
AVFilterFormats *fmts_list;
|
|
|
|
|
2013-04-23 16:46:51 +03:00
|
|
|
if (geq->is_rgb) {
|
2015-04-03 19:55:18 +02:00
|
|
|
fmts_list = ff_make_format_list(rgb_pix_fmts);
|
2013-04-23 16:46:51 +03:00
|
|
|
} else
|
2015-04-03 19:55:18 +02:00
|
|
|
fmts_list = ff_make_format_list(yuv_pix_fmts);
|
|
|
|
if (!fmts_list)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
return ff_set_common_formats(ctx, fmts_list);
|
2012-05-14 20:03:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int geq_config_props(AVFilterLink *inlink)
|
|
|
|
{
|
|
|
|
GEQContext *geq = inlink->dst->priv;
|
|
|
|
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
|
|
|
|
|
2015-06-13 20:49:32 +02:00
|
|
|
av_assert0(desc);
|
|
|
|
|
2012-05-14 20:03:19 +03:00
|
|
|
geq->hsub = desc->log2_chroma_w;
|
|
|
|
geq->vsub = desc->log2_chroma_h;
|
2018-01-04 09:49:55 +02:00
|
|
|
geq->bps = desc->comp[0].depth;
|
2013-02-25 12:14:24 +03:00
|
|
|
geq->planes = desc->nb_components;
|
2018-01-04 09:49:55 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct ThreadData {
|
|
|
|
int height;
|
|
|
|
int width;
|
|
|
|
int plane;
|
|
|
|
int linesize;
|
|
|
|
} ThreadData;
|
|
|
|
|
|
|
|
static int slice_geq_filter(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
|
|
|
|
{
|
|
|
|
GEQContext *geq = ctx->priv;
|
|
|
|
ThreadData *td = arg;
|
|
|
|
const int height = td->height;
|
|
|
|
const int width = td->width;
|
|
|
|
const int plane = td->plane;
|
|
|
|
const int linesize = td->linesize;
|
|
|
|
const int slice_start = (height * jobnr) / nb_jobs;
|
|
|
|
const int slice_end = (height * (jobnr+1)) / nb_jobs;
|
|
|
|
int x, y;
|
|
|
|
uint8_t *ptr;
|
|
|
|
uint16_t *ptr16;
|
|
|
|
|
|
|
|
double values[VAR_VARS_NB];
|
|
|
|
values[VAR_W] = geq->values[VAR_W];
|
|
|
|
values[VAR_H] = geq->values[VAR_H];
|
|
|
|
values[VAR_N] = geq->values[VAR_N];
|
|
|
|
values[VAR_SW] = geq->values[VAR_SW];
|
|
|
|
values[VAR_SH] = geq->values[VAR_SH];
|
|
|
|
values[VAR_T] = geq->values[VAR_T];
|
|
|
|
|
|
|
|
if (geq->bps == 8) {
|
|
|
|
for (y = slice_start; y < slice_end; y++) {
|
|
|
|
ptr = geq->dst + linesize * y;
|
|
|
|
values[VAR_Y] = y;
|
|
|
|
|
|
|
|
for (x = 0; x < width; x++) {
|
|
|
|
values[VAR_X] = x;
|
|
|
|
ptr[x] = av_expr_eval(geq->e[plane], values, geq);
|
|
|
|
}
|
|
|
|
ptr += linesize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (y = slice_start; y < slice_end; y++) {
|
|
|
|
ptr16 = geq->dst16 + (linesize/2) * y;
|
|
|
|
values[VAR_Y] = y;
|
|
|
|
for (x = 0; x < width; x++) {
|
|
|
|
values[VAR_X] = x;
|
|
|
|
ptr16[x] = av_expr_eval(geq->e[plane], values, geq);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-06-30 12:16:04 +02:00
|
|
|
|
2012-05-14 20:03:19 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-10 03:30:30 +03:00
|
|
|
static int geq_filter_frame(AVFilterLink *inlink, AVFrame *in)
|
2012-05-14 20:03:19 +03:00
|
|
|
{
|
2012-11-28 22:19:09 +03:00
|
|
|
int plane;
|
2018-01-04 09:49:55 +02:00
|
|
|
AVFilterContext *ctx = inlink->dst;
|
|
|
|
const int nb_threads = ff_filter_get_nb_threads(ctx);
|
|
|
|
GEQContext *geq = ctx->priv;
|
2012-05-14 20:03:19 +03:00
|
|
|
AVFilterLink *outlink = inlink->dst->outputs[0];
|
2013-03-10 03:30:30 +03:00
|
|
|
AVFrame *out;
|
2018-01-04 09:49:55 +02:00
|
|
|
|
|
|
|
geq->values[VAR_N] = inlink->frame_count_out,
|
|
|
|
geq->values[VAR_T] = in->pts == AV_NOPTS_VALUE ? NAN : in->pts * av_q2d(inlink->time_base),
|
2012-05-14 20:03:19 +03:00
|
|
|
|
2012-11-28 22:19:09 +03:00
|
|
|
geq->picref = in;
|
2013-03-10 03:30:30 +03:00
|
|
|
out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
|
2012-11-28 22:19:09 +03:00
|
|
|
if (!out) {
|
2013-03-10 03:30:30 +03:00
|
|
|
av_frame_free(&in);
|
2012-11-28 22:19:09 +03:00
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
}
|
2013-03-10 03:30:30 +03:00
|
|
|
av_frame_copy_props(out, in);
|
2012-05-14 20:03:19 +03:00
|
|
|
|
2013-02-25 12:14:24 +03:00
|
|
|
for (plane = 0; plane < geq->planes && out->data[plane]; plane++) {
|
2018-01-04 09:50:51 +02:00
|
|
|
const int width = (plane == 1 || plane == 2) ? AV_CEIL_RSHIFT(inlink->w, geq->hsub) : inlink->w;
|
|
|
|
const int height = (plane == 1 || plane == 2) ? AV_CEIL_RSHIFT(inlink->h, geq->vsub) : inlink->h;
|
2018-01-04 09:49:55 +02:00
|
|
|
const int linesize = out->linesize[plane];
|
|
|
|
ThreadData td;
|
2012-05-14 20:03:19 +03:00
|
|
|
|
2018-01-04 09:49:55 +02:00
|
|
|
geq->dst = out->data[plane];
|
|
|
|
geq->dst16 = (uint16_t*)out->data[plane];
|
2012-05-14 20:03:19 +03:00
|
|
|
|
2018-01-04 09:50:51 +02:00
|
|
|
geq->values[VAR_W] = width;
|
|
|
|
geq->values[VAR_H] = height;
|
|
|
|
geq->values[VAR_SW] = width / (double)inlink->w;
|
|
|
|
geq->values[VAR_SH] = height / (double)inlink->h;
|
2018-01-04 09:49:55 +02:00
|
|
|
|
2018-01-04 09:50:51 +02:00
|
|
|
td.width = width;
|
|
|
|
td.height = height;
|
2018-01-04 09:49:55 +02:00
|
|
|
td.plane = plane;
|
|
|
|
td.linesize = linesize;
|
|
|
|
|
2018-01-04 09:50:51 +02:00
|
|
|
ctx->internal->execute(ctx, slice_geq_filter, &td, NULL, FFMIN(height, nb_threads));
|
2012-05-14 20:03:19 +03:00
|
|
|
}
|
|
|
|
|
2013-03-10 03:30:30 +03:00
|
|
|
av_frame_free(&geq->picref);
|
2012-11-28 22:19:09 +03:00
|
|
|
return ff_filter_frame(outlink, out);
|
2012-05-14 20:03:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static av_cold void geq_uninit(AVFilterContext *ctx)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
GEQContext *geq = ctx->priv;
|
|
|
|
|
|
|
|
for (i = 0; i < FF_ARRAY_ELEMS(geq->e); i++)
|
|
|
|
av_expr_free(geq->e[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const AVFilterPad geq_inputs[] = {
|
|
|
|
{
|
|
|
|
.name = "default",
|
|
|
|
.type = AVMEDIA_TYPE_VIDEO,
|
|
|
|
.config_props = geq_config_props,
|
2012-11-28 22:19:09 +03:00
|
|
|
.filter_frame = geq_filter_frame,
|
2012-05-14 20:03:19 +03:00
|
|
|
},
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const AVFilterPad geq_outputs[] = {
|
|
|
|
{
|
|
|
|
.name = "default",
|
|
|
|
.type = AVMEDIA_TYPE_VIDEO,
|
|
|
|
},
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
2013-10-29 13:50:56 +03:00
|
|
|
AVFilter ff_vf_geq = {
|
2012-05-14 20:03:19 +03:00
|
|
|
.name = "geq",
|
|
|
|
.description = NULL_IF_CONFIG_SMALL("Apply generic equation to each pixel."),
|
|
|
|
.priv_size = sizeof(GEQContext),
|
|
|
|
.init = geq_init,
|
|
|
|
.uninit = geq_uninit,
|
|
|
|
.query_formats = geq_query_formats,
|
|
|
|
.inputs = geq_inputs,
|
|
|
|
.outputs = geq_outputs,
|
|
|
|
.priv_class = &geq_class,
|
2018-01-04 09:49:55 +02:00
|
|
|
.flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS,
|
2012-05-14 20:03:19 +03:00
|
|
|
};
|