[vlc-commits] codec: subsdec/subsusf: do inner align on user value

Francois Cartegnie git at videolan.org
Tue Jul 24 15:42:37 CEST 2018


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Tue Jul 24 14:44:22 2018 +0200| [8b589802198ae4a0c5ba3838922453d93e465fb3] | committer: Francois Cartegnie

codec: subsdec/subsusf: do inner align on user value

adds default -1/auto/invalid value for align.
we had no way to tell if user specified something.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=8b589802198ae4a0c5ba3838922453d93e465fb3
---

 modules/codec/subsdec.c | 33 +++++++++++++++++++++++----------
 modules/codec/subsusf.c | 20 +++++++++++++-------
 2 files changed, 36 insertions(+), 17 deletions(-)

diff --git a/modules/codec/subsdec.c b/modules/codec/subsdec.c
index 364d7a19da..03da4bd70f 100644
--- a/modules/codec/subsdec.c
+++ b/modules/codec/subsdec.c
@@ -162,9 +162,10 @@ static const char *const ppsz_encoding_names[] = {
     N_("Vietnamese (Windows-1258)"),
 };
 
-static const int  pi_justification[] = { 0, 1, 2 };
+static const int  pi_justification[] = { -1, 0, 1, 2 };
 static const char *const ppsz_justification_text[] = {
-    N_("Center"),N_("Left"),N_("Right")};
+    N_("Auto"),N_("Center"),N_("Left"),N_("Right")
+};
 
 #define ENCODING_TEXT N_("Subtitle text encoding")
 #define ENCODING_LONGTEXT N_("Set the encoding used in text subtitles")
@@ -242,7 +243,7 @@ static int OpenDecoder( vlc_object_t *p_this )
     p_dec->fmt_out.i_codec = 0;
 
     /* init of p_sys */
-    p_sys->i_align = 0;
+    p_sys->i_align = -1;
     p_sys->iconv_handle = (vlc_iconv_t)-1;
     p_sys->b_autodetect_utf8 = false;
 
@@ -461,11 +462,24 @@ static subpicture_t *ParseText( decoder_t *p_dec, block_t *p_block )
 
     subtext_updater_sys_t *p_spu_sys = p_spu->updater.p_sys;
 
-    p_spu_sys->region.align = SUBPICTURE_ALIGN_BOTTOM | p_sys->i_align;
-    p_spu_sys->region.inner_align = SUBPICTURE_ALIGN_BOTTOM;
-    p_spu_sys->region.p_segments = ParseSubtitles( &p_spu_sys->region.align, psz_subtitle );
-
+    int i_inline_align = -1;
+    p_spu_sys->region.p_segments = ParseSubtitles( &i_inline_align, psz_subtitle );
     free( psz_subtitle );
+    if( p_sys->i_align >= 0 ) /* bottom ; left, right or centered */
+    {
+        p_spu_sys->region.align = SUBPICTURE_ALIGN_BOTTOM | p_sys->i_align;
+        p_spu_sys->region.inner_align = p_sys->i_align;
+    }
+    else if( i_inline_align >= 0 )
+    {
+        p_spu_sys->region.align = i_inline_align;
+        p_spu_sys->region.inner_align = i_inline_align;
+    }
+    else /* default, bottom ; centered */
+    {
+        p_spu_sys->region.align = SUBPICTURE_ALIGN_BOTTOM;
+        p_spu_sys->region.inner_align = 0;
+    }
 
     return p_spu;
 }
@@ -738,7 +752,7 @@ static text_segment_t* ParseSubtitles( int *pi_align, const char *psz_subtitle )
     //FIXME: Remove initial allocation? Might make the below code more complicated
     p_first_segment = p_segment = text_segment_New( "" );
 
-    bool b_has_align = false;
+    *pi_align = -1;
 
     /* */
     while( *psz_subtitle )
@@ -938,14 +952,13 @@ static text_segment_t* ParseSubtitles( int *pi_align, const char *psz_subtitle )
                  strchr( psz_subtitle, '}' ) )
         {
             /* Check for forced alignment */
-            if( !b_has_align &&
+            if( *pi_align < 0 &&
                 !strncmp( psz_subtitle, "{\\an", 4 ) && psz_subtitle[4] >= '1' && psz_subtitle[4] <= '9' && psz_subtitle[5] == '}' )
             {
                 static const int pi_vertical[3] = { SUBPICTURE_ALIGN_BOTTOM, 0, SUBPICTURE_ALIGN_TOP };
                 static const int pi_horizontal[3] = { SUBPICTURE_ALIGN_LEFT, 0, SUBPICTURE_ALIGN_RIGHT };
                 const int i_id = psz_subtitle[4] - '1';
 
-                b_has_align = true;
                 *pi_align = pi_vertical[i_id/3] | pi_horizontal[i_id%3];
             }
             /* TODO fr -> rotation */
diff --git a/modules/codec/subsusf.c b/modules/codec/subsusf.c
index e9cd2a9645..8b9aef868f 100644
--- a/modules/codec/subsusf.c
+++ b/modules/codec/subsusf.c
@@ -437,12 +437,17 @@ static subpicture_region_t *CreateTextRegion( decoder_t *p_dec,
             }
         }
 
+        /* Set default or user align/magin.
+         * Style overriden if no user value. */
+        p_text_region->i_x = i_sys_align > 0 ? 20 : 0;
+        p_text_region->i_y = 10;
+        p_text_region->i_align = SUBPICTURE_ALIGN_BOTTOM |
+                                 ((i_sys_align > 0) ? i_sys_align : 0);
+
         if( p_ssa_style )
         {
             msg_Dbg( p_dec, "style is: %s", p_ssa_style->psz_stylename );
 
-            p_text_region->i_align = p_ssa_style->i_align;
-
             /* TODO: Setup % based offsets properly, without adversely affecting
              *       everything else in vlc. Will address with separate patch,
              *       to prevent this one being any more complicated.
@@ -450,15 +455,16 @@ static subpicture_region_t *CreateTextRegion( decoder_t *p_dec,
                      * p_ssa_style->i_margin_percent_h;
                      * p_ssa_style->i_margin_percent_v;
              */
-            p_text_region->i_x         = p_ssa_style->i_margin_h;
-            p_text_region->i_y         = p_ssa_style->i_margin_v;
+            if( i_sys_align == -1 )
+            {
+                p_text_region->i_align     = p_ssa_style->i_align;
+                p_text_region->i_x         = p_ssa_style->i_margin_h;
+                p_text_region->i_y         = p_ssa_style->i_margin_v;
+            }
             p_text_region->p_text = text_segment_NewInheritStyle( p_ssa_style->p_style );
         }
         else
         {
-            p_text_region->i_align = SUBPICTURE_ALIGN_BOTTOM | i_sys_align;
-            p_text_region->i_x = i_sys_align ? 20 : 0;
-            p_text_region->i_y = 10;
             p_text_region->p_text = text_segment_New( NULL );
         }
         /* Look for position arguments which may override the style-based



More information about the vlc-commits mailing list