[vlc-commits] [Git][videolan/vlc][master] 7 commits: subpicture: initialize position to INT_MAX

Steve Lhomme (@robUx4) gitlab at videolan.org
Sun Mar 10 07:20:25 UTC 2024



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
4f0d7e77 by Steve Lhomme at 2024-03-10T06:50:39+00:00
subpicture: initialize position to INT_MAX

So it matches the assert during the final positioning of region when rendering. These values
must be set on the output of the SPU updater.
If it doesn't do it, or didn't initialized the regions properly, the subpicture source is doing it wrong.

- - - - -
23609f0a by Steve Lhomme at 2024-03-10T06:50:39+00:00
vout_subpictures: assert that both original dimensions are set

This should never happen.

- - - - -
5bbfe2e5 by Steve Lhomme at 2024-03-10T06:50:39+00:00
subtitles: assert when the destination doesn't have a SAR during region gathering

This should never happen. The core must fill it.

- - - - -
55696fa2 by Steve Lhomme at 2024-03-10T06:50:39+00:00
video_text: keep all position flags in the text_flags

sys->position is already filtered in vout_OSDText() with SUBPICTURE_ALIGN_MASK.

- - - - -
571b5256 by Steve Lhomme at 2024-03-10T06:50:39+00:00
vout: don't multiply the region alpha by the subpicture alpha

It's already done in the core during SpuRenderRegion().

- - - - -
e079b924 by Steve Lhomme at 2024-03-10T06:50:39+00:00
vlc_subpictures: remove unused vlc_render_subpicture::i_alpha

The rendered regions have an each their own alpha.

- - - - -
ef86d7bd by Steve Lhomme at 2024-03-10T06:50:39+00:00
vout_subpicture: use a multiplication to explicit where the constant is coming from

255 is the max value for subpic->i_alpha and region->i_alpha.

- - - - -


9 changed files:

- include/vlc_subpicture.h
- modules/codec/arib/substext.h
- modules/codec/substext.h
- modules/video_output/opengl/sub_renderer.c
- modules/video_output/win32/direct3d9.c
- modules/video_output/xcb/render.c
- src/misc/subpicture.c
- src/video_output/video_text.c
- src/video_output/vout_subpictures.c


Changes:

=====================================
include/vlc_subpicture.h
=====================================
@@ -209,7 +209,6 @@ typedef struct subpicture_private_t subpicture_private_t;
 struct vlc_render_subpicture
 {
     vlc_spu_regions regions;                  /**< list of regions to render */
-    int          i_alpha;                                  /**< transparency */
     int64_t      i_order;                    /** an increasing unique number */
     unsigned     i_original_picture_width;  /**< original width of the movie */
     unsigned     i_original_picture_height;/**< original height of the movie */


=====================================
modules/codec/arib/substext.h
=====================================
@@ -60,10 +60,7 @@ static void SubpictureTextUpdate(subpicture_t *subpic,
 
     assert( vlc_spu_regions_is_empty( &subpic->regions ) );
 
-    if (fmt_dst->i_sar_num <= 0 || fmt_dst->i_sar_den <= 0)
-    {
-        return;
-    }
+    assert(fmt_dst->i_sar_num && fmt_dst->i_sar_den);
 
     subpicture_region_t *r;
     arib_text_region_t *p_region;


=====================================
modules/codec/substext.h
=====================================
@@ -126,8 +126,7 @@ static void SubpictureTextUpdate(subpicture_t *subpic,
     }
     vlc_spu_regions_Clear( &subpic->regions );
 
-    if (fmt_dst->i_sar_num <= 0 || fmt_dst->i_sar_den <= 0)
-        return;
+    assert(fmt_dst->i_sar_num && fmt_dst->i_sar_den);
 
     vlc_rational_t sar;
 


=====================================
modules/video_output/opengl/sub_renderer.c
=====================================
@@ -262,7 +262,7 @@ vlc_gl_sub_renderer_Prepare(struct vlc_gl_sub_renderer *sr,
                 glr->tex_width  = 1.0;
                 glr->tex_height = 1.0;
             }
-            glr->alpha  = (float)subpicture->i_alpha * r->i_alpha / 255 / 255;
+            glr->alpha  = (float)r->i_alpha / 255;
             glr->left   =  2.0 * (r->i_x                          ) / subpicture->i_original_picture_width  - 1.0;
             glr->top    = -2.0 * (r->i_y                          ) / subpicture->i_original_picture_height + 1.0;
             glr->right  =  2.0 * (r->i_x + r->fmt.i_visible_width ) / subpicture->i_original_picture_width  - 1.0;


=====================================
modules/video_output/win32/direct3d9.c
=====================================
@@ -983,7 +983,7 @@ static void Direct3D9ImportSubpicture(vout_display_t *vd,
         texture_visible_rect.bottom = r->fmt.i_y_offset + r->fmt.i_visible_height;
 
         Direct3D9SetupVertices(d3dr->vertex, &texture_rect, &texture_visible_rect,
-                              &rect_in_display, subpicture->i_alpha * r->i_alpha / 255, ORIENT_NORMAL);
+                              &rect_in_display, r->i_alpha, ORIENT_NORMAL);
         i++;
     }
 }


=====================================
modules/video_output/xcb/render.c
=====================================
@@ -151,9 +151,9 @@ static void RenderRegion(vout_display_t *vd, const vlc_render_subpicture *subpic
                                ARRAY_SIZE(rects), rects);
 
     /* Multiply by region and subpicture alpha factors */
-    static const float alpha_fixed = 0xffffp0f / (0xffp0f * 0xffp0f);
+    static const float alpha_fixed = 0xffffp0f / 0xffp0f;
     xcb_render_color_t alpha_color = {
-        0, 0, 0, lroundf(reg->i_alpha * subpic->i_alpha * alpha_fixed) };
+        0, 0, 0, lroundf(reg->i_alpha * alpha_fixed) };
 
     xcb_render_fill_rectangles(conn, XCB_RENDER_PICT_OP_IN_REVERSE,
                                sys->picture.subpic, alpha_color,


=====================================
src/misc/subpicture.c
=====================================
@@ -34,6 +34,8 @@
 #include <vlc_subpicture.h>
 #include "subpicture.h"
 
+#include <limits.h>
+
 struct subpicture_private_t
 {
     video_format_t src;
@@ -101,7 +103,6 @@ vlc_render_subpicture *vlc_render_subpicture_New( void )
     vlc_render_subpicture *p_subpic = malloc( sizeof(*p_subpic) );
     if( unlikely(p_subpic == NULL ) )
         return NULL;
-    p_subpic->i_alpha = 0xFF;
     p_subpic->i_original_picture_width = 0;
     p_subpic->i_original_picture_height = 0;
     vlc_spu_regions_init(&p_subpic->regions);
@@ -222,6 +223,8 @@ static subpicture_region_t * subpicture_region_NewInternal( void )
     p_region->zoom_h.den = p_region->zoom_h.num = 1;
     p_region->zoom_v.den = p_region->zoom_v.num = 1;
     p_region->i_alpha = 0xff;
+    p_region->i_x = INT_MAX;
+    p_region->i_y = INT_MAX;
 
     return p_region;
 }
@@ -365,8 +368,7 @@ unsigned picture_BlendSubpicture(picture_t *dst,
 
         if (filter_ConfigureBlend(blend, dst->format.i_width,
                                   dst->format.i_height,  &blend_fmt)
-         || filter_Blend(blend, dst, r->i_x, r->i_y, r->p_picture,
-                         src->i_alpha * r->i_alpha / 255))
+         || filter_Blend(blend, dst, r->i_x, r->i_y, r->p_picture, r->i_alpha))
             msg_Err(blend, "blending %4.4s to %4.4s failed",
                     (char *)&blend->fmt_in.video.i_chroma,
                     (char *)&blend->fmt_out.video.i_chroma );


=====================================
src/video_output/video_text.c
=====================================
@@ -51,8 +51,7 @@ static void OSDTextUpdate(subpicture_t *subpic,
 
     vlc_spu_regions_Clear( &subpic->regions );
 
-    if( fmt_dst->i_sar_num <= 0 || fmt_dst->i_sar_den <= 0 )
-        return;
+    assert(fmt_dst->i_sar_den && fmt_dst->i_sar_num);
 
     subpic->b_absolute = false;
     subpic->i_original_picture_width  = fmt_dst->i_visible_width * fmt_dst->i_sar_num / fmt_dst->i_sar_den;
@@ -71,7 +70,7 @@ static void OSDTextUpdate(subpicture_t *subpic,
     const int   margin_h     = margin_ratio * fmt_dst->i_visible_width;
     const int   margin_v     = margin_ratio * fmt_dst->i_visible_height;
 
-    r->text_flags |= sys->position & SUBPICTURE_ALIGN_MASK;
+    r->text_flags |= sys->position;
     r->i_align = sys->position;
     r->i_x = 0;
     if (r->i_align & SUBPICTURE_ALIGN_LEFT)


=====================================
src/video_output/vout_subpictures.c
=====================================
@@ -1188,7 +1188,7 @@ static subpicture_region_t *SpuRenderRegion(spu_t *spu,
             fade_alpha = 255 * (subpic->i_stop - render_date) /
                                 (subpic->i_stop - fade_start);
     }
-    dst->i_alpha   = fade_alpha * subpic->i_alpha * region->i_alpha / 65025;
+    dst->i_alpha   = fade_alpha * subpic->i_alpha * region->i_alpha / (255 * 255);
     return dst;
 }
 
@@ -1197,13 +1197,10 @@ static void spu_UpdateOriginalSize(spu_t *spu, subpicture_t *subpic,
 {
     if (subpic->i_original_picture_width  == 0 ||
         subpic->i_original_picture_height == 0) {
-        if (subpic->i_original_picture_width  > 0 ||
-            subpic->i_original_picture_height > 0)
-            msg_Err(spu, "original picture size %ux%u is unsupported",
-                    subpic->i_original_picture_width,
-                    subpic->i_original_picture_height);
-        else
-            msg_Dbg(spu, "original picture size is undefined");
+        // detect SPU sources filling original picture half-way
+        assert(subpic->i_original_picture_width == 0 &&
+               subpic->i_original_picture_height == 0);
+        msg_Dbg(spu, "original picture size is undefined");
 
         subpic->i_original_picture_width  = fmtsrc->i_visible_width;
         subpic->i_original_picture_height = fmtsrc->i_visible_height;



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/3d136a03dfb42923bcc113a4ab1c0cb087494c14...ef86d7bdd72ca19223bb58ceafa0ac7e4898c79f

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/3d136a03dfb42923bcc113a4ab1c0cb087494c14...ef86d7bdd72ca19223bb58ceafa0ac7e4898c79f
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list