[vlc-commits] [Git][videolan/vlc][master] 5 commits: freetype2: fix palette filling in YUVP

Steve Lhomme (@robUx4) gitlab at videolan.org
Thu Nov 16 09:10:46 UTC 2023



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
b81bc695 by Steve Lhomme at 2023-11-16T08:26:08+00:00
freetype2: fix palette filling in YUVP

Since fe415420f3ace0b91636884626ff1ddd6ef8c360 the palette set in the local
format is not set on the output region format.

The palette of the region is created in subpicture_region_New() and the
same pointer is used between the region format and the picture format.

- - - - -
451830aa by Steve Lhomme at 2023-11-16T08:26:08+00:00
freetype: remove extra 4 pixels for YUVP rendering

It should use the same size as the non-palletized formats, i.e. the
size used in RenderAXYZ().

It was added in 2479a41d194aa04f855a14ad79d66d94878b591f.

- - - - -
83e18622 by Steve Lhomme at 2023-11-16T08:26:08+00:00
freetype: create the output region outside of rendering functions

The rendering cannot fail. The error handling only needs to be done in one
place.

- - - - -
682bb69f by Steve Lhomme at 2023-11-16T08:26:08+00:00
freetype: reduce indentation

- - - - -
54897d1e by Steve Lhomme at 2023-11-16T08:26:08+00:00
text_renderer: warn when the rendering cannot be done

Due to requested chromas not being supported.

- - - - -


2 changed files:

- modules/text_renderer/freetype/freetype.c
- modules/text_renderer/svg.c


Changes:

=====================================
modules/text_renderer/freetype/freetype.c
=====================================
@@ -342,7 +342,8 @@ error:
  *****************************************************************************
  * This function merges the previously rendered freetype glyphs into a picture
  *****************************************************************************/
-static subpicture_region_t *RenderYUVP( const subpicture_region_t *p_region_in,
+static void RenderYUVP( const subpicture_region_t *p_region_in,
+                       subpicture_region_t *p_region,
                        const line_desc_t *p_line,
                        const FT_BBox *p_regionbbox,
                        const FT_BBox *p_bbox )
@@ -352,50 +353,30 @@ static subpicture_region_t *RenderYUVP( const subpicture_region_t *p_region_in,
           0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
 
     uint8_t *p_dst;
-    video_format_t fmt;
     int i, i_pitch;
     unsigned int x, y;
     uint8_t i_y, i_u, i_v; /* YUV values, derived from incoming RGB */
 
-    /* Create a new subpicture region */
-    video_format_Init( &fmt, VLC_CODEC_YUVP );
-    fmt.i_width          =
-    fmt.i_visible_width  = p_regionbbox->xMax - p_regionbbox->xMin + 4;
-    fmt.i_height         =
-    fmt.i_visible_height = p_regionbbox->yMax - p_regionbbox->yMin + 4;
-    fmt.i_sar_num = fmt.i_sar_den = 1;
-    fmt.transfer  = p_region_in->fmt.transfer;
-    fmt.primaries = p_region_in->fmt.primaries;
-    fmt.space     = p_region_in->fmt.space;
-    fmt.mastering = p_region_in->fmt.mastering;
-
-    subpicture_region_t *p_region = subpicture_region_New(&fmt);
-    if (unlikely(p_region == NULL))
-        return NULL;
-
-    p_region->fmt.i_sar_num = p_region_in->fmt.i_sar_num;
-    p_region->fmt.i_sar_den = p_region_in->fmt.i_sar_den;
-
     /* Calculate text color components
      * Only use the first color */
     const int i_alpha = p_line->p_character[0].p_style->i_font_alpha;
     YUVFromXRGB( p_line->p_character[0].p_style->i_font_color, &i_y, &i_u, &i_v );
 
     /* Build palette */
-    fmt.p_palette->i_entries = 16;
+    p_region->fmt.p_palette->i_entries = 16;
     for( i = 0; i < 8; i++ )
     {
-        fmt.p_palette->palette[i][0] = 0;
-        fmt.p_palette->palette[i][1] = 0x80;
-        fmt.p_palette->palette[i][2] = 0x80;
-        fmt.p_palette->palette[i][3] = (int)pi_gamma[i] * i_alpha / 255;
+        p_region->fmt.p_palette->palette[i][0] = 0;
+        p_region->fmt.p_palette->palette[i][1] = 0x80;
+        p_region->fmt.p_palette->palette[i][2] = 0x80;
+        p_region->fmt.p_palette->palette[i][3] = (int)pi_gamma[i] * i_alpha / 255;
     }
-    for( i = 8; i < fmt.p_palette->i_entries; i++ )
+    for( i = 8; i < p_region->fmt.p_palette->i_entries; i++ )
     {
-        fmt.p_palette->palette[i][0] = i * 16 * i_y / 256;
-        fmt.p_palette->palette[i][1] = i_u;
-        fmt.p_palette->palette[i][2] = i_v;
-        fmt.p_palette->palette[i][3] = (int)pi_gamma[i] * i_alpha / 255;
+        p_region->fmt.p_palette->palette[i][0] = i * 16 * i_y / 256;
+        p_region->fmt.p_palette->palette[i][1] = i_u;
+        p_region->fmt.p_palette->palette[i][2] = i_v;
+        p_region->fmt.p_palette->palette[i][3] = (int)pi_gamma[i] * i_alpha / 255;
     }
 
     p_dst = p_region->p_picture->Y_PIXELS;
@@ -435,13 +416,13 @@ static subpicture_region_t *RenderYUVP( const subpicture_region_t *p_region_in,
         uint8_t *p_top = p_dst; /* Use 1st line as a cache */
         uint8_t left, current;
 
-        for( y = 1; y < fmt.i_height - 1; y++ )
+        for( y = 1; y < p_region->fmt.i_height - 1; y++ )
         {
-            if( y > 1 ) memcpy( p_top, p_dst, fmt.i_width );
+            if( y > 1 ) memcpy( p_top, p_dst, p_region->fmt.i_width );
             p_dst += p_region->p_picture->Y_PITCH;
             left = 0;
 
-            for( x = 1; x < fmt.i_width - 1; x++ )
+            for( x = 1; x < p_region->fmt.i_width - 1; x++ )
             {
                 current = p_dst[x];
                 p_dst[x] = ( 8 * (int)p_dst[x] + left + p_dst[x+1] + p_top[x -1]+ p_top[x] + p_top[x+1] +
@@ -449,10 +430,8 @@ static subpicture_region_t *RenderYUVP( const subpicture_region_t *p_region_in,
                 left = current;
             }
         }
-        memset( p_top, 0, fmt.i_width );
+        memset( p_top, 0, p_region->fmt.i_width );
     }
-
-    return p_region;
 }
 
 /*****************************************************************************
@@ -630,8 +609,9 @@ static void RenderCharAXYZ( filter_t *p_filter,
     }
 }
 
-static inline subpicture_region_t *RenderAXYZ( filter_t *p_filter,
+static inline void RenderAXYZ( filter_t *p_filter,
                               const subpicture_region_t *p_region_in,
+                              subpicture_region_t *p_region,
                               const line_desc_t *p_line_head,
                               const FT_BBox *p_regionbbox,
                               const FT_BBox *p_paddedtextbbox,
@@ -641,28 +621,8 @@ static inline subpicture_region_t *RenderAXYZ( filter_t *p_filter,
 {
     filter_sys_t *p_sys = p_filter->p_sys;
 
-    /* Create a new subpicture region */
-    video_format_t fmt;
-    video_format_Init( &fmt, i_chroma );
-    fmt.i_width          =
-    fmt.i_visible_width  = p_regionbbox->xMax - p_regionbbox->xMin;
-    fmt.i_height         =
-    fmt.i_visible_height = p_regionbbox->yMax - p_regionbbox->yMin;
-    fmt.i_sar_num = fmt.i_sar_den = 1;
-    fmt.transfer  = p_region_in->fmt.transfer;
-    fmt.primaries = p_region_in->fmt.primaries;
-    fmt.space     = p_region_in->fmt.space;
-    fmt.mastering = p_region_in->fmt.mastering;
-
-    subpicture_region_t *p_region = subpicture_region_New(&fmt);
-    if (unlikely(p_region == NULL))
-        return NULL;
-
     picture_t *p_picture = p_region->p_picture;
 
-    p_region->fmt.i_sar_num = p_region_in->fmt.i_sar_num;
-    p_region->fmt.i_sar_den = p_region_in->fmt.i_sar_den;
-
     /* Initialize the picture background */
     const text_style_t *p_style = p_sys->p_default_style;
     uint8_t i_x, i_y, i_z;
@@ -670,12 +630,12 @@ static inline subpicture_region_t *RenderAXYZ( filter_t *p_filter,
     if (p_region_in->text_flags & VLC_SUBPIC_TEXT_FLAG_NO_REGION_BG) {
         /* Render the background just under the text */
         draw->fill( p_picture, STYLE_ALPHA_TRANSPARENT, 0x00, 0x00, 0x00,
-                   0, 0, fmt.i_visible_width, fmt.i_visible_height );
+                   0, 0, p_region->fmt.i_visible_width, p_region->fmt.i_visible_height );
     } else {
         /* Render background under entire subpicture block */
         draw->extract( p_style->i_background_color, &i_x, &i_y, &i_z );
         draw->fill( p_picture, p_style->i_background_alpha, i_x, i_y, i_z,
-                   0, 0, fmt.i_visible_width, fmt.i_visible_height );
+                   0, 0, p_region->fmt.i_visible_width, p_region->fmt.i_visible_height );
     }
 
     /* Render text's background (from decoder) if any */
@@ -699,8 +659,6 @@ static inline subpicture_region_t *RenderAXYZ( filter_t *p_filter,
                             draw );
         }
     }
-
-    return p_region;
 }
 
 static void UpdateDefaultLiveStyles( filter_t *p_filter )
@@ -1055,21 +1013,21 @@ static subpicture_region_t *Render( filter_t *p_filter,
     FT_BBox regionbbox = paddedbbox;
 
     /* _______regionbbox_______________
-        * |                               |
-        * |                               |
-        * |                               |
-        * |     _bbox(<paddedbbox)___     |
-        * |    |         rightaligned|    |
-        * |    |            textlines|    |
-        * |    |_____________________|    |
-        * |_______________________________|
-        *
-        * we need at least 3 bounding boxes.
-        * regionbbox containing the whole, including region background pixels
-        * paddedbox an enlarged text box when for drawing text background
-        * bbox the lines bounding box for all glyphs
-        * For simple unstyled subs, bbox == paddedbox == regionbbox
-        */
+     * |                               |
+     * |                               |
+     * |                               |
+     * |     _bbox(<paddedbbox)___     |
+     * |    |         rightaligned|    |
+     * |    |            textlines|    |
+     * |    |_____________________|    |
+     * |_______________________________|
+     *
+     * we need at least 3 bounding boxes.
+     * regionbbox containing the whole, including region background pixels
+     * paddedbox an enlarged text box when for drawing text background
+     * bbox the lines bounding box for all glyphs
+     * For simple unstyled subs, bbox == paddedbox == regionbbox
+     */
 
     unsigned outertext_w = (regionbbox.xMax - regionbbox.xMin);
     if( outertext_w < (unsigned) p_region_in->i_max_width )
@@ -1110,10 +1068,31 @@ static subpicture_region_t *Render( filter_t *p_filter,
         regionbbox = paddedbbox;
     }
 
+    video_format_t fmt;
+    video_format_Init( &fmt, 0 );
+    fmt.i_width          =
+    fmt.i_visible_width  = regionbbox.xMax - regionbbox.xMin;
+    fmt.i_height         =
+    fmt.i_visible_height = regionbbox.yMax - regionbbox.yMin;
+    fmt.i_sar_num = fmt.i_sar_den = 1;
+    fmt.transfer  = p_region_in->fmt.transfer;
+    fmt.primaries = p_region_in->fmt.primaries;
+    fmt.space     = p_region_in->fmt.space;
+    fmt.mastering = p_region_in->fmt.mastering;
+
     for( const vlc_fourcc_t *p_chroma = p_chroma_list; *p_chroma != 0; p_chroma++ )
     {
+        /* Create a new subpicture region */
+        fmt.i_chroma = *p_chroma;
+        region = subpicture_region_New(&fmt);
+        if (unlikely(region == NULL))
+            continue;
+
+        region->fmt.i_sar_num = p_region_in->fmt.i_sar_num;
+        region->fmt.i_sar_den = p_region_in->fmt.i_sar_den;
+
         if( *p_chroma == VLC_CODEC_YUVP )
-            region = RenderYUVP( p_region_in, text_block.p_laid,
+            RenderYUVP( p_region_in, region, text_block.p_laid,
                                 &regionbbox, &bbox );
         else
         {
@@ -1145,35 +1124,39 @@ static subpicture_region_t *Render( filter_t *p_filter,
                 func = &DRAW_ARGB;
             }
             else
+            {
+                subpicture_region_Delete(region);
+                region = NULL;
                 continue;
+            }
 
-            region = RenderAXYZ( p_filter, p_region_in, text_block.p_laid,
+            RenderAXYZ( p_filter, p_region_in, region, text_block.p_laid,
                                  &regionbbox, &paddedbbox, &bbox,
                                  *p_chroma,
                                  func );
         }
 
-        if( region != NULL )
+        /* Avoid useless pixels:
+         *        reshrink/trim Region Box to padded text one,
+         *        but update offsets to keep position and have same rendering */
+//      if( (bboxcolor & 0xFF) == 0 )
         {
-            /* Avoid useless pixels:
-                *        reshrink/trim Region Box to padded text one,
-                *        but update offsets to keep position and have same rendering */
-//          if( (bboxcolor & 0xFF) == 0 )
-            {
-                region->i_x = (paddedbbox.xMin - regionbbox.xMin) + p_region_in->i_x;
-                region->i_y = (regionbbox.yMax - paddedbbox.yMax) + p_region_in->i_y;
-            }
-//          else /* case where the bounding box is larger and visible */
-//          {
-//              region->i_x = p_region_in->i_x;
-//              region->i_y = p_region_in->i_y;
-//          }
-            region->i_alpha = p_region_in->i_alpha;
-            region->i_align = p_region_in->i_align;
-            break;
+            region->i_x = (paddedbbox.xMin - regionbbox.xMin) + p_region_in->i_x;
+            region->i_y = (regionbbox.yMax - paddedbbox.yMax) + p_region_in->i_y;
         }
+//      else /* case where the bounding box is larger and visible */
+//      {
+//          region->i_x = p_region_in->i_x;
+//          region->i_y = p_region_in->i_y;
+//      }
+        region->i_alpha = p_region_in->i_alpha;
+        region->i_align = p_region_in->i_align;
+        break;
     }
 
+    if (region == NULL)
+        msg_Warn( p_filter, "no output chroma supported for rendering" );
+
 done:
     FreeLines( text_block.p_laid );
 


=====================================
modules/text_renderer/svg.c
=====================================
@@ -337,7 +337,10 @@ static subpicture_region_t *RenderText( filter_t *p_filter,
         if( p_chroma_list[i] == VLC_CODEC_BGRA )
             break;
         if( p_chroma_list[i] == 0 )
+        {
+            msg_Warn( p_filter, "no output chroma supported for rendering" );
             return NULL;
+        }
     }
 
     unsigned i_width = p_filter->fmt_out.video.i_visible_width;



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/e70650037ef8c8becfca73f7182512122efa6255...54897d1ebfd22ccae2faa78a13aa706ab693e731

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/e70650037ef8c8becfca73f7182512122efa6255...54897d1ebfd22ccae2faa78a13aa706ab693e731
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