FreeType: optimize FillARGB() a little
authorRémi Denis-Courmont <remi@remlab.net>
Sat, 9 Nov 2013 14:31:35 +0000 (16:31 +0200)
committerRémi Denis-Courmont <remi@remlab.net>
Sat, 9 Nov 2013 14:32:19 +0000 (16:32 +0200)
modules/text_renderer/freetype.c

index 989ea58..2870aa3 100644 (file)
@@ -1008,16 +1008,23 @@ 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++)
+    if (a == 0)
+        r = g = b = 0;
+    if (a == r && a == b && a == g)
+    {   /* fast path */
+        memset(pic->p->p_pixels, a, pic->p->i_visible_lines * pic->p->i_pitch);
+        return;
+    }
+
+    uint_fast32_t pixel = VLC_FOURCC(a, r, g, b);
+    uint8_t *line = pic->p->p_pixels;
+
+    for (unsigned lines = pic->p->i_visible_lines; lines > 0; lines--)
     {
-        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;
-        }
+        uint32_t *pixels = (uint32_t *)line;
+        for (unsigned cols = pic->p->i_visible_pitch; cols > 0; cols -= 4)
+            *(pixels++) = pixel;
+        line += pic->p->i_pitch;
     }
 }