From f65c85c004b6413d30fb438f3874f706f4d8ed9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20H=C3=A4nel?= Date: Fri, 28 Sep 2012 15:00:48 +0200 Subject: FreeType bitmaps interpreted in wrong format We ask grayscale or mono bitmaps from FreeType but in some cases treat the output as ARGB without conversion. This surfaces using QGLWidget as a viewport to QDeclarative content. The offending glyphs are then generated through QTextureGlyphCache::textureMapForGlyph. This adds a fix for converting to the expected ARGB32 data. Change-Id: Ia219582ebd76b7e4e9379111a42312b4d97718de Reviewed-by: Eskil Abrahamsen Blomfeldt Reviewed-by: Frederik Gladhorn --- src/gui/text/qfontengine_ft.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/gui') diff --git a/src/gui/text/qfontengine_ft.cpp b/src/gui/text/qfontengine_ft.cpp index fe72df64bd..af458c11a2 100644 --- a/src/gui/text/qfontengine_ft.cpp +++ b/src/gui/text/qfontengine_ft.cpp @@ -588,6 +588,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 void convoluteBitmap(const uchar *src, uchar *dst, int width, int height, int pitch) { // convolute the bitmap with a triangle filter to get rid of color fringes @@ -1016,7 +1026,7 @@ QFontEngineFT::Glyph *QFontEngineFT::loadGlyph(QGlyphSet *set, uint glyph, bitmap.rows = info.height*vfactor; bitmap.width = hpixels; bitmap.pitch = format == Format_Mono ? (((info.width + 31) & ~31) >> 3) : ((bitmap.width + 3) & ~3); - if (!hsubpixel && vfactor == 1) + if (!hsubpixel && vfactor == 1 && format != Format_A32) bitmap.buffer = glyph_buffer; else bitmap.buffer = new uchar[bitmap.rows*bitmap.pitch]; @@ -1047,6 +1057,8 @@ QFontEngineFT::Glyph *QFontEngineFT::loadGlyph(QGlyphSet *set, uint glyph, delete [] convoluted; } else if (vfactor != 1) { convertRGBToARGB_V(bitmap.buffer, (uint *)glyph_buffer, info.width, info.height, bitmap.pitch, subpixelType != QFontEngineFT::Subpixel_VRGB, true); + } else if (format == Format_A32 && bitmap.pixel_mode == FT_PIXEL_MODE_GRAY) { + convertGRAYToARGB(bitmap.buffer, (uint *)glyph_buffer, info.width, info.height, bitmap.pitch); } if (bitmap.buffer != glyph_buffer) -- cgit v1.2.3