* [FFmpeg-devel] [PATCH 3/3] avfilter/delogo: added the circular delogo algorithm
@ 2025-02-03 20:45 Jörg Habenicht via ffmpeg-devel
0 siblings, 0 replies; 2+ messages in thread
From: Jörg Habenicht via ffmpeg-devel @ 2025-02-03 20:45 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Jörg Habenicht
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 <j.habenicht@gmx.de>
---
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 & ((1<<hsub)-1)), hsub),
AV_CEIL_RSHIFT(s->h + (s->y & ((1<<vsub)-1)), vsub),
s->band>>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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 2+ messages in thread
* [FFmpeg-devel] [PATCH 0/3] Patch to create a circular delogo area
@ 2025-02-04 19:53 Jörg Habenicht via ffmpeg-devel
2025-02-04 19:54 ` [FFmpeg-devel] [PATCH 3/3] avfilter/delogo: added the circular delogo algorithm Jörg Habenicht via ffmpeg-devel
0 siblings, 1 reply; 2+ messages in thread
From: Jörg Habenicht via ffmpeg-devel @ 2025-02-04 19:53 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Jörg Habenicht
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 2+ messages in thread
* [FFmpeg-devel] [PATCH 3/3] avfilter/delogo: added the circular delogo algorithm
2025-02-04 19:53 [FFmpeg-devel] [PATCH 0/3] Patch to create a circular delogo area Jörg Habenicht via ffmpeg-devel
@ 2025-02-04 19:54 ` Jörg Habenicht via ffmpeg-devel
0 siblings, 0 replies; 2+ messages in thread
From: Jörg Habenicht via ffmpeg-devel @ 2025-02-04 19:54 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Jörg Habenicht
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 <j.habenicht@gmx.de>
---
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 & ((1<<hsub)-1)), hsub),
AV_CEIL_RSHIFT(s->h + (s->y & ((1<<vsub)-1)), vsub),
s->band>>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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-02-04 19:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-03 20:45 [FFmpeg-devel] [PATCH 3/3] avfilter/delogo: added the circular delogo algorithm Jörg Habenicht via ffmpeg-devel
2025-02-04 19:53 [FFmpeg-devel] [PATCH 0/3] Patch to create a circular delogo area Jörg Habenicht via ffmpeg-devel
2025-02-04 19:54 ` [FFmpeg-devel] [PATCH 3/3] avfilter/delogo: added the circular delogo algorithm Jörg Habenicht via ffmpeg-devel
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