1
0
mirror of https://github.com/VDR4Arch/vdr.git synced 2023-10-10 13:36:52 +02:00

Speeded up anti-aliased font rendering by caching the blend indexes

This commit is contained in:
Klaus Schmidinger 2008-02-09 11:52:25 +01:00
parent dc23636d62
commit 197d6a9c85
3 changed files with 20 additions and 7 deletions

View File

@ -1782,6 +1782,7 @@ Martin Wache <M.Wache@gmx.net>
for adding a sleep in cDvbPlayer::Action() in case there is no data to send to the for adding a sleep in cDvbPlayer::Action() in case there is no data to send to the
device, which avoids a busy loop on very fast machines device, which avoids a busy loop on very fast machines
for fixing a possible crash when loading an invalid XPM file for fixing a possible crash when loading an invalid XPM file
for suggesting to speed up anti-aliased font rendering by caching the blend indexes
Matthias Lenk <matthias.lenk@amd.com> Matthias Lenk <matthias.lenk@amd.com>
for reporting an out-of-bounds memory access with audio language ids for reporting an out-of-bounds memory access with audio language ids

View File

@ -5579,7 +5579,7 @@ Video Disk Recorder Revision History
is not available, in order to allow staying on an encrypted channel that takes is not available, in order to allow staying on an encrypted channel that takes
a while for the CAM to start decrypting. a while for the CAM to start decrypting.
2008-02-08: Version 1.5.15 2008-02-09: Version 1.5.15
- Updated the Italian OSD texts (thanks to Diego Pierotto). - Updated the Italian OSD texts (thanks to Diego Pierotto).
- Added option -i to the pictures plugin's pic2mpg to ignore unknown file types. - Added option -i to the pictures plugin's pic2mpg to ignore unknown file types.
@ -5591,3 +5591,5 @@ Video Disk Recorder Revision History
file if you have already used version 1.5.14, because it introduced new parameters. file if you have already used version 1.5.14, because it introduced new parameters.
- Added the new command line option --userdump to enable core dumps in case VDR - Added the new command line option --userdump to enable core dumps in case VDR
is run as root with option -u (thanks to Hans-Werner Hilse). is run as root with option -u (thanks to Hans-Werner Hilse).
- Speeded up anti-aliased font rendering by caching the blend indexes (based on
a suggestion by Martin Wache).

22
font.c
View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: font.c 1.22 2007/11/04 11:08:12 kls Exp $ * $Id: font.c 1.23 2008/02/09 11:52:25 kls Exp $
*/ */
#include "font.h" #include "font.h"
@ -241,10 +241,16 @@ int cFreetypeFont::Width(const char *s) const
return w; return w;
} }
#define MAX_BLEND_LEVELS 256
void cFreetypeFont::DrawText(cBitmap *Bitmap, int x, int y, const char *s, tColor ColorFg, tColor ColorBg, int Width) const void cFreetypeFont::DrawText(cBitmap *Bitmap, int x, int y, const char *s, tColor ColorFg, tColor ColorBg, int Width) const
{ {
if (s && height) { // checking height to make sure we actually have a valid font if (s && height) { // checking height to make sure we actually have a valid font
bool AntiAliased = Setup.AntiAlias && Bitmap->Bpp() >= 8; bool AntiAliased = Setup.AntiAlias && Bitmap->Bpp() >= 8;
bool TransparentBackground = ColorBg == clrTransparent;
int16_t BlendLevelIndex[MAX_BLEND_LEVELS]; // tIndex is 8 bit unsigned, so a negative value can be used to mark unused entries
if (AntiAliased && !TransparentBackground)
memset(BlendLevelIndex, 0xFF, sizeof(BlendLevelIndex)); // initializes the array with negative values
tIndex fg = Bitmap->Index(ColorFg); tIndex fg = Bitmap->Index(ColorFg);
uint prevSym = 0; uint prevSym = 0;
while (*s) { while (*s) {
@ -266,12 +272,16 @@ void cFreetypeFont::DrawText(cBitmap *Bitmap, int x, int y, const char *s, tColo
if (bt > 0x00) { if (bt > 0x00) {
int px = x + pitch + g->Left() + kerning; int px = x + pitch + g->Left() + kerning;
int py = y + row + (height - Bottom() - g->Top()); int py = y + row + (height - Bottom() - g->Top());
tColor bg;
if (bt == 0xFF) if (bt == 0xFF)
Bitmap->SetIndex(px, py, fg); bg = fg;
else { else if (TransparentBackground)
tColor bg = (ColorBg != clrTransparent) ? ColorBg : Bitmap->GetColor(px, py); bg = Bitmap->Index(Bitmap->Blend(ColorFg, Bitmap->GetColor(px, py), bt));
Bitmap->SetIndex(px, py, Bitmap->Index(Bitmap->Blend(ColorFg, bg, bt))); else if (BlendLevelIndex[bt] >= 0)
} bg = BlendLevelIndex[bt];
else
bg = BlendLevelIndex[bt] = Bitmap->Index(Bitmap->Blend(ColorFg, ColorBg, bt));
Bitmap->SetIndex(px, py, bg);
} }
} }
else { //monochrome rendering else { //monochrome rendering