[PATCH] cropadd filter metadata video rotation support

Mitch Capper <[email protected]>
Newsgroups gmane.comp.video.videolan.vlc.devel
Message-ID <CALn233pKzm5JxBspcJwj3Z-S4AVPEtsio_ev8QcZVQRkKQCBHg@mail.gmail.com>
Attached are patches for master and 3.0.x fixing the cropadd function to
respect video orientation.  There is a new crop function coming in 4 so I
am not sure if this will still be used.

This should fix https://code.videolan.org/videolan/vlc/-/issues/25053

~mitch (they, them)

_______________________________________________
vlc-devel mailing list
To unsubscribe or modify your subscription options:
https://mailman.videolan.org/listinfo/vlc-devel
0001-Fixed-cropadd-to-handle-metadata-rotated-videosMaster.patch (application/octet-stream, 2.4 KB)
From b838ed1560ed9255c9caf8a6fff16af3e03fa011 Mon Sep 17 00:00:00 2001
From: Mitch Capper <[email protected]>
Date: Wed, 3 Nov 2021 22:53:24 -0700
Subject: [PATCH] Fixed cropadd to handle metadata rotated videos

---
 modules/video_filter/croppadd.c | 35 +++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/modules/video_filter/croppadd.c b/modules/video_filter/croppadd.c
index c9bdddd5df..c01f461249 100644
--- a/modules/video_filter/croppadd.c
+++ b/modules/video_filter/croppadd.c
@@ -118,6 +118,28 @@ typedef struct
     int i_paddleft;
     int i_paddright;
 } filter_sys_t;
+#define IDX_TOP 0
+#define IDX_LEFT 1
+#define IDX_BOTTOM 2
+#define IDX_RIGHT 3
+
+struct transform {
+    unsigned idx_top;
+    unsigned idx_left;
+    /* idx_bottom is idx_top XOR 2
+       idx_right is idx_left XOR 2 */
+};
+
+static const struct transform transforms[8] = {
+    [ORIENT_TOP_LEFT]     = { IDX_TOP,    IDX_LEFT },
+    [ORIENT_TOP_RIGHT]    = { IDX_TOP,    IDX_RIGHT },
+    [ORIENT_BOTTOM_LEFT]  = { IDX_BOTTOM, IDX_LEFT },
+    [ORIENT_BOTTOM_RIGHT] = { IDX_BOTTOM, IDX_RIGHT },
+    [ORIENT_LEFT_TOP]     = { IDX_LEFT,   IDX_TOP },
+    [ORIENT_LEFT_BOTTOM]  = { IDX_LEFT,   IDX_BOTTOM },
+    [ORIENT_RIGHT_TOP]    = { IDX_RIGHT,  IDX_TOP },
+    [ORIENT_RIGHT_BOTTOM] = { IDX_RIGHT,  IDX_BOTTOM },
+};
 
 /*****************************************************************************
  * OpenFilter: probe the filter and return score
@@ -169,6 +191,19 @@ static int OpenFilter( filter_t *p_filter )
     GET_OPTION( paddleft )
     GET_OPTION( paddright )
 
+    video_format_t *fmt = &p_filter->fmt_in.video;
+    video_orientation_t orientation = fmt->orientation;
+    const struct transform *tx = &transforms[orientation];
+    unsigned crop[] = { p_sys->i_croptop, p_sys->i_cropleft, p_sys->i_cropbottom, p_sys->i_cropright };
+    unsigned padd[] =  { p_sys->i_paddtop, p_sys->i_paddleft, p_sys->i_paddbottom, p_sys->i_paddright };
+    p_sys->i_croptop = crop[tx->idx_top];
+    p_sys->i_cropleft = crop[tx->idx_left];
+    p_sys->i_cropbottom = crop[tx->idx_top ^ 2];
+    p_sys->i_cropright = crop[tx->idx_left ^ 2];
+    p_sys->i_paddtop = padd[tx->idx_top];
+    p_sys->i_paddleft = padd[tx->idx_left];
+    p_sys->i_paddbottom = padd[tx->idx_top ^ 2];
+    p_sys->i_paddright = padd[tx->idx_left ^ 2];
     p_filter->fmt_out.video.i_height =
     p_filter->fmt_out.video.i_visible_height =
         p_filter->fmt_in.video.i_visible_height
-- 
5.55
0001-Fixed-cropadd-to-handle-metadata-rotated-videos3.0.x.patch (application/octet-stream, 2.4 KB)
From aae261f28cd461ec5a2f0280930d15be6374ade7 Mon Sep 17 00:00:00 2001
From: Mitch Capper <[email protected]>
Date: Wed, 3 Nov 2021 22:31:46 -0700
Subject: [PATCH] Fixed cropadd to handle metadata rotated videos

---
 modules/video_filter/croppadd.c | 35 +++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/modules/video_filter/croppadd.c b/modules/video_filter/croppadd.c
index f0145bb075..7017c124c9 100644
--- a/modules/video_filter/croppadd.c
+++ b/modules/video_filter/croppadd.c
@@ -122,6 +122,28 @@ struct filter_sys_t
     int i_paddleft;
     int i_paddright;
 };
+#define IDX_TOP 0
+#define IDX_LEFT 1
+#define IDX_BOTTOM 2
+#define IDX_RIGHT 3
+
+struct transform {
+    unsigned idx_top;
+    unsigned idx_left;
+    /* idx_bottom is idx_top XOR 2
+       idx_right is idx_left XOR 2 */
+};
+
+static const struct transform transforms[8] = {
+    [ORIENT_TOP_LEFT]     = { IDX_TOP,    IDX_LEFT },
+    [ORIENT_TOP_RIGHT]    = { IDX_TOP,    IDX_RIGHT },
+    [ORIENT_BOTTOM_LEFT]  = { IDX_BOTTOM, IDX_LEFT },
+    [ORIENT_BOTTOM_RIGHT] = { IDX_BOTTOM, IDX_RIGHT },
+    [ORIENT_LEFT_TOP]     = { IDX_LEFT,   IDX_TOP },
+    [ORIENT_LEFT_BOTTOM]  = { IDX_LEFT,   IDX_BOTTOM },
+    [ORIENT_RIGHT_TOP]    = { IDX_RIGHT,  IDX_TOP },
+    [ORIENT_RIGHT_BOTTOM] = { IDX_RIGHT,  IDX_BOTTOM },
+};
 
 /*****************************************************************************
  * OpenFilter: probe the filter and return score
@@ -174,6 +196,20 @@ static int OpenFilter( vlc_object_t *p_this )
     GET_OPTION( paddleft )
     GET_OPTION( paddright )
 
+    video_format_t *fmt = &p_filter->fmt_in.video;
+    video_orientation_t orientation = fmt->orientation;
+    const struct transform *tx = &transforms[orientation];
+    unsigned crop[] = { p_sys->i_croptop, p_sys->i_cropleft, p_sys->i_cropbottom, p_sys->i_cropright };
+    unsigned padd[] =  { p_sys->i_paddtop, p_sys->i_paddleft, p_sys->i_paddbottom, p_sys->i_paddright };
+    p_sys->i_croptop = crop[tx->idx_top];
+    p_sys->i_cropleft = crop[tx->idx_left];
+    p_sys->i_cropbottom = crop[tx->idx_top ^ 2];
+    p_sys->i_cropright = crop[tx->idx_left ^ 2];
+    p_sys->i_paddtop = padd[tx->idx_top];
+    p_sys->i_paddleft = padd[tx->idx_left];
+    p_sys->i_paddbottom = padd[tx->idx_top ^ 2];
+    p_sys->i_paddright = padd[tx->idx_left ^ 2];
     p_filter->fmt_out.video.i_height =
     p_filter->fmt_out.video.i_visible_height =
         p_filter->fmt_in.video.i_visible_height
-- 
5.55
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.