[Scummvm-cvs-logs] SF.net SVN: scummvm:[42057] scummvm/branches/gsoc2009-16bit

upthorn at users.sourceforge.net upthorn at users.sourceforge.net
Fri Jul 3 13:46:09 CEST 2009


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

Log Message:
-----------
Cleaned up system.h, renamed OSystem::convertRect to OSystem::convertScreenRect (still not very descriptive). Added graphics/conversion.h and graphics/conversion.cpp with Graphics::crossBlit function created from extending original contents of OSystem::convertRect

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

Added Paths:
-----------
    scummvm/branches/gsoc2009-16bit/graphics/conversion.cpp
    scummvm/branches/gsoc2009-16bit/graphics/conversion.h

Modified: scummvm/branches/gsoc2009-16bit/common/system.h
===================================================================
--- scummvm/branches/gsoc2009-16bit/common/system.h	2009-07-03 11:05:59 UTC (rev 42056)
+++ scummvm/branches/gsoc2009-16bit/common/system.h	2009-07-03 11:46:09 UTC (rev 42057)
@@ -31,6 +31,9 @@
 #include "common/rect.h"
 
 #include "graphics/pixelformat.h"
+#ifdef ENABLE_RGB_COLOR
+#include "graphics/conversion.h"
+#endif
 
 namespace Audio {
 	class Mixer;
@@ -1000,12 +1003,15 @@
 #ifdef ENABLE_RGB_COLOR
 private:
 	/**
-	 * Convert a rectangle from the screenformat to the hardwareformat.
+	 * Convert a rectangle from the screen format to the hardware format.
 	 *
-	 * @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
+	 * @param dstbuf	the buffer which will recieve the converted graphics data
+	 * @param srcbuf	the buffer containing the original graphics data
+	 * @param dstpitch	width in bytes of one full line of the dest buffer
+	 * @param srcpitch	width in bytes of one full line of the source buffer
+	 * @param w			the width of the graphics data
+	 * @param h			the height of the graphics data
+	 * @param hwFmt		the pixel format currently set in hardware
 	 * @return			true if conversion completes successfully, 
 	 *					false if there is an error.
 	 *
@@ -1014,61 +1020,9 @@
 	 * @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;
+	virtual bool convertScreenRect(byte *dstbuf, const byte *srcbuf, int dstpitch, int srcpitch, 
+									int w, int h, Graphics::PixelFormat hwFmt) {
+		return Graphics::crossBlit(dstbuf,srcbuf,dstpitch,srcpitch,w,h,hwFmt,getScreenFormat());
 	};
 #endif // ENABLE_RGB_COLOR
 	//@}

Modified: scummvm/branches/gsoc2009-16bit/dists/msvc8/scummvm.vcproj
===================================================================
--- scummvm/branches/gsoc2009-16bit/dists/msvc8/scummvm.vcproj	2009-07-03 11:05:59 UTC (rev 42056)
+++ scummvm/branches/gsoc2009-16bit/dists/msvc8/scummvm.vcproj	2009-07-03 11:46:09 UTC (rev 42057)
@@ -1431,6 +1431,14 @@
 				>
 			</File>
 			<File
+				RelativePath="..\..\graphics\conversion.cpp"
+				>
+			</File>
+			<File
+				RelativePath="..\..\graphics\conversion.h"
+				>
+			</File>
+			<File
 				RelativePath="..\..\graphics\cursorman.cpp"
 				>
 			</File>

Added: scummvm/branches/gsoc2009-16bit/graphics/conversion.cpp
===================================================================
--- scummvm/branches/gsoc2009-16bit/graphics/conversion.cpp	                        (rev 0)
+++ scummvm/branches/gsoc2009-16bit/graphics/conversion.cpp	2009-07-03 11:46:09 UTC (rev 42057)
@@ -0,0 +1,138 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ */
+
+#include "graphics/conversion.h"
+#include "common/scummsys.h"
+namespace Graphics {
+// TODO: YUV to RGB conversion function
+
+// Function to blit a rect from one color format to another
+bool crossBlit(byte *dst, const byte *src, int dstpitch, int srcpitch, 
+						int w, int h, Graphics::PixelFormat dstFmt, Graphics::PixelFormat srcFmt) {
+	// Error out if conversion is impossible
+	if ((srcFmt.bytesPerPixel == 1) || (dstFmt.bytesPerPixel == 1) 
+			 || (!srcFmt.bytesPerPixel) || (!dstFmt.bytesPerPixel)
+			 || (srcFmt.bytesPerPixel > dstFmt.bytesPerPixel))
+		return false;
+
+	// Don't perform unnecessary conversion
+	if (srcFmt == dstFmt)
+		return true;
+
+	// Faster, but larger, to provide optimized handling for each case.
+	int srcDelta,dstDelta;
+	srcDelta = (srcpitch - w * srcFmt.bytesPerPixel);
+	dstDelta = (dstpitch - w * dstFmt.bytesPerPixel);
+
+	// TODO: optimized cases for dstDelta of 0
+	uint8 r,g,b,a;
+	if (dstFmt.bytesPerPixel == 2)
+	{
+		uint16 color;
+		for (int y = 0; y < h; y++) {
+			for (int x = 0; x < w; x++, src += 2, dst += 2) {
+				color = *(uint16 *) src;
+				srcFmt.colorToARGB(color, a, r, g, b);
+				color = dstFmt.ARGBToColor(a, r, g, b);
+				*(uint16 *) dst = color;
+			}
+			src += srcDelta;
+			dst += dstDelta;
+		}
+	} else if (dstFmt.bytesPerPixel == 3) {
+		uint32 color;
+		uint8 *col = (uint8 *) &color;
+#ifdef SCUMM_BIG_ENDIAN
+		col++;
+#endif
+		if (srcFmt.bytesPerPixel == 2) {
+			for (int y = 0; y < h; y++) {
+				for (int x = 0; x < w; x++, src += 2, dst += 3) {
+					color = *(uint16 *) src;
+					srcFmt.colorToARGB(color, a, r, g, b);
+					color = dstFmt.ARGBToColor(a, r, g, b);
+					memcpy(dst,col,3);
+				}
+				src += srcDelta;
+				dst += dstDelta;
+			}
+		} else {
+			for (int y = 0; y < h; y++) {
+				for (int x = 0; x < w; x++, src += 3, dst += 3) {
+					uint8 r,g,b,a;
+					memcpy(col,src,3);
+					srcFmt.colorToARGB(color, a, r, g, b);
+					color = dstFmt.ARGBToColor(a, r, g, b);
+					memcpy(dst,col,3);
+				}
+				src += srcDelta;
+				dst += dstDelta;
+			}
+		}
+	} else if (dstFmt.bytesPerPixel == 4) {
+		uint32 color;
+		if (srcFmt.bytesPerPixel == 2) {
+			for (int y = 0; y < h; y++) {
+				for (int x = 0; x < w; x++, src += 2, dst += 4) {
+					color = *(uint16 *) src;
+					srcFmt.colorToARGB(color, a, r, g, b);
+					color = dstFmt.ARGBToColor(a, r, g, b);
+					*(uint32 *) dst = color;
+				}
+				src += srcDelta;
+				dst += dstDelta;
+			}
+		} else if (srcFmt.bytesPerPixel == 3) {
+			uint8 *col = (uint8 *)&color;
+#ifdef SCUMM_BIG_ENDIAN
+			col++;
+#endif
+			for (int y = 0; y < h; y++) {
+				for (int x = 0; x < w; x++, src += 2, dst += 4) {
+					memcpy(col,src,3);
+					srcFmt.colorToARGB(color, a, r, g, b);
+					color = dstFmt.ARGBToColor(a, r, g, b);
+					*(uint32 *) dst = color;
+				}
+				src += srcDelta;
+				dst += dstDelta;
+			}
+		} else {
+			for (int y = 0; y < h; y++) {
+				for (int x = 0; x < w; x++, src += 4, dst += 4) {
+					color = *(uint32 *) src;
+					srcFmt.colorToARGB(color, a, r, g, b);
+					color = dstFmt.ARGBToColor(a, r, g, b);
+					*(uint32 *) dst = color;
+				}
+				src += srcDelta;
+				dst += dstDelta;
+			}
+		}
+	} else {
+		return false;
+	}
+	return true;
+}
+} // end of namespace Graphics
\ No newline at end of file


Property changes on: scummvm/branches/gsoc2009-16bit/graphics/conversion.cpp
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Rev Author URL Id
Added: svn:eol-style
   + native

Added: scummvm/branches/gsoc2009-16bit/graphics/conversion.h
===================================================================
--- scummvm/branches/gsoc2009-16bit/graphics/conversion.h	                        (rev 0)
+++ scummvm/branches/gsoc2009-16bit/graphics/conversion.h	2009-07-03 11:46:09 UTC (rev 42057)
@@ -0,0 +1,56 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+#ifndef GRAPHICS_CONVERSION_H
+#define GRAPHICS_CONVERSION_H
+
+#include "common/scummsys.h"
+#include "graphics/pixelformat.h"
+namespace Graphics {
+
+// TODO: generic YUV to RGB pixel conversion
+// TODO: generic YUV to RGB blit
+
+/**
+ * Convert a rectangle from the one format to another, and blits it.
+ *
+ * @param dstbuf	the buffer which will recieve the converted graphics data
+ * @param srcbuf	the buffer containing the original graphics data
+ * @param dstpitch	width in bytes of one full line of the dest buffer
+ * @param srcpitch	width in bytes of one full line of the source buffer
+ * @param w			the width of the graphics data
+ * @param h			the height of the graphics data
+ * @param dstFmt	the desired pixel format
+ * @param srcFmt	the original pixel format
+ * @return			true if conversion completes successfully, 
+ *					false if there is an error.
+ *
+ * @note This implementation currently requires the destination's 
+ *		 format have at least as high a bitdepth as the source's.
+ *
+ */
+bool crossBlit(byte *dst, const byte *src, int dstpitch, int srcpitch, 
+						int w, int h, Graphics::PixelFormat dstFmt, Graphics::PixelFormat srcFmt);
+} // end of namespace Graphics
+#endif //GRAPHICS_CONVERSION_H
\ No newline at end of file


Property changes on: scummvm/branches/gsoc2009-16bit/graphics/conversion.h
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Rev Author URL Id
Added: svn:eol-style
   + native


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