[Scummvm-cvs-logs] SF.net SVN: scummvm:[42051] scummvm/branches/gsoc2009-16bit/common/system.h

upthorn at users.sourceforge.net upthorn at users.sourceforge.net
Fri Jul 3 11:33:58 CEST 2009


Revision: 42051
          http://scummvm.svn.sourceforge.net/scummvm/?rev=42051&view=rev
Author:   upthorn
Date:     2009-07-03 09:33:58 +0000 (Fri, 03 Jul 2009)

Log Message:
-----------
Provided a virtual method for converting graphics rectangles from screen format to hardware format, for backend developers wanting to provide support for color component orders not directly supported in hardware. (This could probably use a fair bit of looking over, it's ugly and has some fairly arbitrary limitations)

Modified Paths:
--------------
    scummvm/branches/gsoc2009-16bit/common/system.h

Modified: scummvm/branches/gsoc2009-16bit/common/system.h
===================================================================
--- scummvm/branches/gsoc2009-16bit/common/system.h	2009-07-03 09:01:51 UTC (rev 42050)
+++ scummvm/branches/gsoc2009-16bit/common/system.h	2009-07-03 09:33:58 UTC (rev 42051)
@@ -997,6 +997,80 @@
 	 */
 	virtual Common::WriteStream *createConfigWriteStream() = 0;
 
+#ifdef ENABLE_RGB_COLOR
+private:
+	/**
+	 * Convert a rectangle from the screenformat to the hardwareformat.
+	 *
+	 * @param buf		the buffer containing the graphics data source
+	 * @param w			the width of the destination rectangle
+	 * @param h			the height of the destination rectangle
+	 * @param dest		the pixel format currently set in hardware
+	 * @return			true if conversion completes successfully, 
+	 *					false if there is an error.
+	 *
+	 * @note This implementation is slow. Please override this if
+	 *		 your backend hardware has a better way to deal with this.
+	 * @note This implementation requires the screen pixel format and 
+	 *		 the hardware pixel format to have a matching bytedepth
+	 */
+	virtual bool convertRect(byte *buf, int w, int h, 
+							Graphics::PixelFormat dest) {
+		Graphics::PixelFormat orig = getScreenFormat();
+
+		// Error out if conversion is impossible
+		if ((orig.bytesPerPixel != dest.bytesPerPixel) ||
+			(dest.bytesPerPixel == 1) || (!dest.bytesPerPixel))
+			return false;
+
+		// Don't perform unnecessary conversion
+		if (orig == dest)
+			return true;
+
+		byte *tmp = buf;
+		byte bytesPerPixel = dest.bytesPerPixel;
+		// Faster, but larger, to provide optimized handling for each case.
+		uint32 numpix = w * h;
+		if (bytesPerPixel == 2)
+		{
+			for (uint32 i = 0; i < numpix; i++) {
+				uint8 r,g,b,a;
+				uint16 color = *(uint16 *) tmp;
+				orig.colorToARGB(color, a, r, g, b);
+				color = dest.ARGBToColor(a, r, g, b);
+				memcpy(tmp,&color,bytesPerPixel);
+				tmp += 2;
+			}
+		} else if (bytesPerPixel == 3) {
+			for (uint32 i = 0; i < numpix; i++) {
+				uint8 r,g,b,a;
+				uint32 color;
+				uint8 *col = (uint8 *)&color;
+#ifdef SCUMM_BIG_ENDIAN
+				col++;
+#endif
+				memcpy(col,tmp,bytesPerPixel);
+				orig.colorToARGB(color, a, r, g, b);
+				color = dest.ARGBToColor(a, r, g, b);
+				memcpy(tmp,col,bytesPerPixel);
+				tmp += 3;
+			}
+		} else if (bytesPerPixel == 4) {
+			for (uint32 i = 0; i < numpix; i++) {
+				uint8 r,g,b,a;
+				uint32 color;
+				memcpy(&color,tmp,bytesPerPixel);
+				orig.colorToARGB(color, a, r, g, b);
+				color = dest.ARGBToColor(a, r, g, b);
+				memcpy(tmp,&color,bytesPerPixel);
+				tmp += 4;
+			}
+		} else {
+			return false;
+		}
+		return true;
+	};
+#endif // ENABLE_RGB_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