]> git.sesse.net Git - vlc/commitdiff
FreeType: add ARGB support
authorRémi Denis-Courmont <remi@remlab.net>
Sat, 9 Nov 2013 14:29:20 +0000 (16:29 +0200)
committerRémi Denis-Courmont <remi@remlab.net>
Sat, 9 Nov 2013 14:32:14 +0000 (16:32 +0200)
modules/text_renderer/freetype.c

index d4269e6dacdc035ec488bfc14ba2d8793e22c91b..989ea58a712c922d821f6621e4c61c81b39cdc6c 100644 (file)
@@ -365,6 +365,7 @@ static void RGBFromRGB( uint32_t i_argb,
     *pi_g = ( i_argb & 0x0000ff00 ) >>  8;
     *pi_b = ( i_argb & 0x000000ff );
 }
+
 /*****************************************************************************
  * Make any TTF/OTF fonts present in the attachments of the media file
  * and store them for later use by the FreeType Engine
@@ -1005,6 +1006,47 @@ static inline void BlendRGBAPixel( picture_t *p_picture,
     }
 }
 
+static void FillARGBPicture(picture_t *pic, int a, int r, int g, int b)
+{
+    for (int dy = 0; dy < pic->p->i_visible_lines; dy++)
+    {
+        for (int dx = 0; dx < pic->p->i_visible_pitch; dx += 4)
+        {
+            uint8_t *rgba = &pic->p->p_pixels[dy * pic->p->i_pitch + dx];
+            rgba[0] = a;
+            rgba[1] = r;
+            rgba[2] = g;
+            rgba[3] = b;
+        }
+    }
+}
+
+static inline void BlendARGBPixel(picture_t *pic, int pic_x, int pic_y,
+                                  int a, int r, int g, int b, int alpha)
+{
+    uint8_t *rgba = &pic->p->p_pixels[pic_y * pic->p->i_pitch + 4 * pic_x];
+    int an = a * alpha / 255;
+    int ao = rgba[3];
+
+    if (ao == 0)
+    {
+        rgba[0] = an;
+        rgba[1] = r;
+        rgba[2] = g;
+        rgba[3] = b;
+    }
+    else
+    {
+        rgba[0] = 255 - (255 - rgba[0]) * (255 - an) / 255;
+        if (rgba[0] != 0)
+        {
+            rgba[1] = (rgba[1] * ao * (255 - an) / 255 + r * an ) / rgba[0];
+            rgba[2] = (rgba[2] * ao * (255 - an) / 255 + g * an ) / rgba[0];
+            rgba[3] = (rgba[3] * ao * (255 - an) / 255 + b * an ) / rgba[0];
+        }
+    }
+}
+
 static inline void BlendAXYZGlyph( picture_t *p_picture,
                                    int i_picture_x, int i_picture_y,
                                    int i_a, int i_x, int i_y, int i_z,
@@ -2092,6 +2134,11 @@ static int RenderCommon( filter_t *p_filter, subpicture_region_t *p_region_out,
                                  RGBFromRGB,
                                  FillRGBAPicture,
                                  BlendRGBAPixel );
+            else if( *p_chroma == VLC_CODEC_ARGB )
+                rv = RenderAXYZ( p_filter, p_region_out, p_lines, &bbox,
+                                 i_margin, *p_chroma, RGBFromRGB,
+                                 FillARGBPicture, BlendARGBPixel );
+
             if( !rv )
                 break;
         }