[Scummvm-cvs-logs] CVS: scummvm/scumm gfx.cpp,2.354,2.355 gfx.h,1.87,1.88

Gregory Montoir cyx at users.sourceforge.net
Thu Sep 30 16:32:01 CEST 2004


Update of /cvsroot/scummvm/scummvm/scumm
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24051/scumm

Modified Files:
	gfx.cpp gfx.h 
Log Message:
rewrote drawStripHE ; although it's less efficient than the previous version, it should fix all the invalid mem read accesses reported by valgrind

Index: gfx.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/gfx.cpp,v
retrieving revision 2.354
retrieving revision 2.355
diff -u -d -r2.354 -r2.355
--- gfx.cpp	28 Sep 2004 21:53:29 -0000	2.354
+++ gfx.cpp	30 Sep 2004 23:30:58 -0000	2.355
@@ -594,7 +594,7 @@
 		if (findResource(MKID('BMAP'), room) != NULL) {
 			if (_fullRedraw) {
 				_bgNeedsRedraw = false;
-				gdi.drawBMAPBg(room, &virtscr[0], _screenStartStrip, virtscr[0].w);
+				gdi.drawBMAPBg(room, &virtscr[0], _screenStartStrip);
 			}
 			cont = false;
 		} else if (findResource(MKID('SMAP'), room) == NULL) {
@@ -1367,7 +1367,7 @@
  * TODO: This function essentially is a stripped down & special cased version of
  * the generic Gdi::drawBitmap() method. We might consider merging those two.
  */
-void Gdi::drawBMAPBg(const byte *ptr, VirtScreen *vs, int startstrip, int width) {
+void Gdi::drawBMAPBg(const byte *ptr, VirtScreen *vs, int startstrip) {
 	assert(ptr);
 	const byte *bmap_ptr;
 	byte code;
@@ -1386,13 +1386,12 @@
 
 	// TODO: The following few lines more or less duplicate decompressBitmap(), only
 	// for an area spanning multiple strips. In particular, the codecs 13 & 14
-	// in decompressBitmap call drawStripHE(), which use the same algorithm as
-	// drawStripHE() does...
+	// in decompressBitmap call drawStripHE()
 	if ((code >= 134 && code <= 138) || (code >= 144 && code <= 148)) {
 		_decomp_shr = code % 10;
 		_decomp_mask = 0xFF >> (8 - _decomp_shr);
 
-		drawStripHE((byte *)vs->backBuf, width, bmap_ptr, vs->w, vs->h, false);
+		drawStripHE((byte *)vs->backBuf, vs->pitch, bmap_ptr, vs->w, vs->h, false);
 	}
 	copyVirtScreenBuffers(Common::Rect(vs->w, vs->h));
 
@@ -2115,52 +2114,53 @@
 }
 
 #define READ_BIT (shift--, dataBit = data & 1, data >>= 1, dataBit)
-#define FILL_BITS do {               \
-		if (shift <= 16) {           \
-			data |= READ_LE_UINT16(src) << shift; \
-			src += 2;                 \
-			shift += 16;              \
-		}                             \
+#define FILL_BITS(n) do {            \
+		if (shift < n) {             \
+			data |= *src++ << shift; \
+			shift += 8;              \
+		}                            \
 	} while (0)
 
 // NOTE: drawStripHE is actually very similar to drawStripComplex
-void Gdi::drawStripHE(byte *dst, int dstPitch, const byte *src, int w, int height, const bool transpCheck) const {
-	uint32 dataBit, data, shift;
+void Gdi::drawStripHE(byte *dst, int dstPitch, const byte *src, int width, int height, const bool transpCheck) const {
+	static const int delta_color[] = { -4, -3, -2, -1, 1, 2, 3, 4 };
+	uint32 dataBit, data;
 	byte color;
-	int32 iteration;
-
-	color = *src;
-	src++;
+	int shift;
+	
+	color = *src++;
 	data = READ_LE_UINT24(src);
 	src += 3;
 	shift = 24;
-
-	while (height) {
-		for (iteration = 0; iteration < w; iteration++) {
-			if (!transpCheck || color != _transparentColor)
-				*dst = _roomPalette[color];
-			dst++;
-			FILL_BITS;
-			
+	
+	int x = width;
+	while (1) {
+		if (!transpCheck || color != _transparentColor)
+			*dst = _roomPalette[color];
+		dst++;
+		--x;
+		if (x == 0) {
+			x = width;
+			dst += dstPitch - width;
+			--height;
+			if (height == 0)
+				return;
+		}
+		FILL_BITS(1);
+		if (READ_BIT) {
+			FILL_BITS(1);
 			if (READ_BIT) {
-				if (!READ_BIT) {
-					color = data & _decomp_mask;
-					shift -= _decomp_shr;
-					data >>= _decomp_shr;
-				} else {
-					dataBit = data & 7;
-					shift -= 3;
-					data >>= 3;
-					// map (0, 1, 2, 3, 4, 5, 6, 7) to (-4, -3, -2, -1, 1, 2, 3, 4)
-					if (dataBit >= 4)
-						color += dataBit - 3;
-					else
-						color += dataBit - 4;
-				}
+				FILL_BITS(3);
+				color += delta_color[data & 7];
+				shift -= 3;
+				data >>= 3;
+			} else {
+				FILL_BITS(_decomp_shr);
+				color = data & _decomp_mask;
+				shift -= _decomp_shr;
+				data >>= _decomp_shr;
 			}
 		}
-		dst += dstPitch - w;
-		height--;
 	}
 }
 

Index: gfx.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/gfx.h,v
retrieving revision 1.87
retrieving revision 1.88
diff -u -d -r1.87 -r1.88
--- gfx.h	28 Sep 2004 15:40:39 -0000	1.87
+++ gfx.h	30 Sep 2004 23:30:59 -0000	1.88
@@ -248,7 +248,7 @@
 	void unkDecode11(byte *dst, int dstPitch, const byte *src, int height) const;
 	void drawStrip3DO(byte *dst, int dstPitch, const byte *src, int height, const bool transpCheck) const;
 
-	void drawStripHE(byte *dst, int dstPitch, const byte *src, int w, int height, const bool transpCheck) const;
+	void drawStripHE(byte *dst, int dstPitch, const byte *src, int width, int height, const bool transpCheck) const;
 
 	/* Mask decompressors */
 	void drawStripC64Mask(byte *dst, int stripnr, int width, int height) const;
@@ -275,7 +275,7 @@
 	StripTable *generateStripTable(const byte *src, int width, int height, StripTable *table) const;
 	void decodeC64Gfx(const byte *src, byte *dst, int size) const;
 
-	void drawBMAPBg(const byte *ptr, VirtScreen *vs, int startstrip, int width);
+	void drawBMAPBg(const byte *ptr, VirtScreen *vs, int startstrip);
 	void drawBMAPObject(const byte *ptr, VirtScreen *vs, int obj, int x, int y, int w, int h);
 	void copyWizImage(uint8 *dst, const uint8 *src, int dstw, int dsth, int srcx, int srcy, int srcw, int srch, const Common::Rect *rect);
 	void decompressWizImage(uint8 *dst, int dstPitch, const Common::Rect &dstRect, const uint8 *src, const Common::Rect &srcRect);





More information about the Scummvm-git-logs mailing list