From 26e66694fad4f3ec1afba2f2c1de3c66c6d3d7ac Mon Sep 17 00:00:00 2001 From: Konstantin Ritt Date: Sun, 8 Nov 2015 11:44:57 +0400 Subject: [PATCH] QFontEngineFT: Minor optimization to convertGRAYToARGB() Precalculate everything we can and use faster loop. Make inlined as it is used just in a single place. Change-Id: If3c33d60739eb4ce896020321442ae81edd1c13d Reviewed-by: Friedemann Kleint Reviewed-by: Lars Knoll --- src/gui/text/qfontengine_ft.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/gui/text/qfontengine_ft.cpp b/src/gui/text/qfontengine_ft.cpp index 0d28785aa1..162f409acd 100644 --- a/src/gui/text/qfontengine_ft.cpp +++ b/src/gui/text/qfontengine_ft.cpp @@ -590,13 +590,16 @@ static void convertRGBToARGB_V(const uchar *src, uint *dst, int width, int heigh } } -static void convertGRAYToARGB(const uchar *src, uint *dst, int width, int height, int src_pitch) { - for (int y = 0; y < height; ++y) { - int readpos = (y * src_pitch); - int writepos = (y * width); - for (int x = 0; x < width; ++x) { - dst[writepos + x] = (0xFF << 24) + (src[readpos + x] << 16) + (src[readpos + x] << 8) + src[readpos + x]; +static inline void convertGRAYToARGB(const uchar *src, uint *dst, int width, int height, int src_pitch) +{ + while (height--) { + const uchar *p = src; + const uchar * const e = p + width; + while (p < e) { + uchar gray = *p++; + *dst++ = (0xFF << 24) | (gray << 16) | (gray << 8) | gray; } + src += src_pitch; } }