[vlc-commits] freetype: really apply char background

Francois Cartegnie git at videolan.org
Mon Aug 24 22:45:43 CEST 2015


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Sun Aug 23 20:31:37 2015 +0200| [5f7d9a6884dbe3cba58c421d21025cc5f666d275] | committer: Francois Cartegnie

freetype: really apply char background

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=5f7d9a6884dbe3cba58c421d21025cc5f666d275
---

 modules/text_renderer/freetype.c    |   58 +++++++++++++++++++++++------------
 modules/text_renderer/text_layout.c |    3 ++
 modules/text_renderer/text_layout.h |    1 +
 3 files changed, 42 insertions(+), 20 deletions(-)

diff --git a/modules/text_renderer/freetype.c b/modules/text_renderer/freetype.c
index 592bd15..ba8a824 100644
--- a/modules/text_renderer/freetype.c
+++ b/modules/text_renderer/freetype.c
@@ -675,8 +675,6 @@ static inline void RenderBackground( subpicture_region_t *p_region,
     {
         int i_align_left = i_margin;
         int i_align_top = i_margin;
-        int line_start = 0;
-        int line_end = 0;
         unsigned line_top = 0;
         int line_bottom = 0;
         int max_height = 0;
@@ -703,36 +701,56 @@ static inline void RenderBackground( subpicture_region_t *p_region,
         if( p_line->i_first_visible_char_index < 0 )
             continue; /* only spaces */
 
+        /* Compute the upper boundary for the background */
+        line_top = __MAX(0, i_align_top - max_height  + p_bbox->yMax + p_line->i_base_line);
+
+        /* Compute lower boundary for the background */
+        line_bottom =  __MIN(line_top + p_line->i_height, p_region->fmt.i_visible_height);
+
         /* Compute the background for the line (identify leading/trailing space) */
-        line_start = p_line->p_character[p_line->i_first_visible_char_index].p_glyph->left +
-                     i_align_left - p_bbox->xMin;
+        int line_start = p_line->p_character[p_line->i_first_visible_char_index].p_glyph->left +
+                         i_align_left - p_bbox->xMin;
 
         /* Fudge factor to make sure caption background edges are left aligned
            despite variable font width */
         if (line_start < 12)
             line_start = 0;
 
-        /* Find right boundary for bounding box for background */
-        line_end = p_line->p_character[p_line->i_last_visible_char_index].p_glyph->left +
-                   p_line->p_character[p_line->i_last_visible_char_index].p_glyph->bitmap.width +
-                   i_align_left - p_bbox->xMin;
-
         /* Setup color for the background */
-        uint8_t i_x, i_y, i_z;
-        ExtractComponents( 0x000000, &i_x, &i_y, &i_z );
+        uint32_t i_prev_color = p_line->p_character[p_line->i_first_visible_char_index].i_background_color;
 
-        /* Compute the upper boundary for the background */
-        line_top = __MAX(0, i_align_top - max_height  + p_bbox->yMax + p_line->i_base_line);
+        int i_char_index = p_line->i_first_visible_char_index;
+        while( i_char_index <= p_line->i_last_visible_char_index )
+        {
+            /* find last char having the same style */
+            int i_seg_end = i_char_index;
+            while( i_seg_end < p_line->i_last_visible_char_index &&
+                   i_prev_color == p_line->p_character[i_seg_end].i_background_color )
+            {
+                i_seg_end++;
+            }
 
-        /* Compute lower boundary for the background */
-        line_bottom =  __MIN(line_top + p_line->i_height, p_region->fmt.i_visible_height);
+            /* Find right boundary for bounding box for background */
+            int line_end = p_line->p_character[i_seg_end].p_glyph->left +
+                           p_line->p_character[i_seg_end].p_glyph->bitmap.width +
+                           i_align_left - p_bbox->xMin;
 
-        /* Render the actual background */
-        for( int dy = line_top; dy < line_bottom; dy++ )
-        {
-            for( int dx = line_start; dx < line_end; dx++ )
-                BlendPixel( p_picture, dx, dy, 0xff, i_x, i_y, i_z, 0xff );
+            uint8_t i_x, i_y, i_z;
+            ExtractComponents( p_line->p_character[i_char_index].i_background_color, &i_x, &i_y, &i_z );
+            const uint8_t i_alpha = (p_line->p_character[i_char_index].i_background_color >> 24) & 0xFF;
+
+            /* Render the actual background */
+            for( int dy = line_top; dy < line_bottom; dy++ )
+            {
+                for( int dx = line_start; dx < line_end; dx++ )
+                    BlendPixel( p_picture, dx, dy, i_alpha, i_x, i_y, i_z, 0xff );
+            }
+
+            line_start = line_end;
+            i_char_index = i_seg_end + 1;
+            i_prev_color = p_line->p_character->i_background_color;
         }
+
     }
 }
 
diff --git a/modules/text_renderer/text_layout.c b/modules/text_renderer/text_layout.c
index 054d774..b775dfc 100644
--- a/modules/text_renderer/text_layout.c
+++ b/modules/text_renderer/text_layout.c
@@ -1055,6 +1055,9 @@ static int LayoutLine( filter_t *p_filter,
                       : (uint32_t) p_glyph_style->i_font_color
                       | (uint32_t) p_glyph_style->i_font_alpha << 24;
 
+        p_ch->i_background_color = ( uint32_t ) p_glyph_style->i_background_color
+                                 |              p_glyph_style->i_background_alpha << 24;
+
         p_ch->i_line_thickness = i_line_thickness;
         p_ch->i_line_offset = i_line_offset;
 
diff --git a/modules/text_renderer/text_layout.h b/modules/text_renderer/text_layout.h
index f6542ce..d5bbd69 100644
--- a/modules/text_renderer/text_layout.h
+++ b/modules/text_renderer/text_layout.h
@@ -33,6 +33,7 @@ typedef struct
     FT_BitmapGlyph p_outline;
     FT_BitmapGlyph p_shadow;
     uint32_t       i_color;             /* ARGB color */
+    uint32_t       i_background_color;  /* ARGB background color */
     int            i_line_offset;       /* underline/strikethrough offset */
     int            i_line_thickness;    /* underline/strikethrough thickness */
 } line_character_t;



More information about the vlc-commits mailing list