[Scummvm-cvs-logs] SF.net SVN: scummvm:[35028] scummvm/trunk/graphics/font.cpp

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Wed Nov 12 23:15:47 CET 2008


Revision: 35028
          http://scummvm.svn.sourceforge.net/scummvm/?rev=35028&view=rev
Author:   fingolfin
Date:     2008-11-12 22:15:47 +0000 (Wed, 12 Nov 2008)

Log Message:
-----------
Further optimized drawCharIntern (on my system, 30% of the time used to draw the GUI is spent in there)

Modified Paths:
--------------
    scummvm/trunk/graphics/font.cpp

Modified: scummvm/trunk/graphics/font.cpp
===================================================================
--- scummvm/trunk/graphics/font.cpp	2008-11-12 21:15:35 UTC (rev 35027)
+++ scummvm/trunk/graphics/font.cpp	2008-11-12 22:15:47 UTC (rev 35028)
@@ -49,21 +49,20 @@
 }
 
 
-template <int bytesPerPixel>
-void drawCharIntern(byte *ptr, uint pitch, const bitmap_t *src, int h, int minX, int maxX, const uint32 color) {
+template <typename PixelType>
+void drawCharIntern(byte *ptr, uint pitch, const bitmap_t *src, int h, int minX, int maxX, const PixelType color) {
 	while (h-- > 0) {
-		const bitmap_t buffer = READ_UINT16(src);
+		bitmap_t buffer = READ_UINT16(src);
 		src++;
 
-		int x = minX;
-		uint mask = 0x8000 >> minX;
-		for (; x < maxX; x++, mask >>= 1) {
-			if ((buffer & mask) != 0) {
-				if (bytesPerPixel == 1)
-					ptr[x] = color;
-				else if (bytesPerPixel == 2)
-					((uint16 *)ptr)[x] = color;
-			}
+		buffer &= ~((1 << (16-maxX)) - 1);
+		buffer <<= minX;
+		PixelType *tmp = (PixelType *)ptr;
+		while (buffer != 0) {
+			if ((buffer & 0x8000) != 0)
+				*tmp = color;
+			tmp++;
+			buffer <<= 1;
 		}
 		
 		ptr += pitch;
@@ -73,7 +72,7 @@
 void NewFont::drawChar(Surface *dst, byte chr, const int tx, const int ty, const uint32 color) const {
 	assert(dst != 0);
 
-	assert(desc.bits != 0 && desc.maxwidth <= 17);
+	assert(desc.bits != 0 && desc.maxwidth <= 16);
 	assert(dst->bytesPerPixel == 1 || dst->bytesPerPixel == 2);
 
 	// If this character is not included in the font, use the default char.
@@ -107,9 +106,9 @@
 	y -= MAX(0, ty + desc.ascent - bby - dst->h);
 
 	if (dst->bytesPerPixel == 1)
-		drawCharIntern<1>(ptr, dst->pitch, tmp, y, MAX(0, -(tx + bbx)), MIN(bbw, dst->w - tx - bbx), color);
+		drawCharIntern<byte>(ptr, dst->pitch, tmp, y, MAX(0, -(tx + bbx)), MIN(bbw, dst->w - tx - bbx), color);
 	else if (dst->bytesPerPixel == 2)
-		drawCharIntern<2>(ptr, dst->pitch, tmp, y, MAX(0, -(tx + bbx)), MIN(bbw, dst->w - tx - bbx), color);
+		drawCharIntern<uint16>(ptr, dst->pitch, tmp, y, MAX(0, -(tx + bbx)), MIN(bbw, dst->w - tx - bbx), color);
 }
 
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list