[Scummvm-cvs-logs] scummvm master -> d2962531cbdfdfc3cdec7af2487add21a056295b

sev- sev at scummvm.org
Sun Jun 26 20:22:07 CEST 2011


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
d2962531cb GRAPHICS: Generalized arbitrary bit depth images processing  in PNG decoder.


Commit: d2962531cbdfdfc3cdec7af2487add21a056295b
    https://github.com/scummvm/scummvm/commit/d2962531cbdfdfc3cdec7af2487add21a056295b
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2011-06-26T11:19:27-07:00

Commit Message:
GRAPHICS: Generalized arbitrary bit depth images processing  in PNG decoder.

This fixes 1bpp image rengering.

Changed paths:
    graphics/png.cpp



diff --git a/graphics/png.cpp b/graphics/png.cpp
index 6ffc53b..2189fd3 100644
--- a/graphics/png.cpp
+++ b/graphics/png.cpp
@@ -166,18 +166,26 @@ Graphics::Surface *PNG::getSurface(const PixelFormat &format) {
 		}
 	} else {
 		byte index, r, g, b;
+		uint32 mask = (0xff >> (8 - _header.bitDepth)) << (8 - _header.bitDepth);
 
 		// Convert the indexed surface to the target pixel format
 		for (uint16 i = 0; i < output->h; i++) {
-			bool otherPixel = false;
+			int data = 0;
+			int bitCount = 8;
+			byte *src1 = src;
 
 			for (uint16 j = 0; j < output->w; j++) {
-				if (_header.bitDepth != 4)
-					index = *src;
-				else if (!otherPixel)
-					index = (*src) >> 4;
-				else
-					index = (*src) & 0xf;
+				if (bitCount == 8) {
+					data = *src;
+					src++;
+				}
+
+				index = (data & mask) >> (8 - _header.bitDepth);
+				data = (data << _header.bitDepth) & 0xff;
+				bitCount -= _header.bitDepth;
+
+				if (bitCount == 0)
+					bitCount = 8;
 
 				r = _palette[index * 4 + 0];
 				g = _palette[index * 4 + 1];
@@ -188,14 +196,8 @@ Graphics::Surface *PNG::getSurface(const PixelFormat &format) {
 					*((uint16 *)output->getBasePtr(j, i)) = format.ARGBToColor(a, r, g, b);
 				else
 					*((uint32 *)output->getBasePtr(j, i)) = format.ARGBToColor(a, r, g, b);
-
-				if (_header.bitDepth != 4 || otherPixel)
-					src++;
-				otherPixel = !otherPixel;
 			}
-			// The surface is a whole scanline wide, skip the rest of it.
-			if (_header.bitDepth == 4)
-				src += output->w / 2 + output->w % 2;
+			src = src1 + output->w;
 		}
 	}
 






More information about the Scummvm-git-logs mailing list