[Scummvm-cvs-logs] SF.net SVN: scummvm:[50739] scummvm/branches/gsoc2010-testbed/engines/ testbed

sud03r at users.sourceforge.net sud03r at users.sourceforge.net
Wed Jul 7 22:31:28 CEST 2010


Revision: 50739
          http://scummvm.svn.sourceforge.net/scummvm/?rev=50739&view=rev
Author:   sud03r
Date:     2010-07-07 20:31:28 +0000 (Wed, 07 Jul 2010)

Log Message:
-----------
Added code to draw rainbow palette using HSV and converting it to RGB

Modified Paths:
--------------
    scummvm/branches/gsoc2010-testbed/engines/testbed/graphics.cpp
    scummvm/branches/gsoc2010-testbed/engines/testbed/graphics.h

Modified: scummvm/branches/gsoc2010-testbed/engines/testbed/graphics.cpp
===================================================================
--- scummvm/branches/gsoc2010-testbed/engines/testbed/graphics.cpp	2010-07-07 20:12:41 UTC (rev 50738)
+++ scummvm/branches/gsoc2010-testbed/engines/testbed/graphics.cpp	2010-07-07 20:31:28 UTC (rev 50739)
@@ -38,7 +38,7 @@
 
 namespace Testbed {
 
-byte GFXTestSuite::_palette[3 * 4] = {0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 0};
+byte GFXTestSuite::_palette[256 * 4] = {0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 0};
 
 GFXTestSuite::GFXTestSuite() {
 	// Initialize color palettes
@@ -85,7 +85,7 @@
 	_palette[8] = r; 
 	_palette[9] = g;
 	_palette[10] = b;
-	g_system->setPalette(_palette, 0, 3);
+	g_system->setPalette(_palette, 0, 256);
 }
 
 // Helper functions used by GFX tests
@@ -102,6 +102,69 @@
 	
 }
 
+void GFXtests::HSVtoRGB(int& rComp, int& gComp, int& bComp, int hue, int sat, int val) {
+	
+	float r = rComp;
+	float g = gComp;
+	float b = bComp;
+
+	float h = hue * (360 / 254.0); // two colors are left for bg and fg
+	float s = sat;
+	float v = val;
+
+	int i;
+	float f, p, q, t;
+
+	if (s == 0) {
+		r = g = b = v * 255;
+		return;
+	}
+
+	h /= 60;	
+	i = (int) h;
+	f = h - i;
+	p = v * (1 - s);
+	q = v * (1 - s * f);
+	t = v * (1 - s * (1 - f));
+
+	switch (i) {
+		case 0:
+			r = v;
+			g = t;
+			b = p;
+			break;
+		case 1:
+			r = q;
+			g = v;
+			b = p;
+			break;
+		case 2:
+			r = p;
+			g = v;
+			b = t;
+			break;
+		case 3:
+			r = p;
+			g = q;
+			b = v;
+			break;
+		case 4:
+			r = t;
+			g = p;
+			b = v;
+			break;
+		default:	
+			r = v;
+			g = p;
+			b = q;
+			break;
+	}
+
+	rComp = r * 255;
+	gComp = g * 255;
+	bComp = b * 255;
+}
+
 void GFXtests::drawCursor(bool cursorPaletteDisabled, const char *gfxModeName, int cursorTargetScale) {	
 
 	// Buffer initialized with yellow color
@@ -712,38 +775,49 @@
 	Common::Point pt(0, 10);
 	Testsuite::writeOnScreen("Rotating palettes, the rectangles should appear moving up!", pt);
 	
-	byte palette[10 * 4] = {0, 0, 0, 0,
-							255, 255, 255, 0,
-							135, 48, 21, 0,
-							205, 190, 87, 0,
-							0, 32, 64, 0,
-							181, 126, 145, 0,
-							47, 78, 36, 0,
-							185, 115, 20, 0,
-							160, 164, 137, 0,
-							43, 52, 0, 0}; // 10 colors : B, W and 8 random 
+	// Use 256 colors
+	byte palette[256 * 4] = {0, 0, 0, 0,
+							 255, 255, 255, 0};
 
-	Common::RandomSource rs;
+	int r, g, b;
+	int colIndx;
+
+	for (int i = 2; i < 256; i++) {
+		HSVtoRGB(r, g, b, i - 2, 1, 1);
+		colIndx = i * 4;
+		palette[colIndx] = r;
+		palette[colIndx + 1] = g;
+		palette[colIndx + 2] = b;
+	}
 	
-	// Initialize this palette randomly
-	g_system->setPalette(palette, 0, 10);
+	// Initialize this palette.
+	g_system->setPalette(palette, 0, 256);
 
-	// Draw 10 Rectangles, each of width 100 pixels and height 10 pixels
-	byte buffer[10 * 100 * 10] = {0};
-	
-	for (int i = 2; i < 10; i++) {
-		memset(buffer + i * 1000, i, 1000 * sizeof(byte));
+	// Draw 254 Rectangles, each 1 pixel wide and 10 pixels long
+	byte buffer[254 * 10] = {0};
+
+	for (int i = 0; i < 10; i++) {
+		for (int j = 0; j < 254; j++) {
+			buffer[i * 256 + j] = j + 2;
+		}
 	}
 	
-	g_system->copyRectToScreen(buffer, 100, 110, 50, 100, 100);
+	g_system->copyRectToScreen(buffer, 256, 22, 50, 256, 10);
+	g_system->updateScreen();
+	g_system->delayMillis(2000);
+	
+	// Reset initial palettes
+	GFXTestSuite::setCustomColor(255, 0, 0);
+	Testsuite::clearScreen();
 
 	int toRotate = 10;
 
 	while (toRotate--) {
 		g_system->updateScreen();
 		g_system->delayMillis(600);
-		rotatePalette(&palette[8], 8);
-		g_system->setPalette(palette, 0, 10);
+		// FIXME : fix rotation
+		// rotatePalette(&palette[8], 254);
+		// g_system->setPalette(palette, 0, 256);
 	}
 
 	if(Testsuite::handleInteractiveInput("Did you saw a rotation in colors of rectangles displayed on screen?", "Yes", "No", kOptionRight)) {

Modified: scummvm/branches/gsoc2010-testbed/engines/testbed/graphics.h
===================================================================
--- scummvm/branches/gsoc2010-testbed/engines/testbed/graphics.h	2010-07-07 20:12:41 UTC (rev 50738)
+++ scummvm/branches/gsoc2010-testbed/engines/testbed/graphics.h	2010-07-07 20:31:28 UTC (rev 50739)
@@ -36,6 +36,7 @@
 void setupMouseLoop(bool disableCursorPalette = false, const char *gfxModeName = "", int cursorTargetScale = 1);
 void initMousePalette();
 void mouseMovements();
+void HSVtoRGB(int& rComp, int& gComp,int& bComp, int hue, int sat, int val);
 void drawCursor(bool cursorPaletteDisabled = false, const char *gfxModeName = "", int cursorTargetScale = 1);
 
 // will contain function declarations for GFX tests
@@ -75,8 +76,9 @@
 	 * 0 (R:0, G:0, B:0) Black (kColorBlack)
 	 * 1 (R:255, G:255, B:255) White (kColorWhite)
 	 * 2 (R:255, G:255, B:255) your customized color (by default white) (kColorCustom)
+	 * The remaining values are zero
 	 */
-	static byte _palette[3 * 4];
+	static byte _palette[256 * 4];
 };
 
 }	// End of namespace Testbed


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