mirror of
https://github.com/love2d/love.git
synced 2026-08-16 00:02:12 +02:00
Reduced the RAM and VRAM space taken up by TrueType font glyphs by 1/2.
This commit is contained in:
@@ -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},
|
||||
};
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user