[FFmpeg-devel] [PATCH 1/3] avfilter/delogo: add parameter to switch on circular delogo
Add a parameter (boolean) r to switch the area from rectangular (r=0) to circular(r=1) delogo. Signed-off-by: Jörg Habenicht --- libavfilter/vf_delogo.c | 7 --- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libavfilter/vf_delogo.c b/libavfilter/vf_delogo.c index bfbf8e6f4c..7641c3b483 100644 --- a/libavfilter/vf_delogo.c +++ b/libavfilter/vf_delogo.c @@ -195,7 +195,7 @@ static void apply_delogo(uint8_t *dst, int dst_linesize, typedef struct DelogoContext { const AVClass *class; -int x, y, w, h, band, show; +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; double var_values[VAR_VARS_NB]; @@ -209,6 +209,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 }, { "show", "show delogo area", OFFSET(show), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS }, { NULL } }; @@ -259,8 +260,8 @@ static av_cold int init(AVFilterContext *ctx) s->band = 1; -av_log(ctx, AV_LOG_VERBOSE, "x:%d y:%d, w:%d h:%d band:%d show:%d\n", - s->x, s->y, s->w, s->h, s->band, s->show); +av_log(ctx, AV_LOG_VERBOSE, "x:%d y:%d, w:%d h:%d band:%d round:%d show:%d\n", + s->x, s->y, s->w, s->h, s->band, s->round, s->show); s->w += s->band*2; s->h += s->band*2; -- 2.45.3 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 0/3] *** SUBJECT HERE ***
Dear list, I made a patch for the delogo filter. With this I can create a circular or elliptic zone to apply the delogo algorithm. The borders are defined with x,y,w,h parameter just like the rectangular area definition. To become circular I added an additional parameter 'r'=0/1 defaulting to '0' i.e. rectangular area definition. I added a large comment to the function body describing the calculation of the ellipse. Hope you don't mind. The patch has been tested with 'make fate-rsync fate' and applies clean to commit 957eb2323a924aa0b148927889eae581185c367b . Please have a look and reply with critics, comments or suggestions. I would be happy to have this one applied to the main branch. best regards Jörg Jörg Habenicht (3): avfilter/delogo: add parameter to switch on circular delogo avfilter/delogo: added circular delogo algorithm description avfilter/delogo: added the circular delogo algorithm libavfilter/vf_delogo.c | 59 + 1 file changed, 54 insertions(+), 5 deletions(-) -- 2.45.3 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 2/3] avfilter/delogo: added circular delogo algorithm description
Added a description of the elliptic formed delogo algorithm. Placed it outside the doxygen function comment. Signed-off-by: Jörg Habenicht --- libavfilter/vf_delogo.c | 24 1 file changed, 24 insertions(+) diff --git a/libavfilter/vf_delogo.c b/libavfilter/vf_delogo.c index 7641c3b483..ea741e2700 100644 --- a/libavfilter/vf_delogo.c +++ b/libavfilter/vf_delogo.c @@ -100,6 +100,30 @@ static void apply_delogo(uint8_t *dst, int dst_linesize, int logo_x, int logo_y, int logo_w, int logo_h, unsigned int band, int show, int direct) { +/* Round area algorithm description: + * + * logo_x, logo_y, logo_w and logo_h define the boundaries of the + * ellipse. In the ellipse formula x^2 / a^2 + y^2 / b^2 = 1 let + * a = logo_w/2, b = logo_h/2 and the center of the ellipse + * (0,0) = (logo_x + a, logo_y + b). + * Let the picture dimensions (px,py,pw,ph) := function API(x,y,w,h). + * A point of the picture is transformed into the ellipse coordinates + * by using x = px - (logo_x + a), y = py - (logo_y +b). + * + * A point is inside the ellipse if x^2 / a^2 + y^2 / b^2 <= 1 + * <=> (x + logo_x)^2 / (logo_w / 2)^2 + * + (y + logo_y)^2 / (logo_h / 2)^2 <= 1 + * <=> (px - logo_x - a + logo_x)^2 / (logo_w / 2)^2 + * + (py - logo_y - b + logo_y)^2 / (logo_h / 2)^2 <= 1 + * <=> (px - a)^2 / (logo_w / 2)^2 + * + (py - b)^2 / (logo_h / 2)^2 <= 1 + * <=> ((px - a) / (logo_w / 2))^2 + * + ((py - b) / (logo_h / 2))^2 <= 1 + * + * px is later defined x, py defined y. + * logo_w is later defined logo_w2, logo_h defined logo_h2. + */ + int x, y; uint64_t interp, weightl, weightr, weightt, weightb, weight; uint8_t *xdst, *xsrc; -- 2.45.3 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 3/3] avfilter/delogo: added the circular delogo algorithm
Use the corrected x,y,w,h values with boundaries and clipping to calculate the points inside the ellipse. Signed-off-by: Jörg Habenicht --- libavfilter/vf_delogo.c | 28 ++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/libavfilter/vf_delogo.c b/libavfilter/vf_delogo.c index ea741e2700..fcf14d3e4f 100644 --- a/libavfilter/vf_delogo.c +++ b/libavfilter/vf_delogo.c @@ -90,6 +90,7 @@ static int set_expr(AVExpr **pexpr, const char *expr, const char *option, void * * @param logo_w width of the logo * @param logo_h height of the logo * @param band the size of the band around the processed area + * @param round whether delogo is applied to a rectangular or round area * @param show show a rectangle around the processed area, useful for * parameters tweaking * @param direct if non-zero perform in-place processing @@ -98,7 +99,7 @@ static void apply_delogo(uint8_t *dst, int dst_linesize, uint8_t *src, int src_linesize, int w, int h, AVRational sar, int logo_x, int logo_y, int logo_w, int logo_h, - unsigned int band, int show, int direct) + unsigned int band, int round, int show, int direct) { /* Round area algorithm description: * @@ -132,6 +133,7 @@ static void apply_delogo(uint8_t *dst, int dst_linesize, unsigned int left_sample, right_sample; int xclipl, xclipr, yclipt, yclipb; int logo_x1, logo_x2, logo_y1, logo_y2; +double a, b, logo_w2, logo_h2; xclipl = FFMAX(-logo_x, 0); xclipr = FFMAX(logo_x+logo_w-w, 0); @@ -147,6 +149,13 @@ static void apply_delogo(uint8_t *dst, int dst_linesize, topright = src+logo_y1 * src_linesize+logo_x2; botleft = src+logo_y2 * src_linesize+logo_x1; +if (round) { +logo_w2 = (logo_x2 - logo_x1) / 2.0; +logo_h2 = (logo_y2 - logo_y1) / 2.0; +a = logo_x1 + logo_w2; +b = logo_y1 + logo_h2; +} + if (!direct) av_image_copy_plane(dst, dst_linesize, src, src_linesize, w, h); @@ -171,6 +180,21 @@ static void apply_delogo(uint8_t *dst, int dst_linesize, continue; } +if (round) { +double xf, yf; +/* Evaluate if x,y is inside the ellipse, else continue + * This is the calculation + * (px - a)^2 / (logo_w / 2)^2 + + * (py - b)^2 / (logo_h / 2)^2 <= 1 + */ +xf = ((double)x - a) / logo_w2; +xf *= xf; +yf = ((double)y - b) / logo_h2; +yf *= yf; +if (xf + yf > 1.0) +continue; +} + /* Weighted interpolation based on relative distances, taking SAR into account */ weightl = (uint64_t) (logo_x2-x) * (y-logo_y1) * (logo_y2-y) * sar.den; weightr = (uint64_t)(x-logo_x1) * (y-logo_y1) * (logo_y2-y) * sar.den; @@ -388,7 +412,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) AV_CEIL_RSHIFT(s->w + (s->x & ((1y & ((1 >FFMIN(hsub, vsub), - s->show, direct); + s->round, s->show, direct); } if (!direct) -- 2.45.3 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 0/3] Patch to create a circular delogo area
Dear list, sorry for the previous posting. I noticed the lines got mangled. So here is a new try to get the patches right. Old text: I made a patch for the delogo filter. With this I can create a circular or elliptic zone to apply the delogo algorithm. The borders are defined with x,y,w,h parameter just like the rectangular area definition. To become circular I added an additional parameter 'r'=0/1 defaulting to '0' i.e. rectangular area definition. I added a large comment to the function body describing the calculation of the ellipse. Hope you don't mind. The patch has been tested with 'make fate-rsync fate' and applies clean to the master branch, commit 957eb2323a924aa0b148927889eae581185c367b . Please have a look. best regards Jörg Jörg Habenicht (3): avfilter/delogo: add parameter to switch on circular delogo avfilter/delogo: added circular delogo algorithm description avfilter/delogo: added the circular delogo algorithm libavfilter/vf_delogo.c | 59 + 1 file changed, 54 insertions(+), 5 deletions(-) -- 2.45.3 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 3/3] avfilter/delogo: added the circular delogo algorithm
Use the corrected x,y,w,h values with boundaries and clipping to calculate the points inside the ellipse. Signed-off-by: Jörg Habenicht --- libavfilter/vf_delogo.c | 28 ++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/libavfilter/vf_delogo.c b/libavfilter/vf_delogo.c index ea741e2700..fcf14d3e4f 100644 --- a/libavfilter/vf_delogo.c +++ b/libavfilter/vf_delogo.c @@ -90,6 +90,7 @@ static int set_expr(AVExpr **pexpr, const char *expr, const char *option, void * * @param logo_w width of the logo * @param logo_h height of the logo * @param band the size of the band around the processed area + * @param round whether delogo is applied to a rectangular or round area * @param show show a rectangle around the processed area, useful for * parameters tweaking * @param direct if non-zero perform in-place processing @@ -98,7 +99,7 @@ static void apply_delogo(uint8_t *dst, int dst_linesize, uint8_t *src, int src_linesize, int w, int h, AVRational sar, int logo_x, int logo_y, int logo_w, int logo_h, - unsigned int band, int show, int direct) + unsigned int band, int round, int show, int direct) { /* Round area algorithm description: * @@ -132,6 +133,7 @@ static void apply_delogo(uint8_t *dst, int dst_linesize, unsigned int left_sample, right_sample; int xclipl, xclipr, yclipt, yclipb; int logo_x1, logo_x2, logo_y1, logo_y2; +double a, b, logo_w2, logo_h2; xclipl = FFMAX(-logo_x, 0); xclipr = FFMAX(logo_x+logo_w-w, 0); @@ -147,6 +149,13 @@ static void apply_delogo(uint8_t *dst, int dst_linesize, topright = src+logo_y1 * src_linesize+logo_x2; botleft = src+logo_y2 * src_linesize+logo_x1; +if (round) { +logo_w2 = (logo_x2 - logo_x1) / 2.0; +logo_h2 = (logo_y2 - logo_y1) / 2.0; +a = logo_x1 + logo_w2; +b = logo_y1 + logo_h2; +} + if (!direct) av_image_copy_plane(dst, dst_linesize, src, src_linesize, w, h); @@ -171,6 +180,21 @@ static void apply_delogo(uint8_t *dst, int dst_linesize, continue; } +if (round) { +double xf, yf; +/* Evaluate if x,y is inside the ellipse, else continue + * This is the calculation + * (px - a)^2 / (logo_w / 2)^2 + + * (py - b)^2 / (logo_h / 2)^2 <= 1 + */ +xf = ((double)x - a) / logo_w2; +xf *= xf; +yf = ((double)y - b) / logo_h2; +yf *= yf; +if (xf + yf > 1.0) +continue; +} + /* Weighted interpolation based on relative distances, taking SAR into account */ weightl = (uint64_t) (logo_x2-x) * (y-logo_y1) * (logo_y2-y) * sar.den; weightr = (uint64_t)(x-logo_x1) * (y-logo_y1) * (logo_y2-y) * sar.den; @@ -388,7 +412,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) AV_CEIL_RSHIFT(s->w + (s->x & ((1y & ((1 >FFMIN(hsub, vsub), - s->show, direct); + s->round, s->show, direct); } if (!direct) -- 2.45.3 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 2/3] avfilter/delogo: added circular delogo algorithm description
Added a description of the elliptic formed delogo algorithm. Placed it outside the doxygen function comment. Signed-off-by: Jörg Habenicht --- libavfilter/vf_delogo.c | 24 1 file changed, 24 insertions(+) diff --git a/libavfilter/vf_delogo.c b/libavfilter/vf_delogo.c index 7641c3b483..ea741e2700 100644 --- a/libavfilter/vf_delogo.c +++ b/libavfilter/vf_delogo.c @@ -100,6 +100,30 @@ static void apply_delogo(uint8_t *dst, int dst_linesize, int logo_x, int logo_y, int logo_w, int logo_h, unsigned int band, int show, int direct) { +/* Round area algorithm description: + * + * logo_x, logo_y, logo_w and logo_h define the boundaries of the + * ellipse. In the ellipse formula x^2 / a^2 + y^2 / b^2 = 1 let + * a = logo_w/2, b = logo_h/2 and the center of the ellipse + * (0,0) = (logo_x + a, logo_y + b). + * Let the picture dimensions (px,py,pw,ph) := function API(x,y,w,h). + * A point of the picture is transformed into the ellipse coordinates + * by using x = px - (logo_x + a), y = py - (logo_y +b). + * + * A point is inside the ellipse if x^2 / a^2 + y^2 / b^2 <= 1 + * <=> (x + logo_x)^2 / (logo_w / 2)^2 + * + (y + logo_y)^2 / (logo_h / 2)^2 <= 1 + * <=> (px - logo_x - a + logo_x)^2 / (logo_w / 2)^2 + * + (py - logo_y - b + logo_y)^2 / (logo_h / 2)^2 <= 1 + * <=> (px - a)^2 / (logo_w / 2)^2 + * + (py - b)^2 / (logo_h / 2)^2 <= 1 + * <=> ((px - a) / (logo_w / 2))^2 + * + ((py - b) / (logo_h / 2))^2 <= 1 + * + * px is later defined x, py defined y. + * logo_w is later defined logo_w2, logo_h defined logo_h2. + */ + int x, y; uint64_t interp, weightl, weightr, weightt, weightb, weight; uint8_t *xdst, *xsrc; -- 2.45.3 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 1/3] avfilter/delogo: add parameter to switch on circular delogo
Add a parameter (boolean) r to switch the area from rectangular (r=0) to circular(r=1) delogo. Signed-off-by: Jörg Habenicht --- libavfilter/vf_delogo.c | 7 --- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libavfilter/vf_delogo.c b/libavfilter/vf_delogo.c index bfbf8e6f4c..7641c3b483 100644 --- a/libavfilter/vf_delogo.c +++ b/libavfilter/vf_delogo.c @@ -195,7 +195,7 @@ static void apply_delogo(uint8_t *dst, int dst_linesize, typedef struct DelogoContext { const AVClass *class; -int x, y, w, h, band, show; +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; double var_values[VAR_VARS_NB]; @@ -209,6 +209,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 }, { "show", "show delogo area", OFFSET(show), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS }, { NULL } }; @@ -259,8 +260,8 @@ static av_cold int init(AVFilterContext *ctx) s->band = 1; -av_log(ctx, AV_LOG_VERBOSE, "x:%d y:%d, w:%d h:%d band:%d show:%d\n", - s->x, s->y, s->w, s->h, s->band, s->show); +av_log(ctx, AV_LOG_VERBOSE, "x:%d y:%d, w:%d h:%d band:%d round:%d show:%d\n", + s->x, s->y, s->w, s->h, s->band, s->round, s->show); s->w += s->band*2; s->h += s->band*2; -- 2.45.3 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 2/2] avfilter/delogo: change delogo round area to superellipse area
Changed the delogo area to a definition of a superellipse. See here https://en.wikipedia.org/wiki/Superellipse Changed the meaning of the parameter 'r'. 'r' = 0.0 resolves to a rectangular area. 0 <'r' < 1 resolves to a star with concave sides. 'r' = 1.0 resolves to a rhombus. 1 < 'r' < 2 resolves to a rhombus with convex sides. 'r' = 2.0 resolves to an ellipse or a circel. 2 < 'r' resolves to something like a rectangle with round corners. Unset is the default of 'r' = 0.0 . Signed-off-by: Jörg Habenicht --- libavfilter/vf_delogo.c | 51 ++--- 1 file changed, 43 insertions(+), 8 deletions(-) diff --git a/libavfilter/vf_delogo.c b/libavfilter/vf_delogo.c index 60f16b309c..ed81d112e2 100644 --- a/libavfilter/vf_delogo.c +++ b/libavfilter/vf_delogo.c @@ -90,7 +90,7 @@ static int set_expr(AVExpr **pexpr, const char *expr, const char *option, void * * @param logo_w width of the logo * @param logo_h height of the logo * @param band the size of the band around the processed area - * @param round whether delogo is applied to a rectangular or round area + * @param round parameter of superellipse, 0==rectanglar, 1.0==rhombus, 2.0==circular/ellipse * @param show show a rectangle around the processed area, useful for * parameters tweaking * @param direct if non-zero perform in-place processing @@ -99,7 +99,7 @@ static void apply_delogo(uint8_t *dst, int dst_linesize, uint8_t *src, int src_linesize, int w, int h, AVRational sar, int logo_x, int logo_y, int logo_w, int logo_h, - unsigned int band, int round, int show, int direct) + unsigned int band, double round, int show, int direct) { /* Round area algorithm description: * @@ -123,6 +123,18 @@ static void apply_delogo(uint8_t *dst, int dst_linesize, * * px is later defined x, py defined y. * logo_w is later defined logo_w2, logo_h defined logo_h2. + * + * A point inside a superellipse is defined as x^n / a^n + y^n / b^n = 1 + * <=> (x + logo_x)^n / (logo_w / 2)^n + * + (y + logo_y)^n / (logo_h / 2)^n <= 1 + * <=> (px - logo_x - a + logo_x)^n / (logo_w / 2)^n + * + (py - logo_y - b + logo_y)^n / (logo_h / 2)^n <= 1 + * <=> (px - a)^n / (logo_w / 2)^n + * + (py - b)^n / (logo_h / 2)^n <= 1 + * <=> ((px - a) / (logo_w / 2))^n + * + ((py - b) / (logo_h / 2))^n <= 1 + * + * n is defined by the parameter 'round' */ int x, y; @@ -149,7 +161,7 @@ static void apply_delogo(uint8_t *dst, int dst_linesize, topright = src+logo_y1 * src_linesize+logo_x2; botleft = src+logo_y2 * src_linesize+logo_x1; -if (round) { +if (round > 0.0) { logo_w2 = (logo_x2 - logo_x1) / 2.0; logo_h2 = (logo_y2 - logo_y1) / 2.0; a = logo_x1 + logo_w2; @@ -180,17 +192,40 @@ static void apply_delogo(uint8_t *dst, int dst_linesize, continue; } -if (round) { +if (round > 0.0) { double xf, yf; /* Evaluate if x,y is inside the ellipse, else continue * This is the calculation - * (px - a)^2 / (logo_w / 2)^2 + - * (py - b)^2 / (logo_h / 2)^2 <= 1 + * (px - a)^n / (logo_w / 2)^n + + * (py - b)^n / (logo_h / 2)^n <= 1 */ +errno = 0; xf = ((double)x - a) / logo_w2; -xf *= xf; +xf = fabs(xf); // use positive values only, analog to xf^2 +xf = pow(xf, round); +if (isnan(xf)) { +av_log(NULL, AV_LOG_ERROR, + "Error in delogo calculating ellipse value. NAN value returned\n"); +return; +} +if (errno) { +av_log(NULL, AV_LOG_ERROR, + "Error in delogo calculating ellipse value. Math error returned\n"); +return; +} yf = ((double)y - b) / logo_h2; -yf *= yf; +yf = fabs(yf); // use positive values only, analog to yf^2 +yf = pow(yf, round); +if (isnan(xf)) { +av_log(NULL, AV_LOG_ERROR, + "Error in delogo calculating ellipse value. NAN value returned\n"); +return; +} +if (errno) { +av_log(NULL, AV_LOG_ERROR, + "Error in delogo calculating ellipse value. Math error returned\n"); +return; +} if (xf + yf > 1.0) continue; } -- 2.45.3 ___ ffmpeg-devel mailin
[FFmpeg-devel] [PATCH 0/2] Extend delogo area to a superellipse
Dear list, with help from Michael I extended the ellipse area to a superellipse. The user parameter 'r' has changed to become a float value. Values 0 < r < 1 the area looks like a four edge star. Value r = 1 the area get a rhombus. Values 1 < r < 2 the area is a rhombus with concave sides. Value r = 2 the area is an ellipse or a circle. Values 2 < r the area looks like a rectangular with round edges. Value = 0 (default, unset) the area is rectangular. Because of the usage of math functions I added more code testing the return values. The parameter r=2 to get an ellipse delogo area seems non intuitive to me. We should add a better description for the users of the delogo filter. The patch has been tested with 'make fate-rsync fate' rebased on the master branch commit 268d0b6527cba1ebac1f44347578617341f85c35 and applies clean to my previous patchset "Patch to create a circular delogo area" Please have a look. best regards Jörg Jörg Habenicht (2): avfilter/delogo: changed type of parameter 'r' to float avfilter/delogo: change delogo round area to superellipse area libavfilter/vf_delogo.c | 72 + 1 file changed, 58 insertions(+), 14 deletions(-) -- 2.45.3 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 1/2] avfilter/delogo: changed type of parameter 'r' to float
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 --- 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 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2 2/2] avfilter/delogo: change delogo round area to superellipse area
Changed the delogo area to a definition of a superellipse. See here https://en.wikipedia.org/wiki/Superellipse Changed the meaning of the parameter 'r'. 'r' = 0.0 resolves to a rectangular area. 0 <'r' < 1 resolves to a star with concave sides. 'r' = 1.0 resolves to a rhombus. 1 < 'r' < 2 resolves to a rhombus with convex sides. 'r' = 2.0 resolves to an ellipse or a circel. 2 < 'r' resolves to something like a rectangle with round corners. Unset is the default of 'r' = 0.0 . Signed-off-by: Jörg Habenicht --- libavfilter/vf_delogo.c | 51 ++--- 1 file changed, 43 insertions(+), 8 deletions(-) diff --git a/libavfilter/vf_delogo.c b/libavfilter/vf_delogo.c index 60f16b309c..900c062cb4 100644 --- a/libavfilter/vf_delogo.c +++ b/libavfilter/vf_delogo.c @@ -90,7 +90,7 @@ static int set_expr(AVExpr **pexpr, const char *expr, const char *option, void * * @param logo_w width of the logo * @param logo_h height of the logo * @param band the size of the band around the processed area - * @param round whether delogo is applied to a rectangular or round area + * @param round parameter of superellipse, 0==rectanglar, 1.0==rhombus, 2.0==circular/ellipse * @param show show a rectangle around the processed area, useful for * parameters tweaking * @param direct if non-zero perform in-place processing @@ -99,7 +99,7 @@ static void apply_delogo(uint8_t *dst, int dst_linesize, uint8_t *src, int src_linesize, int w, int h, AVRational sar, int logo_x, int logo_y, int logo_w, int logo_h, - unsigned int band, int round, int show, int direct) + unsigned int band, double round, int show, int direct) { /* Round area algorithm description: * @@ -123,6 +123,18 @@ static void apply_delogo(uint8_t *dst, int dst_linesize, * * px is later defined x, py defined y. * logo_w is later defined logo_w2, logo_h defined logo_h2. + * + * A point inside a superellipse is defined as x^n / a^n + y^n / b^n = 1 + * <=> (x + logo_x)^n / (logo_w / 2)^n + * + (y + logo_y)^n / (logo_h / 2)^n <= 1 + * <=> (px - logo_x - a + logo_x)^n / (logo_w / 2)^n + * + (py - logo_y - b + logo_y)^n / (logo_h / 2)^n <= 1 + * <=> (px - a)^n / (logo_w / 2)^n + * + (py - b)^n / (logo_h / 2)^n <= 1 + * <=> ((px - a) / (logo_w / 2))^n + * + ((py - b) / (logo_h / 2))^n <= 1 + * + * n is defined by the parameter 'round' */ int x, y; @@ -149,7 +161,7 @@ static void apply_delogo(uint8_t *dst, int dst_linesize, topright = src+logo_y1 * src_linesize+logo_x2; botleft = src+logo_y2 * src_linesize+logo_x1; -if (round) { +if (round > 0.0) { logo_w2 = (logo_x2 - logo_x1) / 2.0; logo_h2 = (logo_y2 - logo_y1) / 2.0; a = logo_x1 + logo_w2; @@ -180,17 +192,40 @@ static void apply_delogo(uint8_t *dst, int dst_linesize, continue; } -if (round) { +if (round > 0.0) { double xf, yf; /* Evaluate if x,y is inside the ellipse, else continue * This is the calculation - * (px - a)^2 / (logo_w / 2)^2 + - * (py - b)^2 / (logo_h / 2)^2 <= 1 + * (px - a)^n / (logo_w / 2)^n + + * (py - b)^n / (logo_h / 2)^n <= 1 */ +errno = 0; xf = ((double)x - a) / logo_w2; -xf *= xf; +xf = fabs(xf); // use positive values only, analog to xf^2 +xf = pow(xf, round); +if (isnan(xf)) { +av_log(NULL, AV_LOG_ERROR, + "Error in delogo calculating ellipse value. NAN value returned\n"); +return; +} +if (errno) { +av_log(NULL, AV_LOG_ERROR, + "Error in delogo calculating ellipse value. Math error returned\n"); +return; +} yf = ((double)y - b) / logo_h2; -yf *= yf; +yf = fabs(yf); // use positive values only, analog to yf^2 +yf = pow(yf, round); +if (isnan(yf)) { +av_log(NULL, AV_LOG_ERROR, + "Error in delogo calculating ellipse value. NAN value returned\n"); +return; +} +if (errno) { +av_log(NULL, AV_LOG_ERROR, + "Error in delogo calculating ellipse value. Math error returned\n"); +return; +} if (xf + yf > 1.0) continue; } -- 2.45.3 ___ ffmpeg-devel mailin
[FFmpeg-devel] [PATCH v2 1/2] avfilter/delogo: changed type of parameter 'r' to float
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 --- 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 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2 0/2] Extend delogo area to a superellipse
Version 2 of the pathset. One test "if (isnan(yf))" was missing. Corrected in this version with help from Michael I extended the ellipse area to a superellipse. The user parameter 'r' has changed to become a float value. Values 0 < r < 1 the area looks like a four edge star. Value r = 1 the area get a rhombus. Values 1 < r < 2 the area is a rhombus with concave sides. Value r = 2 the area is an ellipse or a circle. Values 2 < r the area looks like a rectangular with round edges. Value = 0 (default, unset) the area is rectangular. Because of the usage of math functions I added more code testing the return values. The parameter r=2 to get an ellipse delogo area seems non intuitive to me. We should add a better description for the users of the delogo filter. The patch has been tested with 'make fate-rsync fate' rebased on the master branch commit 268d0b6527cba1ebac1f44347578617341f85c35 and applies clean to my previous patchset "Patch to create a circular delogo area" Please have a look. best regards Jörg Jörg Habenicht (2): avfilter/delogo: changed type of parameter 'r' to float avfilter/delogo: change delogo round area to superellipse area libavfilter/vf_delogo.c | 72 + 1 file changed, 58 insertions(+), 14 deletions(-) -- 2.45.3 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH 1/3] avfilter/delogo: add parameter to switch on circular delogo
Hi Am 06.02.25 um 18:12 schrieb Michael Niedermayer: > Hi Jörg > > On Tue, Feb 04, 2025 at 08:53:58PM +0100, Jörg Habenicht via ffmpeg-devel > wrote: >> Add a parameter (boolean) r to switch the area from >> rectangular (r=0) to circular(r=1) delogo. >> [...] >> @@ -209,6 +209,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 }, > maybe a superellipse would be interresting > https://en.wikipedia.org/wiki/Superellipse > > This would allow intermediates between a rectangle, elipse and rhombus > I imagine this could cover more cases of logos hm, good idea. How do I get the user Interface right? Extending the new 'r' option from bool to accept a float type? r=2.0 would result in an ellipse or circle and r=1.0 would result in a rhombus? > > either way teh 3 patches should be merged > > thx > > my pleasure cu Jörg ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".