[vlc-commits] FreeType: optimize FillARGB() a little

Rémi Denis-Courmont git at videolan.org
Sat Nov 9 15:32:26 CET 2013


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Nov  9 16:31:35 2013 +0200| [f4d4293230d248566f4aa5870786c9543e7377ef] | committer: Rémi Denis-Courmont

FreeType: optimize FillARGB() a little

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

 modules/text_renderer/freetype.c |   25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/modules/text_renderer/freetype.c b/modules/text_renderer/freetype.c
index 989ea58..2870aa3 100644
--- a/modules/text_renderer/freetype.c
+++ b/modules/text_renderer/freetype.c
@@ -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;
     }
 }
 



More information about the vlc-commits mailing list