Cache the transparent colour instead of calling a function for every pixel.

svn-id: r42192
This commit is contained in:
Denis Kasak 2009-07-06 19:41:13 +00:00
parent b2c24dd640
commit 61fa4d27d5
2 changed files with 6 additions and 2 deletions

View File

@ -162,6 +162,8 @@ void Font::drawChar(Surface *dst, uint8 chr, int tx, int ty, bool markDirty) con
int ySpaceLeft = dst->h - ty - 1;
int yPixelsToDraw = (_fontHeight < ySpaceLeft) ? _fontHeight : ySpaceLeft;
int _transparent = dst->getTransparentColour();
for (int y = 0; y < yPixelsToDraw; ++y) {
for (int x = 0; x <= xPixelsToDraw; ++x) {
@ -189,7 +191,7 @@ void Font::drawChar(Surface *dst, uint8 chr, int tx, int ty, bool markDirty) con
}
// Paint pixel (if not transparent)
if (colour != dst->getTransparentColour())
if (colour != _transparent)
ptr[x] = colour;
}

View File

@ -142,12 +142,14 @@ void Sprite::draw(Surface *surface, bool markDirty) const {
byte *dst = (byte *)surface->getBasePtr(clippedDestRect.left, clippedDestRect.top);
byte *src = _data;
int _transparent = surface->getTransparentColour();
// Blit the sprite to the surface
for (int i = sourceRect.top; i < sourceRect.bottom; ++i) {
for (int j = sourceRect.left; j < sourceRect.right; ++j) {
// Don't blit if the pixel is transparent on the target surface
if (src[i * _width + j] != surface->getTransparentColour()) {
if (src[i * _width + j] != _transparent) {
// Draw the sprite mirrored if the _mirror flag is set
if (_mirror) {