[vlc-commits] [Git][videolan/vlc][master] 3 commits: ttml: scale png subtitles according to tss:extent

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Sun May 7 14:54:29 UTC 2023



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
52c6ec46 by Dmitriy Matveichev at 2023-05-07T14:42:18+00:00
ttml: scale png subtitles according to tss:extent

- - - - -
9b9483ab by Dmitriy Matveichev at 2023-05-07T14:42:18+00:00
ttml: process correct tss:extent values in pixels only

- - - - -
7efd8ab5 by Dmitriy Matveichev at 2023-05-07T14:42:18+00:00
ttml: process correct tss:extent values in percents

- - - - -


1 changed file:

- modules/codec/ttml/substtml.c


Changes:

=====================================
modules/codec/ttml/substtml.c
=====================================
@@ -1154,13 +1154,64 @@ static void TTMLRegionsToSpuTextRegions( decoder_t *p_dec, subpicture_t *p_spu,
     }
 }
 
+static bool isValidPixelsExtent( int flags, float extent_x, float extent_y )
+{
+    return !( flags & UPDT_REGION_EXTENT_X_IS_RATIO ) && !( flags & UPDT_REGION_EXTENT_Y_IS_RATIO )
+        && extent_x > 0 && extent_y > 0;
+}
+
+static bool isValidPercentsExtent( int flags, float extent_x, float extent_y )
+{
+    return ( flags & UPDT_REGION_EXTENT_X_IS_RATIO ) && ( flags & UPDT_REGION_EXTENT_Y_IS_RATIO )
+        && extent_x > 0 && extent_y > 0;
+}
+
+static void setPixelsWidthAndHeight( video_format_t* fmt, float extent_x, float extent_y )
+{
+    fmt->i_width = extent_x;
+    fmt->i_visible_width = extent_x;
+
+    fmt->i_height = extent_y;
+    fmt->i_visible_height = extent_y;
+}
+
+static void setPercentsWidthAndHeight( video_format_t* fmt, float extent_x, float extent_y )
+{
+    fmt->i_width = extent_x * fmt->i_width;
+    fmt->i_visible_width = fmt->i_width;
+
+    fmt->i_height = extent_y * fmt->i_height;
+    fmt->i_visible_height = fmt->i_height;
+}
+
+static picture_t * rescalePicture( image_handler_t *p_image, picture_t *p_picture, float extent_x, float extent_y )
+{
+    video_format_t fmt_out;
+    video_format_Copy( &fmt_out, &p_picture->format );
+    setPercentsWidthAndHeight( &fmt_out, extent_x, extent_y );
+
+    picture_t *p_scaled_picture = image_Convert( p_image, p_picture,  &p_picture->format, &fmt_out );
+
+    video_format_Clean( &fmt_out );
+
+    return p_scaled_picture;
+}
+
 static picture_t * picture_CreateFromPNG( decoder_t *p_dec,
-                                          const uint8_t *p_data, size_t i_data )
+                                          const uint8_t *p_data, size_t i_data,
+                                          int flags, float extent_x, float extent_y )
 {
     if( i_data < 16 )
         return NULL;
+        
     video_format_t fmt_out;
     video_format_Init( &fmt_out, VLC_CODEC_YUVA );
+    
+    if ( isValidPixelsExtent( flags, extent_x, extent_y ) )
+    {
+        setPixelsWidthAndHeight( &fmt_out, extent_x, extent_y );
+    }
+    
     es_format_t es_in;
     es_format_Init( &es_in, VIDEO_ES, VLC_CODEC_PNG );
     es_in.video.i_chroma = es_in.i_codec;
@@ -1179,6 +1230,18 @@ static picture_t * picture_CreateFromPNG( decoder_t *p_dec,
     if( p_image )
     {
         p_pic = image_Read( p_image, p_block, &es_in, &fmt_out );
+        
+        if ( p_pic && isValidPercentsExtent( flags, extent_x, extent_y ) )
+        {
+            picture_t *p_scaled_pic = rescalePicture( p_image, p_pic, extent_x, extent_y );
+
+            if ( p_scaled_pic )
+            {
+                picture_Release( p_pic );
+                p_pic = p_scaled_pic;
+            }
+        }
+        
         image_HandlerDelete( p_image );
     }
     else block_Release( p_block );
@@ -1198,7 +1261,10 @@ static void TTMLRegionsToSpuBitmapRegions( decoder_t *p_dec, subpicture_t *p_spu
                         p_region; p_region = (ttml_region_t *) p_region->updt.p_next )
     {
         picture_t *p_pic = picture_CreateFromPNG( p_dec, p_region->bgbitmap.p_bytes,
-                                                         p_region->bgbitmap.i_bytes );
+                                                         p_region->bgbitmap.i_bytes,
+                                                         p_region->updt.flags,
+                                                         p_region->updt.extent.x,
+                                                         p_region->updt.extent.y );
         if( p_pic )
         {
             ttml_image_updater_region_t *r = TTML_ImageUpdaterRegionNew( p_pic );



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/9d4e884c7452f1919dfc1d264c683778cc60d630...7efd8ab523fad1fa05da1c77e2b9ed578a76a146

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/9d4e884c7452f1919dfc1d264c683778cc60d630...7efd8ab523fad1fa05da1c77e2b9ed578a76a146
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