[Scummvm-cvs-logs] CVS: scummvm/backends/sdl sdl-common.cpp,1.104,1.105

Max Horn fingolfin at users.sourceforge.net
Sat Feb 7 04:34:11 CET 2004


Update of /cvsroot/scummvm/scummvm/backends/sdl
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11118

Modified Files:
	sdl-common.cpp 
Log Message:
new auto-dirty-rect checksum algorithm (not so well tested but uses the standard adler32 checksum algorithm)

Index: sdl-common.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/backends/sdl/sdl-common.cpp,v
retrieving revision 1.104
retrieving revision 1.105
diff -u -d -r1.104 -r1.105
--- sdl-common.cpp	22 Jan 2004 04:31:31 -0000	1.104
+++ sdl-common.cpp	7 Feb 2004 12:30:25 -0000	1.105
@@ -335,8 +335,6 @@
 	}
 }
 
-#define ROL(a,n) a = (a << (n)) | (a >> (32 - (n)))
-#define DOLINE(x) a ^= ((const uint32*)buf)[0 + (x) * (_screenWidth / 4)]; b ^= ((const uint32 *)buf)[1 + (x) * (_screenWidth / 4)]
 
 void OSystem_SDL_Common::mk_checksums(const byte *buf) {
 	uint32 *sums = _dirty_checksums;
@@ -344,32 +342,36 @@
 	const uint last_x = (uint)_screenWidth / 8;
 	const uint last_y = (uint)_screenHeight / 8;
 
+	const uint BASE = 65521; /* largest prime smaller than 65536 */
+
 	/* the 8x8 blocks in buf are enumerated starting in the top left corner and
 	 * reading each line at a time from left to right */
 	for(y = 0; y != last_y; y++, buf += _screenWidth * (8 - 1))
-		for(x=0; x != last_x; x++, buf += 8) {
-			uint32 a = x;
-			uint32 b = y;
-
-			DOLINE(0); ROL(a,13); ROL(b,11);
-			DOLINE(2); ROL(a,13); ROL(b,11);
-			DOLINE(4); ROL(a,13); ROL(b,11);
-			DOLINE(6); ROL(a,13); ROL(b,11);
-
-			a *= 0xDEADBEEF;
-			b *= 0xBAADF00D;
+		for(x = 0; x != last_x; x++, buf += 8) {
+			// Adler32 checksum algorithm (from RFC1950, used by gzip and zlib).
+			// This computes the Adler32 checksum of a 8x8 pixel block. Note
+			// that we can do the modulo operation (which is the slowest part)
+			// of the algorithm) at the end, instead of doing each iteration,
+			// since we only have 64 iterations in total - and thus s1 and
+			// s2 can't overflow anyway.
+			uint32 s1 = 1;
+			uint32 s2 = 0;
+			const byte *ptr = buf;
+			for (int subY = 0; subY < 8; subY++) {
+				for (int subX = 0; subX < 8; subX++) {
+					s1 += ptr[subX];
+					s2 += s1;
+				}
+				ptr += _screenWidth;
+			}
 
-			DOLINE(1); ROL(a,13); ROL(b,11);
-			DOLINE(3); ROL(a,13); ROL(b,11);
-			DOLINE(5); ROL(a,13); ROL(b,11);
-			DOLINE(7); ROL(a,13); ROL(b,11);
+			s1 %= BASE;
+			s2 %= BASE;
 
 			/* output the checksum for this block */
-			*sums++ = a + b;
-		}
+			*sums++ =  (s2 << 16) + s1;
+	}
 }
-#undef DOLINE
-#undef ROL
 
 void OSystem_SDL_Common::add_dirty_rgn_auto(const byte *buf) {
 	assert(((long)buf & 3) == 0);





More information about the Scummvm-git-logs mailing list