[vlc-commits] [Git][videolan/vlc][master] 19 commits: vout_subpictures: don't rely on the cropped format for chroma conversion

Steve Lhomme (@robUx4) gitlab at videolan.org
Wed Feb 7 17:43:20 UTC 2024



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
32baf8df by Steve Lhomme at 2024-02-07T17:24:44+00:00
vout_subpictures: don't rely on the cropped format for chroma conversion

So it remains independent of the rest of the code.

- - - - -
018d5828 by Steve Lhomme at 2024-02-07T17:24:44+00:00
subpicture: move the assert on chroma in subpicture_region_ForPicture()

The documentation says the chroma must match.

- - - - -
8680f730 by Steve Lhomme at 2024-02-07T17:24:44+00:00
subpicture: allow NULL format for subpicture_region_ForPicture()

- - - - -
ee03ffe3 by Steve Lhomme at 2024-02-07T17:24:44+00:00
zvbi: don't pass region format to set opaque bits

We are really filling bits in the picture of the region. We don't need to know how it will be cropped.
The picture regions are created with subpicture_region_New() so the 2 formats are the same anyway.

- - - - -
bebc3bca by Steve Lhomme at 2024-02-07T17:24:44+00:00
logo: use the cropping data from the source picture

If the original picture has some aspect ratio and/or cropping, it needs to be respected when drawing it.

- - - - -
3556c97b by Steve Lhomme at 2024-02-07T17:24:44+00:00
mosaic: only initialize fmt_in if we're going to use it

It's only used when converting the image at each run.

- - - - -
bef8857c by Steve Lhomme at 2024-02-07T17:24:44+00:00
mosaic: use the converted format directly

When coming out of the converter it's the same as fmt_out, and otherwise we set fmt_out to the same values.

- - - - -
1c38d44c by Steve Lhomme at 2024-02-07T17:24:44+00:00
mosaic: use the cropping data from the source picture

If the original picture has some aspect ratio and/or cropping, it needs to be respected when drawing it.

- - - - -
bee69545 by Steve Lhomme at 2024-02-07T17:24:44+00:00
mosaic: only initialize fmt_out if we're going to use it

It's only used when converting the image at each run.

- - - - -
e9b8cefb by Steve Lhomme at 2024-02-07T17:24:44+00:00
rss: use the picture visible dimensions

Rather than the plane ones. They are the same value.

- - - - -
39bff27f by Steve Lhomme at 2024-02-07T17:24:44+00:00
rss: use the cropping data from the source picture

If the original picture has some aspect ratio and/or cropping, it needs to be respected when drawing it.

- - - - -
eeb64b36 by Steve Lhomme at 2024-02-07T17:24:44+00:00
svg: use the cropping data from the source picture

If the original picture has some aspect ratio and/or cropping, it needs to be respected when drawing it.

- - - - -
2361e89a by Steve Lhomme at 2024-02-07T17:24:44+00:00
dynamicoverlay: use the cropping data from the source picture

In the case it's not text, it's initialized to p_ovl->data.p_pic->format.

If the original picture has some aspect ratio and/or cropping, it needs to be respected when drawing it.

- - - - -
d52145f1 by Steve Lhomme at 2024-02-07T17:24:44+00:00
dynamicoverlay: replace internal format with an telling if it's set and its type

This is used to differentiate what part of the union should be used.
A former format.i_chroma==0 meant it was not set.

- - - - -
15721470 by Steve Lhomme at 2024-02-07T17:24:44+00:00
subpicture: set the SAR reset after creating the picture region

- - - - -
efec2462 by Steve Lhomme at 2024-02-07T17:24:44+00:00
subpicture: pass NULL as the region format

It's the same format as the picture except for the SAR which is set later.

- - - - -
31a5960f by Steve Lhomme at 2024-02-07T17:24:44+00:00
test/opengl: pass NULL as the region format

It's the same format as the picture.

- - - - -
811db2d9 by Steve Lhomme at 2024-02-07T17:24:44+00:00
subpicture_helper: pass NULL as the region format

It's the same format as the picture.

- - - - -
37bd1351 by Steve Lhomme at 2024-02-07T17:24:44+00:00
imageupdater: pass NULL as the region format

It's the format of the picture.

- - - - -


14 changed files:

- include/vlc_subpicture.h
- modules/codec/ttml/imageupdater.h
- modules/codec/zvbi.c
- modules/spu/dynamicoverlay/dynamicoverlay.c
- modules/spu/dynamicoverlay/dynamicoverlay.h
- modules/spu/dynamicoverlay/dynamicoverlay_commands.c
- modules/spu/logo.c
- modules/spu/mosaic.c
- modules/spu/rss.c
- modules/text_renderer/svg.c
- src/misc/subpicture.c
- src/video_output/vout_spuregion_helper.h
- src/video_output/vout_subpictures.c
- test/modules/video_output/opengl/sub_renderer.c


Changes:

=====================================
include/vlc_subpicture.h
=====================================
@@ -147,6 +147,10 @@ VLC_API subpicture_region_t * subpicture_region_NewText( void );
  * The chroma of the format must match the one of the picture.
  * The dimensions of the format should not exceed the ones of the picture. This
  * is not checked explicitly in the function.
+ *
+ * \param p_fmt format for the subpicture cropping/SAR (may be NULL)
+ *
+ * \note if p_fmt is NULL, the format of the picture will be used.
  */
 VLC_API subpicture_region_t * subpicture_region_ForPicture( const video_format_t *p_fmt, picture_t *pic );
 


=====================================
modules/codec/ttml/imageupdater.h
=====================================
@@ -95,7 +95,7 @@ static void TTML_ImageSpuUpdate(subpicture_t *p_spu,
     for(ttml_image_updater_region_t *p_updtregion = p_sys->p_regions;
                                      p_updtregion; p_updtregion = p_updtregion->p_next)
     {
-        subpicture_region_t *r = subpicture_region_ForPicture(&p_updtregion->p_pic->format, p_updtregion->p_pic);
+        subpicture_region_t *r = subpicture_region_ForPicture(NULL, p_updtregion->p_pic);
         if (unlikely(r == NULL))
             return;
 


=====================================
modules/codec/zvbi.c
=====================================
@@ -181,7 +181,7 @@ static subpicture_t *Subpicture( decoder_t *p_dec,
 
 static void EventHandler( vbi_event *ev, void *user_data );
 static int OpaquePage( picture_t *p_src, const vbi_page *p_page,
-                       const video_format_t *p_fmt, bool b_opaque, const int text_offset );
+                       bool b_opaque, const int text_offset );
 static int get_first_visible_row( vbi_char *p_text, int rows, int columns);
 static int get_last_visible_row( vbi_char *p_text, int rows, int columns);
 
@@ -502,7 +502,7 @@ static int Decode( decoder_t *p_dec, block_t *p_block )
         memcpy( p_sys->nav_link, &p_page.nav_link, sizeof( p_sys->nav_link )) ;
         vlc_mutex_unlock( &p_sys->lock );
 
-        OpaquePage( p_pic, &p_page, &p_region->fmt, b_opaque, i_first_row * p_page.columns );
+        OpaquePage( p_pic, &p_page, b_opaque, i_first_row * p_page.columns );
     }
 
 exit:
@@ -641,16 +641,16 @@ static int get_last_visible_row( vbi_char *p_text, int rows, int columns)
 }
 
 static int OpaquePage( picture_t *p_src, const vbi_page *p_page,
-                       const video_format_t *p_fmt, bool b_opaque, const int text_offset )
+                       bool b_opaque, const int text_offset )
 {
     unsigned int    x, y;
 
-    assert( p_fmt->i_chroma == VLC_CODEC_RGBA );
+    assert( p_src->format.i_chroma == VLC_CODEC_RGBA );
 
     /* Kludge since zvbi doesn't provide an option to specify opacity. */
-    for( y = 0; y < p_fmt->i_height; y++ )
+    for( y = 0; y < p_src->format.i_height; y++ )
     {
-        for( x = 0; x < p_fmt->i_width; x++ )
+        for( x = 0; x < p_src->format.i_width; x++ )
         {
             const vbi_opacity opacity = p_page->text[ text_offset + y/10 * p_page->columns + x/12 ].opacity;
             const int background = p_page->text[ text_offset + y/10 * p_page->columns + x/12 ].background;


=====================================
modules/spu/dynamicoverlay/dynamicoverlay.c
=====================================
@@ -353,27 +353,28 @@ static subpicture_t *Filter( filter_t *p_filter, vlc_tick_t date )
 
     vlc_vector_foreach(p_overlay, &p_sys->overlays)
     {
-        if (!p_overlay->b_active || p_overlay->format.i_chroma == 0)
+        if (!p_overlay->b_active || p_overlay->type == OVERLAY_UNSET)
             continue;
 
         subpicture_region_t *p_region;
 
-        if( p_overlay->format.i_chroma == 0 )
+        if( p_overlay->type == OVERLAY_IS_TEXT )
             p_region = subpicture_region_NewText();
         else
-            p_region = subpicture_region_ForPicture( &p_overlay->format, p_overlay->data.p_pic );
+            p_region = subpicture_region_ForPicture( NULL, p_overlay->data.p_pic );
         if( unlikely(p_region == NULL) )
         {
             break;
         }
 
         msg_Dbg( p_filter, "Displaying overlay: %4.4s, %d, %d, %d",
-                 (char*)&p_overlay->format.i_chroma, p_overlay->i_x, p_overlay->i_y,
+                 p_overlay->type == OVERLAY_IS_TEXT ? "TEXT" : (char*)&p_overlay->data.p_pic->format.i_chroma,
+                 p_overlay->i_x, p_overlay->i_y,
                  p_overlay->i_alpha );
 
-        if( p_overlay->format.i_chroma == 0 )
+        if( p_overlay->type == OVERLAY_IS_TEXT )
         {
-            video_format_Copy( &p_region->fmt, &p_overlay->format );
+            video_format_Setup( &p_region->fmt, 0, 0, 0, 0, 0, 0, 1 );
             p_region->p_text = text_segment_New( p_overlay->data.p_text );
             p_region->p_text->style = text_style_Duplicate( p_overlay->p_fontstyle );
         }


=====================================
modules/spu/dynamicoverlay/dynamicoverlay.h
=====================================
@@ -133,7 +133,11 @@ typedef struct overlay_t
     int i_alpha;
     bool b_active;
 
-    video_format_t format;
+    enum {
+        OVERLAY_UNSET,
+        OVERLAY_IS_TEXT,
+        OVERLAY_IS_PICTURE,
+    } type;
     text_style_t *p_fontstyle;
     union {
         picture_t *p_pic;


=====================================
modules/spu/dynamicoverlay/dynamicoverlay_commands.c
=====================================
@@ -54,8 +54,7 @@ overlay_t *OverlayCreate( void )
     p_ovl->i_x = p_ovl->i_y = 0;
     p_ovl->i_alpha = 0xFF;
     p_ovl->b_active = false;
-    video_format_Setup( &p_ovl->format, 0, 0, 0,
-                        0, 0, 1, 1 );
+    p_ovl->type = OVERLAY_UNSET;
     p_ovl->p_fontstyle = text_style_Create( STYLE_NO_DEFAULTS );
     p_ovl->data.p_text = NULL;
     p_ovl->data.p_pic = NULL;
@@ -480,8 +479,7 @@ static int exec_DataSharedMem( filter_t *p_filter,
             return VLC_ENOMEM;
         }
 
-        video_format_Setup( &p_ovl->format, 0,
-                            0, 0, 0, 0, 0, 1 );
+        p_ovl->type = OVERLAY_IS_TEXT;
 
         p_data = shmat( p_params->i_shmid, NULL, SHM_RDONLY );
         if( p_data == NULL )
@@ -509,7 +507,7 @@ static int exec_DataSharedMem( filter_t *p_filter,
         if( p_ovl->data.p_pic == NULL )
             return VLC_ENOMEM;
 
-        p_ovl->format = p_ovl->data.p_pic->format;
+        p_ovl->type = OVERLAY_IS_PICTURE;
 
         for( size_t i_plane = 0; i_plane < (size_t)p_ovl->data.p_pic->i_planes;
              ++i_plane )


=====================================
modules/spu/logo.c
=====================================
@@ -319,7 +319,6 @@ static subpicture_t *FilterSub( filter_t *p_filter, vlc_tick_t date )
 
     subpicture_t *p_spu;
     subpicture_region_t *p_region;
-    video_format_t fmt;
     picture_t *p_pic;
     logo_t *p_logo;
 
@@ -362,13 +361,7 @@ static subpicture_t *FilterSub( filter_t *p_filter, vlc_tick_t date )
         goto exit;
 
     /* Create new SPU region */
-    video_format_Copy(&fmt, &p_pic->format);
-    fmt.i_sar_num = fmt.i_sar_den = 1;
-    fmt.i_width = fmt.i_visible_width = p_pic->p[Y_PLANE].i_visible_pitch;
-    fmt.i_height = fmt.i_visible_height = p_pic->p[Y_PLANE].i_visible_lines;
-    fmt.i_x_offset = fmt.i_y_offset = 0;
-    p_region = subpicture_region_ForPicture( &fmt, p_pic );
-    video_format_Clean(&fmt);
+    p_region = subpicture_region_ForPicture( NULL, p_pic );
     if( !p_region )
     {
         msg_Err( p_filter, "cannot allocate SPU region" );


=====================================
modules/spu/mosaic.c
=====================================
@@ -586,12 +586,11 @@ static subpicture_t *Filter( filter_t *p_filter, vlc_tick_t date )
         i_row = ( i_real_index / p_sys->i_cols ) % p_sys->i_rows;
         i_col = i_real_index % p_sys->i_cols ;
 
-        video_format_Init( &fmt_in, 0 );
-        video_format_Init( &fmt_out, 0 );
-
         p_converted = vlc_picture_chain_PeekFront( &p_es->pictures );
         if ( !p_sys->b_keep )
         {
+            video_format_Init( &fmt_in, 0 );
+            video_format_Init( &fmt_out, 0 );
             /* Convert the images */
             fmt_in.i_chroma = p_converted->format.i_chroma;
             fmt_in.i_height = p_converted->format.i_height;
@@ -625,32 +624,22 @@ static subpicture_t *Filter( filter_t *p_filter, vlc_tick_t date )
 
             p_converted = image_Convert( p_sys->p_image, p_converted,
                                          &fmt_in, &fmt_out );
+            video_format_Clean( &fmt_in );
+            video_format_Clean( &fmt_out );
             if( !p_converted )
             {
                 msg_Warn( p_filter,
                            "image resizing and chroma conversion failed" );
-                video_format_Clean( &fmt_in );
-                video_format_Clean( &fmt_out );
                 continue;
             }
         }
-        else
-        {
-            fmt_in.i_width = fmt_out.i_width = p_converted->format.i_width;
-            fmt_in.i_height = fmt_out.i_height = p_converted->format.i_height;
-            fmt_in.i_chroma = fmt_out.i_chroma = p_converted->format.i_chroma;
-            fmt_out.i_visible_width = fmt_out.i_width;
-            fmt_out.i_visible_height = fmt_out.i_height;
-        }
 
-        p_region = subpicture_region_ForPicture( &fmt_out, p_converted );
+        p_region = subpicture_region_ForPicture( NULL, p_converted );
         if( !p_sys->b_keep )
             picture_Release( p_converted );
 
         if( !p_region )
         {
-            video_format_Clean( &fmt_in );
-            video_format_Clean( &fmt_out );
             msg_Err( p_filter, "cannot allocate SPU region" );
             subpicture_Delete( p_spu );
             vlc_global_unlock( VLC_MOSAIC_MUTEX );
@@ -670,7 +659,7 @@ static subpicture_t *Filter( filter_t *p_filter, vlc_tick_t date )
         }
         else
         {
-            if( fmt_out.i_width > col_inner_width ||
+            if( p_converted->format.i_width > col_inner_width ||
                 p_sys->b_ar || p_sys->b_keep )
             {
                 /* we don't have to center the video since it takes the
@@ -685,10 +674,10 @@ static subpicture_t *Filter( filter_t *p_filter, vlc_tick_t date )
                 p_region->i_x = p_sys->i_xoffset
                         + i_col * ( p_sys->i_width / p_sys->i_cols )
                         + ( i_col * p_sys->i_borderw ) / p_sys->i_cols
-                        + ( col_inner_width - fmt_out.i_width ) / 2;
+                        + ( col_inner_width - p_converted->format.i_width ) / 2;
             }
 
-            if( fmt_out.i_height > row_inner_height
+            if( p_converted->format.i_height > row_inner_height
                 || p_sys->b_ar || p_sys->b_keep )
             {
                 /* we don't have to center the video since it takes the
@@ -703,16 +692,13 @@ static subpicture_t *Filter( filter_t *p_filter, vlc_tick_t date )
                 p_region->i_y = p_sys->i_yoffset
                         + i_row * ( p_sys->i_height / p_sys->i_rows )
                         + ( i_row * p_sys->i_borderh ) / p_sys->i_rows
-                        + ( row_inner_height - fmt_out.i_height ) / 2;
+                        + ( row_inner_height - p_converted->format.i_height ) / 2;
             }
         }
         p_region->i_align = p_sys->i_align;
         p_region->i_alpha = p_es->i_alpha;
 
         vlc_spu_regions_push(&p_spu->regions, p_region);
-
-        video_format_Clean( &fmt_in );
-        video_format_Clean( &fmt_out );
     }
 
     vlc_global_unlock( VLC_MOSAIC_MUTEX );


=====================================
modules/spu/rss.c
=====================================
@@ -500,17 +500,8 @@ static subpicture_t *Filter( filter_t *p_filter, vlc_tick_t date )
     {
         /* Display the feed's image */
         picture_t *p_pic = p_feed->p_pic;
-        video_format_t fmt_out;
 
-        video_format_Copy( &fmt_out, &p_pic->format );
-
-        fmt_out.i_sar_num = fmt_out.i_sar_den = 1;
-        fmt_out.i_width =
-            fmt_out.i_visible_width = p_pic->p[Y_PLANE].i_visible_pitch;
-        fmt_out.i_height =
-            fmt_out.i_visible_height = p_pic->p[Y_PLANE].i_visible_lines;
-
-        p_region = subpicture_region_ForPicture( &fmt_out, p_pic );
+        p_region = subpicture_region_ForPicture( NULL, p_pic );
         if( !p_region )
         {
             msg_Err( p_filter, "cannot allocate SPU region" );
@@ -522,9 +513,8 @@ static subpicture_t *Filter( filter_t *p_filter, vlc_tick_t date )
             vlc_spu_regions_push( &p_spu->regions, p_region );
 
             /* Offset text to display right next to the image */
-            region->i_x += fmt_out.i_visible_width;
+            region->i_x += p_pic->format.i_visible_width;
         }
-        video_format_Clean(&fmt_out);
     }
 
     vlc_mutex_unlock( &p_sys->lock );


=====================================
modules/text_renderer/svg.c
=====================================
@@ -385,7 +385,7 @@ static subpicture_region_t *RenderText( filter_t *p_filter,
     if (p_picture == NULL)
         return NULL;
 
-    subpicture_region_t *p_region_out = subpicture_region_ForPicture(&p_picture->format, p_picture);
+    subpicture_region_t *p_region_out = subpicture_region_ForPicture(NULL, p_picture);
     picture_Release(p_picture);
     if (unlikely(p_region_out == NULL))
         return NULL;


=====================================
src/misc/subpicture.c
=====================================
@@ -147,10 +147,7 @@ subpicture_t *subpicture_NewFromPicture( vlc_object_t *p_obj,
     p_subpic->i_original_picture_width  = fmt_out.i_visible_width;
     p_subpic->i_original_picture_height = fmt_out.i_visible_height;
 
-    fmt_out.i_sar_num =
-    fmt_out.i_sar_den = 0;
-
-    subpicture_region_t *p_region = subpicture_region_ForPicture( &fmt_out, p_pip );
+    subpicture_region_t *p_region = subpicture_region_ForPicture( NULL, p_pip );
     picture_Release( p_pip );
 
     if (likely(p_region == NULL))
@@ -159,6 +156,10 @@ subpicture_t *subpicture_NewFromPicture( vlc_object_t *p_obj,
         return NULL;
     }
 
+    p_region->fmt.i_sar_num =
+    p_region->fmt.i_sar_den = 0;
+
+
     vlc_spu_regions_push( &p_subpic->regions, p_region );
     return p_subpic;
 }
@@ -278,13 +279,17 @@ subpicture_region_t *subpicture_region_NewText( void )
 
 subpicture_region_t *subpicture_region_ForPicture( const video_format_t *p_fmt, picture_t *pic )
 {
-    if ( !video_format_IsSameChroma( p_fmt, &pic->format ) )
+    assert( !p_fmt || video_format_IsSameChroma( p_fmt, &pic->format ) );
+    if ( p_fmt && !video_format_IsSameChroma( p_fmt, &pic->format ) )
         return NULL;
 
     subpicture_region_t *p_region = subpicture_region_NewInternal( );
     if( !p_region )
         return NULL;
 
+    if (p_fmt == NULL)
+        p_fmt = &pic->format;
+
     video_format_Copy( &p_region->fmt, p_fmt );
     if ( p_fmt->i_chroma == VLC_CODEC_YUVP || p_fmt->i_chroma == VLC_CODEC_RGBP )
     {


=====================================
src/video_output/vout_spuregion_helper.h
=====================================
@@ -84,7 +84,7 @@ spuregion_CreateFromPicture( vlc_object_t *p_this, video_format_t *p_fmt,
     if(!p_pic)
         return NULL;
 
-    subpicture_region_t *region = subpicture_region_ForPicture(p_fmt, p_pic);
+    subpicture_region_t *region = subpicture_region_ForPicture(NULL, p_pic);
     picture_Release( p_pic );
 
     return region;


=====================================
src/video_output/vout_subpictures.c
=====================================
@@ -983,7 +983,7 @@ static subpicture_region_t *SpuRenderRegion(spu_t *spu,
 
     bool convert_chroma = true;
     for (int i = 0; chroma_list[i] && convert_chroma; i++) {
-        if (region_fmt.i_chroma == chroma_list[i])
+        if (region->fmt.i_chroma == chroma_list[i])
             convert_chroma = false;
     }
 
@@ -1145,7 +1145,6 @@ static subpicture_region_t *SpuRenderRegion(spu_t *spu,
         }
     }
 
-    assert(video_format_IsSameChroma( &region_fmt, &region_picture->format ));
     subpicture_region_t *dst = subpicture_region_ForPicture(&region_fmt, region_picture);
     if (dst == NULL)
         return NULL;


=====================================
test/modules/video_output/opengl/sub_renderer.c
=====================================
@@ -178,7 +178,7 @@ static void test_opengl_offscreen(
     subpicture->i_original_picture_width = 4;
     subpicture->i_original_picture_height = 4;
 
-    subpicture_region_t *p_region = subpicture_region_ForPicture(&fmt, picture);
+    subpicture_region_t *p_region = subpicture_region_ForPicture(NULL, picture);
     assert(p_region != NULL);
     vlc_spu_regions_push( &subpicture->regions, p_region );
 



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/70c643090bac6ba5c27f0cb4a68959bc8fb04380...37bd13516a6a6833b54cabb0e04bd6721cbd78c6

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/70c643090bac6ba5c27f0cb4a68959bc8fb04380...37bd13516a6a6833b54cabb0e04bd6721cbd78c6
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