From: "Jörg Habenicht via ffmpeg-devel" <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: "Jörg Habenicht" <j.habenicht@gmx.de>
Subject: [FFmpeg-devel] [PATCH v2 2/2] avfilter/delogo: change delogo round area to superellipse area
Date: Fri, 7 Feb 2025 23:47:33 +0100
Message-ID: <20250207224733.4666-3-j.habenicht@gmx.de> (raw)
In-Reply-To: <20250207224733.4666-1-j.habenicht@gmx.de>
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 <j.habenicht@gmx.de>
---
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 mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
prev parent reply other threads:[~2025-02-07 22:48 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-07 22:47 [FFmpeg-devel] [PATCH v2 0/2] Extend delogo area to a superellipse Jörg Habenicht via ffmpeg-devel
2025-02-07 22:47 ` [FFmpeg-devel] [PATCH v2 1/2] avfilter/delogo: changed type of parameter 'r' to float Jörg Habenicht via ffmpeg-devel
2025-02-07 22:47 ` Jörg Habenicht via ffmpeg-devel [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250207224733.4666-3-j.habenicht@gmx.de \
--to=ffmpeg-devel@ffmpeg.org \
--cc=j.habenicht@gmx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git