Reduced the RAM and VRAM space taken up by TrueType font glyphs by 1/2.

This commit is contained in:
Alex Szpakowski
2013-12-31 20:15:55 -04:00
parent a00c006c44
commit f3bd944cf5
5 changed files with 15 additions and 21 deletions
+5 -5
View File
@@ -43,8 +43,8 @@ GlyphData::GlyphData(uint32 glyph, GlyphMetrics glyphMetrics, GlyphData::Format
{
switch (f)
{
case GlyphData::FORMAT_LUMINANCE_ALPHA:
data = new unsigned char[metrics.width * metrics.height * 2];
case GlyphData::FORMAT_ALPHA:
data = new unsigned char[metrics.width * metrics.height];
break;
case GlyphData::FORMAT_RGBA:
default:
@@ -68,8 +68,8 @@ int GlyphData::getSize() const
{
switch (format)
{
case GlyphData::FORMAT_LUMINANCE_ALPHA:
return getWidth() * getHeight() * 2;
case GlyphData::FORMAT_ALPHA:
return getWidth() * getHeight();
break;
case GlyphData::FORMAT_RGBA:
default:
@@ -168,7 +168,7 @@ bool GlyphData::getConstant(GlyphData::Format in, const char *&out)
StringMap<GlyphData::Format, GlyphData::FORMAT_MAX_ENUM>::Entry GlyphData::formatEntries[] =
{
{"luminance alpha", GlyphData::FORMAT_LUMINANCE_ALPHA},
{"alpha", GlyphData::FORMAT_ALPHA},
{"rgba", GlyphData::FORMAT_RGBA},
};
+1 -1
View File
@@ -58,7 +58,7 @@ public:
enum Format
{
FORMAT_LUMINANCE_ALPHA,
FORMAT_ALPHA,
FORMAT_RGBA,
FORMAT_MAX_ENUM
};
@@ -86,18 +86,12 @@ GlyphData *TrueTypeRasterizer::getGlyphData(uint32 glyph) const
glyphMetrics.width = bitmap.width;
glyphMetrics.advance = face->glyph->metrics.horiAdvance >> 6;
GlyphData *glyphData = new GlyphData(glyph, glyphMetrics, GlyphData::FORMAT_LUMINANCE_ALPHA);
GlyphData *glyphData = new GlyphData(glyph, glyphMetrics, GlyphData::FORMAT_ALPHA);
int size = bitmap.rows * bitmap.width;
unsigned char *dst = (unsigned char *) glyphData->getData();
// Note that bitmap.buffer contains only luminosity. We copy that single
// value to our luminosity-alpha format.
for (int i = 0; i < size; i++)
{
dst[2*i] = 255;
dst[2*i+1] = bitmap.buffer[i];
}
// We treat the luminance of the FreeType bitmap as alpha in the GlyphData.
memcpy(glyphData->getData(), bitmap.buffer, size);
// Having copied the data over, we can destroy the glyph
FT_Done_Glyph(ftglyph);