[FFmpeg-devel] [PATCH v2 1/2] avfilter/delogo: changed type of parameter 'r' to float
Jörg Habenicht
j.habenicht at gmx.de
Sat Feb 8 00:47:32 EET 2025
Changed the type of the parameter 'r' from int to float. To be able to
flex the area as superellipse from rounded rectangle ('r' > 2.0) to a
concave shaped star ('r' < 1.0).
Check the input value to be 'r' >= 0.0, else error exit
Signed-off-by: Jörg Habenicht <j.habenicht at gmx.de>
---
libavfilter/vf_delogo.c | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/libavfilter/vf_delogo.c b/libavfilter/vf_delogo.c
index fcf14d3e4f..60f16b309c 100644
--- a/libavfilter/vf_delogo.c
+++ b/libavfilter/vf_delogo.c
@@ -243,10 +243,11 @@ static void apply_delogo(uint8_t *dst, int dst_linesize,
typedef struct DelogoContext {
const AVClass *class;
- int x, y, w, h, band, show, round;
- char *x_expr, *y_expr, *w_expr, *h_expr;
- AVExpr *x_pexpr, *y_pexpr, *w_pexpr, *h_pexpr;
+ int x, y, w, h, band, show;
+ char *x_expr, *y_expr, *w_expr, *h_expr, *r_expr;
+ AVExpr *x_pexpr, *y_pexpr, *w_pexpr, *h_pexpr, *r_pexpr;
double var_values[VAR_VARS_NB];
+ double round;
} DelogoContext;
#define OFFSET(x) offsetof(DelogoContext, x)
@@ -257,7 +258,7 @@ static const AVOption delogo_options[]= {
{ "y", "set logo y position", OFFSET(y_expr), AV_OPT_TYPE_STRING, { .str = "-1" }, 0, 0, FLAGS },
{ "w", "set logo width", OFFSET(w_expr), AV_OPT_TYPE_STRING, { .str = "-1" }, 0, 0, FLAGS },
{ "h", "set logo height", OFFSET(h_expr), AV_OPT_TYPE_STRING, { .str = "-1" }, 0, 0, FLAGS },
- { "r", "logo is round/ellipse", OFFSET(round), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
+ { "r", "set superellipse parameter",OFFSET(r_expr), AV_OPT_TYPE_STRING, { .str = "0" }, 0, 0, FLAGS },
{ "show", "show delogo area", OFFSET(show), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
{ NULL }
};
@@ -271,6 +272,7 @@ static av_cold void uninit(AVFilterContext *ctx)
av_expr_free(s->y_pexpr); s->y_pexpr = NULL;
av_expr_free(s->w_pexpr); s->w_pexpr = NULL;
av_expr_free(s->h_pexpr); s->h_pexpr = NULL;
+ av_expr_free(s->r_pexpr); s->r_pexpr = NULL;
}
static const enum AVPixelFormat pix_fmts[] = {
@@ -288,13 +290,15 @@ static av_cold int init(AVFilterContext *ctx)
if ((ret = set_expr(&s->x_pexpr, s->x_expr, "x", ctx)) < 0 ||
(ret = set_expr(&s->y_pexpr, s->y_expr, "y", ctx)) < 0 ||
(ret = set_expr(&s->w_pexpr, s->w_expr, "w", ctx)) < 0 ||
- (ret = set_expr(&s->h_pexpr, s->h_expr, "h", ctx)) < 0 )
+ (ret = set_expr(&s->h_pexpr, s->h_expr, "h", ctx)) < 0 ||
+ (ret = set_expr(&s->r_pexpr, s->r_expr, "r", ctx)) < 0 )
return ret;
s->x = av_expr_eval(s->x_pexpr, s->var_values, s);
s->y = av_expr_eval(s->y_pexpr, s->var_values, s);
s->w = av_expr_eval(s->w_pexpr, s->var_values, s);
s->h = av_expr_eval(s->h_pexpr, s->var_values, s);
+ s->round = av_expr_eval(s->r_pexpr, s->var_values, s);
#define CHECK_UNSET_OPT(opt) \
if (s->opt == -1) { \
@@ -306,9 +310,14 @@ static av_cold int init(AVFilterContext *ctx)
CHECK_UNSET_OPT(w);
CHECK_UNSET_OPT(h);
+ if (s->round < 0.0) {
+ av_log(s, AV_LOG_ERROR, "Option r was set negative (r=%.2f).\n", s->round);
+ return AVERROR(EINVAL);
+ }
+
s->band = 1;
- av_log(ctx, AV_LOG_VERBOSE, "x:%d y:%d, w:%d h:%d band:%d round:%d show:%d\n",
+ av_log(ctx, AV_LOG_VERBOSE, "x:%d y:%d, w:%d h:%d band:%d round:%f show:%d\n",
s->x, s->y, s->w, s->h, s->band, s->round, s->show);
s->w += s->band*2;
--
2.45.3
More information about the ffmpeg-devel
mailing list