[vlc-devel] [PATCH 04/14] Added secondary subtitle configuration

Thomas Guillem thomas at gllm.fr
Mon May 13 11:55:42 CEST 2019


You should split this commit in two: core, then Qt.

Ando also, nitpick in commit title: added -> add

On Sat, May 11, 2019, at 08:33, Roland Bewick wrote:
> - Alignment (default unset)
> - Margin (Positive value to avoid overlap with primary subs)
> ---
>  modules/gui/qt/components/simple_preferences.cpp |  3 +
>  modules/gui/qt/ui/sprefs_subtitles.ui            | 91 ++++++++++++++++++++++++
>  src/video_output/vout_subpictures.c              | 41 ++++++++---
>  3 files changed, 127 insertions(+), 8 deletions(-)
> 
> diff --git a/modules/gui/qt/components/simple_preferences.cpp 
> b/modules/gui/qt/components/simple_preferences.cpp
> index 914b92f07d..7d41ae3f1c 100644
> --- a/modules/gui/qt/components/simple_preferences.cpp
> +++ b/modules/gui/qt/components/simple_preferences.cpp
> @@ -870,6 +870,9 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, 
> QWidget *_parent,
>              optionWidgets["shadowCB"] = ui.shadowCheck;
>              optionWidgets["backgroundCB"] = ui.backgroundCheck;
>  
> +            CONFIG_GENERIC( "secondary-spu-alignment", IntegerList,
> +                            ui.secondarySubsAlignmentLabel, 
> secondarySubsAlignment );
> +            CONFIG_GENERIC_NO_BOOL( "secondary-sub-margin", Integer, 
> ui.secondarySubsPosLabel, secondarySubsPosition );
>          END_SPREFS_CAT;
>  
>          case SPrefsHotkeys:
> diff --git a/modules/gui/qt/ui/sprefs_subtitles.ui 
> b/modules/gui/qt/ui/sprefs_subtitles.ui
> index b9e851dc9d..d630a60660 100644
> --- a/modules/gui/qt/ui/sprefs_subtitles.ui
> +++ b/modules/gui/qt/ui/sprefs_subtitles.ui
> @@ -313,6 +313,97 @@
>          </layout>
>         </widget>
>        </item>
> +      <item>
> +       <widget class="QGroupBox" name="groupBox_5">
> +        <property name="sizePolicy">
> +         <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
> +          <horstretch>0</horstretch>
> +          <verstretch>0</verstretch>
> +         </sizepolicy>
> +        </property>
> +        <property name="title">
> +         <string>Dual Subtitles</string>
> +        </property>
> +        <layout class="QVBoxLayout" name="verticalLayout">
> +         <item>
> +          <widget class="QWidget" name="secondarySpuZone" 
> native="true">
> +           <layout class="QGridLayout">
> +            <item row="0" column="1">
> +             <widget class="QComboBox" name="secondarySubsAlignment"/>
> +            </item>
> +            <item row="0" column="0">
> +             <widget class="QLabel" name="secondarySubsAlignmentLabel">
> +              <property name="sizePolicy">
> +               <sizepolicy hsizetype="Maximum" vsizetype="Preferred">
> +                <horstretch>0</horstretch>
> +                <verstretch>0</verstretch>
> +               </sizepolicy>
> +              </property>
> +              <property name="text">
> +               <string>Align</string>
> +              </property>
> +              <property name="alignment">
> +               
> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
> +              </property>
> +              <property name="buddy">
> +               <cstring>secondarySubsAlignment</cstring>
> +              </property>
> +             </widget>
> +            </item>
> +            <item row="0" column="2">
> +             <spacer name="horizontalSpacer">
> +              <property name="orientation">
> +               <enum>Qt::Horizontal</enum>
> +              </property>
> +              <property name="sizeType">
> +               <enum>QSizePolicy::Preferred</enum>
> +              </property>
> +              <property name="sizeHint" stdset="0">
> +               <size>
> +                <width>50</width>
> +                <height>20</height>
> +               </size>
> +              </property>
> +             </spacer>
> +            </item>
> +            <item row="0" column="3">
> +             <widget class="QLabel" name="secondarySubsPosLabel">
> +              <property name="text">
> +               <string>Offset</string>
> +              </property>
> +              <property name="buddy">
> +               <cstring>secondarySubsPosition</cstring>
> +              </property>
> +             </widget>
> +            </item>
> +            <item row="0" column="4">
> +             <widget class="QSpinBox" name="secondarySubsPosition">
> +              <property name="maximumSize">
> +               <size>
> +                <width>16777215</width>
> +                <height>16777215</height>
> +               </size>
> +              </property>
> +              <property name="alignment">
> +               
> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
> +              </property>
> +              <property name="suffix">
> +               <string> px</string>
> +              </property>
> +              <property name="minimum">
> +               <number>-1024</number>
> +              </property>
> +              <property name="maximum">
> +               <number>1024</number>
> +              </property>
> +             </widget>
> +            </item>
> +           </layout>
> +          </widget>
> +         </item>
> +        </layout>
> +       </widget>
> +      </item>
>       </layout>
>      </widget>
>     </item>
> diff --git a/src/video_output/vout_subpictures.c 
> b/src/video_output/vout_subpictures.c
> index 6b106534d3..9fdbf0dc94 100644
> --- a/src/video_output/vout_subpictures.c
> +++ b/src/video_output/vout_subpictures.c
> @@ -52,6 +52,9 @@
>  /* Number of simultaneous subpictures */
>  #define VOUT_MAX_SUBPICTURES (__MAX(VOUT_MAX_PICTURES, 
> SPU_MAX_PREPARE_TIME/5000))
>  
> +/* ID of the primary SPU. Secondary SPU IDs will be higher. */
> +#define SPU_ID_PRIMARY 1
> +
>  /* Hold of subpicture with converted ts */
>  typedef struct {
>      subpicture_t *subpicture;
> @@ -91,6 +94,9 @@ struct spu_private_t {
>      atomic_int margin;                 /**< force position of a subpicture */
>      video_palette_t palette;              /**< force palette of subpicture */
>  
> +    int secondary_sub_alignment;   /**< force alignment for secondary 
> subs */
> +    int secondary_sub_margin;      /**< move the secondary sub 
> vertically  */
> +
>      /* Subpiture filters */
>      char           *source_chain_current;
>      char           *source_chain_update;
> @@ -468,23 +474,28 @@ static void SpuAreaFitInside(spu_area_t *area, 
> const spu_area_t *boundary)
>   */
>  static void SpuRegionPlace(int *x, int *y,
>                             const subpicture_t *subpic,
> -                           const subpicture_region_t *region)
> +                           const subpicture_region_t *region,
> +                           int i_secondary_spu_align_override)
>  {
> +    int i_align = region->i_align;
> +    if (subpic->i_spu_id > SPU_ID_PRIMARY && 
> i_secondary_spu_align_override >= 0)
> +        i_align = i_secondary_spu_align_override;
> +
>      assert(region->i_x != INT_MAX && region->i_y != INT_MAX);
>      if (subpic->b_absolute) {
>          *x = region->i_x;
>          *y = region->i_y;
>      } else {
> -        if (region->i_align & SUBPICTURE_ALIGN_TOP)
> -            *y = region->i_y;
> -        else if (region->i_align & SUBPICTURE_ALIGN_BOTTOM)
> +        if (i_align & SUBPICTURE_ALIGN_TOP)
> +            *y = region->i_y + ( subpic->b_subtitle ? 
> region->fmt.i_visible_height : 0 );
> +        else if (i_align & SUBPICTURE_ALIGN_BOTTOM)
>              *y = subpic->i_original_picture_height - 
> region->fmt.i_visible_height - region->i_y;
>          else
>              *y = subpic->i_original_picture_height / 2 - 
> region->fmt.i_visible_height / 2;
>  
> -        if (region->i_align & SUBPICTURE_ALIGN_LEFT)
> +        if (i_align & SUBPICTURE_ALIGN_LEFT)
>              *x = region->i_x;
> -        else if (region->i_align & SUBPICTURE_ALIGN_RIGHT)
> +        else if (i_align & SUBPICTURE_ALIGN_RIGHT)
>              *x = subpic->i_original_picture_width - 
> region->fmt.i_visible_width - region->i_x;
>          else
>              *x = subpic->i_original_picture_width / 2 - 
> region->fmt.i_visible_width / 2;
> @@ -777,7 +788,9 @@ static void SpuRenderRegion(spu_t *spu,
>  
>      /* Compute the margin which is expressed in destination pixel unit
>       * The margin is applied only to subtitle and when no forced crop 
> is
> -     * requested (dvd menu) */
> +     * requested (dvd menu).
> +     * Note: Margin will also be applied to secondary subtitles if 
> they exist
> +     * to ensure that overlap does not occur. */
>      int y_margin = 0;
>      if (!crop_requested && subpic->b_subtitle)
>          y_margin = spu_invscale_h(atomic_load(&sys->margin), 
> scale_size);
> @@ -785,7 +798,14 @@ static void SpuRenderRegion(spu_t *spu,
>      /* Place the picture
>       * We compute the position in the rendered size */
>      SpuRegionPlace(&x_offset, &y_offset,
> -                   subpic, region);
> +                   subpic, region, sys->secondary_sub_alignment);
> +
> +    if (subpic->i_spu_id > SPU_ID_PRIMARY && !subpic->b_absolute)
> +    {
> +        /* Move the secondary subtitles by the secondary margin before 
> overlap detection.
> +           This way, overlaps will be resolved if they still exist. */
> +        y_offset -= 
> spu_invscale_h(atomic_load(&sys->secondary_sub_margin), scale_size);
> +    }
>  
>      /* Save this position for subtitle overlap support
>       * it is really important that there are given without scale_size 
> applied */
> @@ -1386,6 +1406,11 @@ spu_t *spu_Create(vlc_object_t *object, 
> vout_thread_t *vout)
>      sys->scale_yuvp = NULL;
>  
>      atomic_init(&sys->margin, var_InheritInteger(spu, "sub-margin"));
> +    atomic_init(&sys->secondary_sub_margin,
> +                var_InheritInteger(spu, "secondary-sub-margin"));
> +
> +    sys->secondary_sub_alignment = var_InheritInteger(spu,
> +                                                      
> "secondary-spu-alignment");
>  
>      /* Register the default subpicture channel */
>      sys->channel = VOUT_SPU_CHANNEL_AVAIL_FIRST;
> -- 
> 2.11.0
> 
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel


More information about the vlc-devel mailing list