Commit 714da1fd authored by Danil Iashchenko's avatar Danil Iashchenko Committed by Mark Thompson

lavfi: Add boxblur_opencl filter

Behaves like existing boxblur filter.
parent e8050aa7
......@@ -3311,6 +3311,7 @@ avgblur_opencl_filter_deps="opencl"
azmq_filter_deps="libzmq"
blackframe_filter_deps="gpl"
boxblur_filter_deps="gpl"
boxblur_opencl_filter_deps="opencl gpl"
bs2b_filter_deps="libbs2b"
colormatrix_filter_deps="gpl"
convolution_opencl_filter_deps="opencl"
......
......@@ -149,14 +149,16 @@ OBJS-$(CONFIG_ASS_FILTER) += vf_subtitles.o
OBJS-$(CONFIG_ATADENOISE_FILTER) += vf_atadenoise.o
OBJS-$(CONFIG_AVGBLUR_FILTER) += vf_avgblur.o
OBJS-$(CONFIG_AVGBLUR_OPENCL_FILTER) += vf_avgblur_opencl.o opencl.o \
opencl/avgblur.o
opencl/avgblur.o boxblur.o
OBJS-$(CONFIG_BBOX_FILTER) += bbox.o vf_bbox.o
OBJS-$(CONFIG_BENCH_FILTER) += f_bench.o
OBJS-$(CONFIG_BITPLANENOISE_FILTER) += vf_bitplanenoise.o
OBJS-$(CONFIG_BLACKDETECT_FILTER) += vf_blackdetect.o
OBJS-$(CONFIG_BLACKFRAME_FILTER) += vf_blackframe.o
OBJS-$(CONFIG_BLEND_FILTER) += vf_blend.o framesync.o
OBJS-$(CONFIG_BOXBLUR_FILTER) += vf_boxblur.o
OBJS-$(CONFIG_BOXBLUR_FILTER) += vf_boxblur.o boxblur.o
OBJS-$(CONFIG_BOXBLUR_OPENCL_FILTER) += vf_avgblur_opencl.o opencl.o \
opencl/avgblur.o boxblur.o
OBJS-$(CONFIG_BWDIF_FILTER) += vf_bwdif.o
OBJS-$(CONFIG_CHROMAKEY_FILTER) += vf_chromakey.o
OBJS-$(CONFIG_CIESCOPE_FILTER) += vf_ciescope.o
......
......@@ -148,6 +148,7 @@ extern AVFilter ff_vf_blackdetect;
extern AVFilter ff_vf_blackframe;
extern AVFilter ff_vf_blend;
extern AVFilter ff_vf_boxblur;
extern AVFilter ff_vf_boxblur_opencl;
extern AVFilter ff_vf_bwdif;
extern AVFilter ff_vf_chromakey;
extern AVFilter ff_vf_ciescope;
......
/*
* Copyright (c) 2002 Michael Niedermayer <michaelni@gmx.at>
* Copyright (c) 2011 Stefano Sabatini
* Copyright (c) 2018 Danil Iashchenko
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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
*/
#include "boxblur.h"
static const char *const var_names[] = {
"w",
"h",
"cw",
"ch",
"hsub",
"vsub",
NULL
};
enum var_name {
VAR_W,
VAR_H,
VAR_CW,
VAR_CH,
VAR_HSUB,
VAR_VSUB,
VARS_NB
};
int ff_boxblur_eval_filter_params(AVFilterLink *inlink,
FilterParam *luma_param,
FilterParam *chroma_param,
FilterParam *alpha_param)
{
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
AVFilterContext *ctx = inlink->dst;
int w = inlink->w, h = inlink->h;
int cw, ch;
double var_values[VARS_NB], res;
char *expr;
int ret;
if (!luma_param->radius_expr) {
av_log(ctx, AV_LOG_ERROR, "Luma radius expression is not set.\n");
return AVERROR(EINVAL);
}
/* fill missing params */
if (!chroma_param->radius_expr) {
chroma_param->radius_expr = av_strdup(luma_param->radius_expr);
if (!chroma_param->radius_expr)
return AVERROR(ENOMEM);
}
if (chroma_param->power < 0)
chroma_param->power = luma_param->power;
if (!alpha_param->radius_expr) {
alpha_param->radius_expr = av_strdup(luma_param->radius_expr);
if (!alpha_param->radius_expr)
return AVERROR(ENOMEM);
}
if (alpha_param->power < 0)
alpha_param->power = luma_param->power;
var_values[VAR_W] = inlink->w;
var_values[VAR_H] = inlink->h;
var_values[VAR_CW] = cw = w>>(desc->log2_chroma_w);
var_values[VAR_CH] = ch = h>>(desc->log2_chroma_h);
var_values[VAR_HSUB] = 1<<(desc->log2_chroma_w);
var_values[VAR_VSUB] = 1<<(desc->log2_chroma_h);
#define EVAL_RADIUS_EXPR(comp) \
expr = comp->radius_expr; \
ret = av_expr_parse_and_eval(&res, expr, var_names, var_values, \
NULL, NULL, NULL, NULL, NULL, 0, ctx); \
comp->radius = res; \
if (ret < 0) { \
av_log(NULL, AV_LOG_ERROR, \
"Error when evaluating " #comp " radius expression '%s'\n", expr); \
return ret; \
}
EVAL_RADIUS_EXPR(luma_param);
EVAL_RADIUS_EXPR(chroma_param);
EVAL_RADIUS_EXPR(alpha_param);
av_log(ctx, AV_LOG_VERBOSE,
"luma_radius:%d luma_power:%d "
"chroma_radius:%d chroma_power:%d "
"alpha_radius:%d alpha_power:%d "
"w:%d chroma_w:%d h:%d chroma_h:%d\n",
luma_param ->radius, luma_param ->power,
chroma_param->radius, chroma_param->power,
alpha_param ->radius, alpha_param ->power,
w, cw, h, ch);
#define CHECK_RADIUS_VAL(w_, h_, comp) \
if (comp->radius < 0 || \
2*comp->radius > FFMIN(w_, h_)) { \
av_log(ctx, AV_LOG_ERROR, \
"Invalid " #comp " radius value %d, must be >= 0 and <= %d\n", \
comp->radius, FFMIN(w_, h_)/2); \
return AVERROR(EINVAL); \
}
CHECK_RADIUS_VAL(w, h, luma_param);
CHECK_RADIUS_VAL(cw, ch, chroma_param);
CHECK_RADIUS_VAL(w, h, alpha_param);
return 0;
}
/*
* Copyright (c) 2002 Michael Niedermayer <michaelni@gmx.at>
* Copyright (c) 2011 Stefano Sabatini
* Copyright (c) 2018 Danil Iashchenko
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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
*/
#ifndef AVFILTER_BOXBLUR_H
#define AVFILTER_BOXBLUR_H
#include "libavutil/eval.h"
#include "libavutil/pixdesc.h"
#include "libavutil/mem.h"
#include "avfilter.h"
typedef struct FilterParam {
int radius;
int power;
char *radius_expr;
} FilterParam;
#define Y 0
#define U 1
#define V 2
#define A 3
int ff_boxblur_eval_filter_params(AVFilterLink *inlink,
FilterParam *luma_param,
FilterParam *chroma_param,
FilterParam *alpha_param);
#endif // AVFILTER_BOXBLUR_H
This diff is collapsed.
......@@ -27,39 +27,13 @@
#include "libavutil/avstring.h"
#include "libavutil/common.h"
#include "libavutil/eval.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "avfilter.h"
#include "formats.h"
#include "internal.h"
#include "video.h"
#include "boxblur.h"
static const char *const var_names[] = {
"w",
"h",
"cw",
"ch",
"hsub",
"vsub",
NULL
};
enum var_name {
VAR_W,
VAR_H,
VAR_CW,
VAR_CH,
VAR_HSUB,
VAR_VSUB,
VARS_NB
};
typedef struct FilterParam {
int radius;
int power;
char *radius_expr;
} FilterParam;
typedef struct BoxBlurContext {
const AVClass *class;
......@@ -73,40 +47,6 @@ typedef struct BoxBlurContext {
uint8_t *temp[2]; ///< temporary buffer used in blur_power()
} BoxBlurContext;
#define Y 0
#define U 1
#define V 2
#define A 3
static av_cold int init(AVFilterContext *ctx)
{
BoxBlurContext *s = ctx->priv;
if (!s->luma_param.radius_expr) {
av_log(ctx, AV_LOG_ERROR, "Luma radius expression is not set.\n");
return AVERROR(EINVAL);
}
/* fill missing params */
if (!s->chroma_param.radius_expr) {
s->chroma_param.radius_expr = av_strdup(s->luma_param.radius_expr);
if (!s->chroma_param.radius_expr)
return AVERROR(ENOMEM);
}
if (s->chroma_param.power < 0)
s->chroma_param.power = s->luma_param.power;
if (!s->alpha_param.radius_expr) {
s->alpha_param.radius_expr = av_strdup(s->luma_param.radius_expr);
if (!s->alpha_param.radius_expr)
return AVERROR(ENOMEM);
}
if (s->alpha_param.power < 0)
s->alpha_param.power = s->luma_param.power;
return 0;
}
static av_cold void uninit(AVFilterContext *ctx)
{
BoxBlurContext *s = ctx->priv;
......@@ -138,9 +78,6 @@ static int config_input(AVFilterLink *inlink)
AVFilterContext *ctx = inlink->dst;
BoxBlurContext *s = ctx->priv;
int w = inlink->w, h = inlink->h;
int cw, ch;
double var_values[VARS_NB], res;
char *expr;
int ret;
if (!(s->temp[0] = av_malloc(2*FFMAX(w, h))) ||
......@@ -150,48 +87,16 @@ static int config_input(AVFilterLink *inlink)
s->hsub = desc->log2_chroma_w;
s->vsub = desc->log2_chroma_h;
var_values[VAR_W] = inlink->w;
var_values[VAR_H] = inlink->h;
var_values[VAR_CW] = cw = w>>s->hsub;
var_values[VAR_CH] = ch = h>>s->vsub;
var_values[VAR_HSUB] = 1<<s->hsub;
var_values[VAR_VSUB] = 1<<s->vsub;
#define EVAL_RADIUS_EXPR(comp) \
expr = s->comp##_param.radius_expr; \
ret = av_expr_parse_and_eval(&res, expr, var_names, var_values, \
NULL, NULL, NULL, NULL, NULL, 0, ctx); \
s->comp##_param.radius = res; \
if (ret < 0) { \
av_log(NULL, AV_LOG_ERROR, \
"Error when evaluating " #comp " radius expression '%s'\n", expr); \
return ret; \
}
EVAL_RADIUS_EXPR(luma);
EVAL_RADIUS_EXPR(chroma);
EVAL_RADIUS_EXPR(alpha);
av_log(ctx, AV_LOG_VERBOSE,
"luma_radius:%d luma_power:%d "
"chroma_radius:%d chroma_power:%d "
"alpha_radius:%d alpha_power:%d "
"w:%d chroma_w:%d h:%d chroma_h:%d\n",
s->luma_param .radius, s->luma_param .power,
s->chroma_param.radius, s->chroma_param.power,
s->alpha_param .radius, s->alpha_param .power,
w, cw, h, ch);
#define CHECK_RADIUS_VAL(w_, h_, comp) \
if (s->comp##_param.radius < 0 || \
2*s->comp##_param.radius > FFMIN(w_, h_)) { \
av_log(ctx, AV_LOG_ERROR, \
"Invalid " #comp " radius value %d, must be >= 0 and <= %d\n", \
s->comp##_param.radius, FFMIN(w_, h_)/2); \
return AVERROR(EINVAL); \
ret = ff_boxblur_eval_filter_params(inlink,
&s->luma_param,
&s->chroma_param,
&s->alpha_param);
if (ret != 0) {
av_log(ctx, AV_LOG_ERROR, "Failed to evaluate "
"filter params: %d.\n", ret);
return ret;
}
CHECK_RADIUS_VAL(w, h, luma);
CHECK_RADIUS_VAL(cw, ch, chroma);
CHECK_RADIUS_VAL(w, h, alpha);
s->radius[Y] = s->luma_param.radius;
s->radius[U] = s->radius[V] = s->chroma_param.radius;
......@@ -404,7 +309,6 @@ AVFilter ff_vf_boxblur = {
.description = NULL_IF_CONFIG_SMALL("Blur the input."),
.priv_size = sizeof(BoxBlurContext),
.priv_class = &boxblur_class,
.init = init,
.uninit = uninit,
.query_formats = query_formats,
.inputs = avfilter_vf_boxblur_inputs,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment