[Scummvm-cvs-logs] SF.net SVN: scummvm:[41865] scummvm/branches/gsoc2009-draci/engines/draci/ sprite.cpp

dkasak13 at users.sourceforge.net dkasak13 at users.sourceforge.net
Thu Jun 25 16:03:57 CEST 2009


Revision: 41865
          http://scummvm.svn.sourceforge.net/scummvm/?rev=41865&view=rev
Author:   dkasak13
Date:     2009-06-25 14:03:57 +0000 (Thu, 25 Jun 2009)

Log Message:
-----------
Added transformToRows() static method to Sprite. Modified Sprite constructors to use it.

Modified Paths:
--------------
    scummvm/branches/gsoc2009-draci/engines/draci/sprite.cpp

Modified: scummvm/branches/gsoc2009-draci/engines/draci/sprite.cpp
===================================================================
--- scummvm/branches/gsoc2009-draci/engines/draci/sprite.cpp	2009-06-25 11:57:00 UTC (rev 41864)
+++ scummvm/branches/gsoc2009-draci/engines/draci/sprite.cpp	2009-06-25 14:03:57 UTC (rev 41865)
@@ -31,6 +31,26 @@
 namespace Draci {
 
 /**
+ *  @brief Transforms an image from column-wise to row-wise
+ *	@param img pointer to the buffer containing the image data
+ *		   width width of the image in the buffer
+ *		   height height of the image in the buffer
+ */
+static void transformToRows(byte *img, uint16 width, uint16 height) {
+	byte *buf = new byte[width * height];
+	byte *tmp = buf;
+	memcpy(buf, img, width * height);
+	
+	for (uint16 i = 0; i < width; ++i) {
+		for (uint16 j = 0; j < height; ++j) {
+			img[j * width + i] = *tmp++;
+		}
+	}
+	
+	delete[] buf;
+}
+
+/**
  *  Constructor for loading sprites from a raw data buffer, one byte per pixel.
  */
 Sprite::Sprite(byte *raw_data, uint16 width, uint16 height, uint16 x, uint16 y, 
@@ -38,18 +58,12 @@
 	
 	_data = new byte[width * height];
 	
-	// If the sprite is stored row-wise, just copy it to the internal buffer.
-	// Otherwise, transform it and then copy.
-	
-	if (!columnwise) {
-		memcpy(_data, raw_data, width * height);
-	} else {
-		for (uint16 i = 0; i < width; ++i) {
-			for (uint16 j = 0; j < height; ++j) {
-				_data[j * width + i] = *raw_data++;
-			}
-		}
-	}
+	memcpy(_data, raw_data, width * height);
+
+	// If the sprite is stored column-wise, transform it to row-wise
+	if (columnwise) {
+		transformToRows(_data, width, height);
+	}	
 }
 
 /**
@@ -66,17 +80,11 @@
 
 	_data = new byte[_width * _height];
 
-	// If the sprite is stored row-wise, just copy it to the internal buffer.
-	// Otherwise, transform it and then copy.
-	
-	if (!columnwise) {
-		reader.read(_data, _width * _height);
-	} else {
-		for (uint16 i = 0; i < _width; ++i) {
-			for (uint16 j = 0; j < _height; ++j) {
-				_data[j * _width + i] = reader.readByte();
-			}
-		}
+	reader.read(_data, _width * _height);
+
+	// If the sprite is stored column-wise, transform it to row-wise
+	if (columnwise) {
+		transformToRows(_data, _width, _height);
 	}		
 }
 


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