[Scummvm-cvs-logs] SF.net SVN: scummvm: [25209] scummvm/trunk/engines/scumm

cyx at users.sourceforge.net cyx at users.sourceforge.net
Fri Jan 26 23:03:42 CET 2007


Revision: 25209
          http://scummvm.svn.sourceforge.net/scummvm/?rev=25209&view=rev
Author:   cyx
Date:     2007-01-26 14:03:41 -0800 (Fri, 26 Jan 2007)

Log Message:
-----------
templatified some Wiz decoding functions

Modified Paths:
--------------
    scummvm/trunk/engines/scumm/akos.cpp
    scummvm/trunk/engines/scumm/he/wiz_he.cpp
    scummvm/trunk/engines/scumm/he/wiz_he.h

Modified: scummvm/trunk/engines/scumm/akos.cpp
===================================================================
--- scummvm/trunk/engines/scumm/akos.cpp	2007-01-26 21:47:42 UTC (rev 25208)
+++ scummvm/trunk/engines/scumm/akos.cpp	2007-01-26 22:03:41 UTC (rev 25209)
@@ -1321,9 +1321,13 @@
 
 	byte *dstPtr = (byte *)_out.pixels + dst.left + dst.top * _out.pitch;
 	if (_shadow_mode == 3) {
-		Wiz::decompressWizImage(dstPtr, _out.pitch, dst, _srcptr, src, 0, palPtr, xmap);
+		Wiz::decompressWizImage<kWizXMap>(dstPtr, _out.pitch, _srcptr, src, 0, palPtr, xmap);
 	} else {
-		Wiz::decompressWizImage(dstPtr, _out.pitch, dst, _srcptr, src, 0, palPtr);
+		if (palPtr != NULL) {
+			Wiz::decompressWizImage<kWizRMap>(dstPtr, _out.pitch, _srcptr, src, 0, palPtr);
+		} else {
+			Wiz::decompressWizImage<kWizCopy>(dstPtr, _out.pitch, _srcptr, src, 0);
+		}
 	}
 #endif
 	return 0;

Modified: scummvm/trunk/engines/scumm/he/wiz_he.cpp
===================================================================
--- scummvm/trunk/engines/scumm/he/wiz_he.cpp	2007-01-26 21:47:42 UTC (rev 25208)
+++ scummvm/trunk/engines/scumm/he/wiz_he.cpp	2007-01-26 22:03:41 UTC (rev 25209)
@@ -362,7 +362,13 @@
 			const int dx = (srcx < 0) ? srcx : (srcw - r1.width());
 			r1.translate(dx, 0);
 		}
-		decompressWizImage(dst, dstw, r2, src, r1, flags, palPtr, xmapPtr);
+		if (xmapPtr) {
+			decompressWizImage<kWizXMap>(dst, dstw, src, r1, flags, palPtr, xmapPtr);
+		} else if (palPtr) {
+			decompressWizImage<kWizRMap>(dst, dstw, src, r1, flags, palPtr);
+		} else {
+			decompressWizImage<kWizCopy>(dst, dstw, src, r1, flags);
+		}
 	}
 }
 
@@ -373,7 +379,7 @@
 			mask >>= 1;
 			if (mask == 0) {
 				mask = 0x80;
-				++dst;	
+				++dst;
 			}
 		}
 		break;
@@ -489,41 +495,28 @@
 	}
 }
 
-void Wiz::copyRaw16BitWizImage(uint8 *dst, const uint8 *src, int dstw, int dsth, int srcx, int srcy, int srcw, int srch, const Common::Rect *rect, int flags, const uint8 *palPtr, int transColor) {
-	// RAW 16 bits in 555 format
-
-	// HACK: Skip every second bit for now
+void Wiz::copyRawWizImage(uint8 *dst, const uint8 *src, int dstw, int dsth, int srcx, int srcy, int srcw, int srch, const Common::Rect *rect, int flags, const uint8 *palPtr, int transColor) {
 	Common::Rect r1, r2;
 	if (calcClipRects(dstw, dsth, srcx, srcy, srcw, srch, rect, r1, r2)) {
+		dst += r2.left + r2.top * dstw;
+		src += r1.left + r1.top * srcw;
 		if (flags & (kWIFFlipY | kWIFFlipX)) {
 			warning("Unhandled Wiz flags (kWIFFlipY | kWIFFlipX)");
 		}
-		byte imagePal[256];
-		if (!palPtr) {
-			for (int i = 0; i < 256; i++) {
-				imagePal[i] = i;
-			}
-			palPtr = imagePal;
-		}
 		int h = r1.height();
 		int w = r1.width();
-		src += r1.left + r1.top * srcw * 2;
-		dst += r2.left + r2.top * dstw;
-		while (h--) {
-			for (int i = 0; i < w; ++i) {
-				uint8 col = src[2 * i];
-				if (transColor == -1 || transColor != col) {
-					dst[i] = palPtr[col];
-				}
-			}
-			src += srcw * 2;
-			dst += dstw;
+		if (palPtr) {
+			decompressRawWizImage<kWizRMap>(dst, dstw, src, srcw, w, h, transColor, palPtr);
+		} else {
+			decompressRawWizImage<kWizCopy>(dst, dstw, src, srcw, w, h, transColor);
 		}
-
 	}
 }
 
-void Wiz::copyRawWizImage(uint8 *dst, const uint8 *src, int dstw, int dsth, int srcx, int srcy, int srcw, int srch, const Common::Rect *rect, int flags, const uint8 *palPtr, int transColor) {
+void Wiz::copyRaw16BitWizImage(uint8 *dst, const uint8 *src, int dstw, int dsth, int srcx, int srcy, int srcw, int srch, const Common::Rect *rect, int flags, const uint8 *palPtr, int transColor) {
+	// RAW 16 bits in 555 format
+
+	// HACK: Skip every second bit for now
 	Common::Rect r1, r2;
 	if (calcClipRects(dstw, dsth, srcx, srcy, srcw, srch, rect, r1, r2)) {
 		if (flags & (kWIFFlipY | kWIFFlipX)) {
@@ -538,34 +531,33 @@
 		}
 		int h = r1.height();
 		int w = r1.width();
-		src += r1.left + r1.top * srcw;
+		src += r1.left + r1.top * srcw * 2;
 		dst += r2.left + r2.top * dstw;
 		while (h--) {
 			for (int i = 0; i < w; ++i) {
-				uint8 col = src[i];
+				uint8 col = src[2 * i];
 				if (transColor == -1 || transColor != col) {
 					dst[i] = palPtr[col];
 				}
 			}
-			src += srcw;
+			src += srcw * 2;
 			dst += dstw;
 		}
 	}
 }
 
-void Wiz::decompressWizImage(uint8 *dst, int dstPitch, const Common::Rect &dstRect, const uint8 *src, const Common::Rect &srcRect, int flags, const uint8 *palPtr, const uint8 *xmapPtr) {
+template <int type>
+void Wiz::decompressWizImage(uint8 *dst, int dstPitch, const uint8 *src, const Common::Rect &srcRect, int flags, const uint8 *palPtr, const uint8 *xmapPtr) {
 	const uint8 *dataPtr, *dataPtrNext;
 	uint8 code, *dstPtr, *dstPtrNext;
 	int h, w, xoff, dstInc;
-	uint16 off;
 
-	byte imagePal[256];
-	if (!palPtr) {
-		for (int i = 0; i < 256; i++) {
-			imagePal[i] = i;
-		}
-		palPtr = imagePal;
+	if (type == kWizXMap) {
+		assert(palPtr != 0 && xmapPtr != 0);
 	}
+	if (type == kWizRMap) {
+		assert(palPtr != 0);
+	}
 
 	dstPtr = dst;
 	dataPtr = src;
@@ -593,10 +585,10 @@
 	while (h--) {
 		xoff = srcRect.left;
 		w = srcRect.width();
-		off = READ_LE_UINT16(dataPtr); dataPtr += 2;
+		uint16 lineSize = READ_LE_UINT16(dataPtr); dataPtr += 2;
 		dstPtrNext = dstPtr + dstPitch;
-		dataPtrNext = dataPtr + off;
-		if (off != 0) {
+		dataPtrNext = dataPtr + lineSize;
+		if (lineSize != 0) {
 			while (w > 0) {
 				code = *dataPtr++;
 				if (code & 1) {
@@ -626,11 +618,15 @@
 						code += w;
 					}
 					while (code--) {
-						if (xmapPtr) {
+						if (type == kWizXMap) {
 							*dstPtr = xmapPtr[palPtr[*dataPtr] * 256 + *dstPtr];
-						} else {
+						}
+						if (type == kWizRMap) {
 							*dstPtr = palPtr[*dataPtr];
 						}
+						if (type == kWizCopy) {
+							*dstPtr = *dataPtr;
+						}
 						dstPtr += dstInc;
 					}
 					dataPtr++;
@@ -650,11 +646,15 @@
 						code += w;
 					}
 					while (code--) {
-						if (xmapPtr) {
+						if (type == kWizXMap) {
 							*dstPtr = xmapPtr[palPtr[*dataPtr++] * 256 + *dstPtr];
-						} else {
+						}
+						if (type == kWizRMap) {
 							*dstPtr = palPtr[*dataPtr++];
 						}
+						if (type == kWizCopy) {
+							*dstPtr = *dataPtr++;
+						}
 						dstPtr += dstInc;
 					}
 				}
@@ -665,6 +665,32 @@
 	}
 }
 
+template <int type>
+void Wiz::decompressRawWizImage(uint8 *dst, int dstPitch, const uint8 *src, int srcPitch, int w, int h, int transColor, const uint8 *palPtr) {
+	if (type == kWizRMap) {
+		assert(palPtr != 0);
+	}
+
+	if (w <= 0 || h <= 0) {
+		return;
+	}
+	while (h--) {
+		for (int i = 0; i < w; ++i) {
+			uint8 col = src[i];
+			if (transColor == -1 || transColor != col) {
+				if (type == kWizRMap) {
+					dst[i] = palPtr[col];
+				}
+				if (type == kWizCopy) {
+					dst[i] = col;
+				}
+			}
+		}
+		src += srcPitch;
+		dst += dstPitch;
+	}
+}
+
 int Wiz::isWizPixelNonTransparent(const uint8 *data, int x, int y, int w, int h) {
 	if (x < 0 || x >= w || y < 0 || y >= h) {
 		return 0;
@@ -909,7 +935,7 @@
 					runCountSame = 0;
 				}
 				assert(runCountDiff < ARRAYSIZE(diffBuffer));
-				diffBuffer[runCountDiff++] = color;				
+				diffBuffer[runCountDiff++] = color;
 				if (runCountDiff == 0x40) {
 					if (dst) {
 						*dst++ = ((runCountDiff - 1) << 2) | 0;
@@ -1098,7 +1124,7 @@
 
 	dataPtr = _vm->getResourceAddress(rtImage, resNum);
 	assert(dataPtr);
-	
+
 	uint8 *wizh = _vm->findWrappedBlock(MKID_BE('WIZH'), dataPtr, state, 0);
 	assert(wizh);
 	uint32 comp   = READ_LE_UINT32(wizh + 0x0);
@@ -1387,12 +1413,12 @@
   		int16 xmin_b, xmax_b, ymin_b, ymax_b;
   		xmin_b = ymin_b = (int16)0x7FFF;
   		xmax_b = ymax_b = (int16)0x8000;
-		
+
 		for (i = 0; i < 4; ++i) {
   			xmin_b = MIN(bbox[i].x, xmin_b);
   			xmax_b = MAX(bbox[i].x, xmax_b);
   			ymin_b = MIN(bbox[i].y, ymin_b);
-  			ymax_b = MAX(bbox[i].y, ymax_b);			
+  			ymax_b = MAX(bbox[i].y, ymax_b);
 		}
 
 		PolygonDrawData pdd(ymax_p - ymin_p + 1);

Modified: scummvm/trunk/engines/scumm/he/wiz_he.h
===================================================================
--- scummvm/trunk/engines/scumm/he/wiz_he.h	2007-01-26 21:47:42 UTC (rev 25208)
+++ scummvm/trunk/engines/scumm/he/wiz_he.h	2007-01-26 22:03:41 UTC (rev 25209)
@@ -133,6 +133,12 @@
 	kWPFMaskImg = 0x80000
 };
 
+enum {
+	kWizXMap = 0,
+	kWizRMap,
+	kWizCopy
+};
+
 class ScummEngine_v70he;
 
 class Wiz {
@@ -196,7 +202,8 @@
 	static void copyWizImageWithMask(uint8 *dst, const uint8 *src, int dstw, int dsth, int srcx, int srcy, int srcw, int srch, const Common::Rect *rect, int maskT, int maskP);
 	static void copyRawWizImage(uint8 *dst, const uint8 *src, int dstw, int dsth, int srcx, int srcy, int srcw, int srch, const Common::Rect *rect, int flags, const uint8 *palPtr, int transColor);
 	static void copyRaw16BitWizImage(uint8 *dst, const uint8 *src, int dstw, int dsth, int srcx, int srcy, int srcw, int srch, const Common::Rect *rect, int flags, const uint8 *palPtr, int transColor);
-	static void decompressWizImage(uint8 *dst, int dstPitch, const Common::Rect &dstRect, const uint8 *src, const Common::Rect &srcRect, int flags, const uint8 *palPtr = NULL, const uint8 *xmapPtr = NULL);
+	template<int type> static void decompressWizImage(uint8 *dst, int dstPitch, const uint8 *src, const Common::Rect &srcRect, int flags, const uint8 *palPtr = NULL, const uint8 *xmapPtr = NULL);
+	template<int type> static void decompressRawWizImage(uint8 *dst, int dstPitch, const uint8 *src, int srcPitch, int w, int h, int transColor, const uint8 *palPtr = NULL);
 	int isWizPixelNonTransparent(const uint8 *data, int x, int y, int w, int h);
 	uint8 getWizPixelColor(const uint8 *data, int x, int y, int w, int h, uint8 color);
 	uint8 getRawWizPixelColor(const uint8 *data, int x, int y, int w, int h, uint8 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