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 <eskil.abrahamsen-blomfeldt@digia.com>
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@digia.com>
This commit is contained in:
Florian Hänel 2012-09-28 15:00:48 +02:00 committed by The Qt Project
parent 968b117375
commit f65c85c004

View File

@ -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)