[Scummvm-cvs-logs] SF.net SVN: scummvm:[55273] scummvm/trunk/engines/gob

drmccoy at users.sourceforge.net drmccoy at users.sourceforge.net
Sun Jan 16 23:29:49 CET 2011


Revision: 55273
          http://scummvm.svn.sourceforge.net/scummvm/?rev=55273&view=rev
Author:   drmccoy
Date:     2011-01-16 22:29:49 +0000 (Sun, 16 Jan 2011)

Log Message:
-----------
GOB: Adding a proper shade method

Modified Paths:
--------------
    scummvm/trunk/engines/gob/draw_v2.cpp
    scummvm/trunk/engines/gob/surface.cpp
    scummvm/trunk/engines/gob/surface.h

Modified: scummvm/trunk/engines/gob/draw_v2.cpp
===================================================================
--- scummvm/trunk/engines/gob/draw_v2.cpp	2011-01-16 22:29:18 UTC (rev 55272)
+++ scummvm/trunk/engines/gob/draw_v2.cpp	2011-01-16 22:29:49 UTC (rev 55273)
@@ -735,10 +735,18 @@
 		break;
 
 	case DRAW_FILLRECT:
-		_spritesArray[_destSurface]->fillRect(destSpriteX,
-				_destSpriteY, _destSpriteX + _spriteRight - 1,
-				_destSpriteY + _spriteBottom - 1, getColor(_backColor));
+		if (!(_backColor & 0xFF00) || !(_backColor & 0x0100)) {
+			_spritesArray[_destSurface]->fillRect(destSpriteX,
+					_destSpriteY, _destSpriteX + _spriteRight - 1,
+					_destSpriteY + _spriteBottom - 1, getColor(_backColor));
+		} else {
+			uint8 strength = 16 - (((uint16) _backColor) >> 12);
 
+			_spritesArray[_destSurface]->shadeRect(destSpriteX,
+					_destSpriteY, _destSpriteX + _spriteRight - 1,
+					_destSpriteY + _spriteBottom - 1, getColor(_backColor), strength);
+		}
+
 		dirtiedRect(_destSurface, _destSpriteX, _destSpriteY,
 				_destSpriteX + _spriteRight - 1, _destSpriteY + _spriteBottom - 1);
 		break;

Modified: scummvm/trunk/engines/gob/surface.cpp
===================================================================
--- scummvm/trunk/engines/gob/surface.cpp	2011-01-16 22:29:18 UTC (rev 55272)
+++ scummvm/trunk/engines/gob/surface.cpp	2011-01-16 22:29:49 UTC (rev 55273)
@@ -489,6 +489,61 @@
 	fill(0);
 }
 
+void Surface::shadeRect(uint16 left, uint16 top, uint16 right, uint16 bottom,
+		uint32 color, uint8 strength) {
+
+	if (_bpp == 1) {
+		// We can't properly shade in paletted mode, fill the rect instead
+		fillRect(left, top, right, bottom, color);
+		return;
+	}
+
+	// Just in case those are swapped
+	if (left > right)
+		SWAP(left, right);
+	if (top  > bottom)
+		SWAP(top, bottom);
+
+	if ((left >= _width) || (top >= _height))
+		// Nothing to do
+		return;
+
+	// Area to actually shade
+	uint16 width  = CLIP<int32>(right  - left + 1, 0, _width  - left);
+	uint16 height = CLIP<int32>(bottom - top  + 1, 0, _height - top);
+
+	if ((width == 0) || (height == 0))
+		// Nothing to do
+		return;
+
+	Graphics::PixelFormat pixelFormat = g_system->getScreenFormat();
+
+	uint8 cR, cG, cB;
+	pixelFormat.colorToRGB(color, cR, cG, cB);
+
+	int shadeR = cR * (16 - strength);
+	int shadeG = cG * (16 - strength);
+	int shadeB = cB * (16 - strength);
+
+	Pixel p = get(left, top);
+	while (height-- > 0) {
+		for (uint16 i = 0; i < width; i++, ++p) {
+			uint8 r, g, b;
+
+			pixelFormat.colorToRGB(p.get(), r, g, b);
+
+			r = CLIP<int>((shadeR + strength * r) >> 4, 0, 255);
+			g = CLIP<int>((shadeG + strength * g) >> 4, 0, 255);
+			b = CLIP<int>((shadeB + strength * b) >> 4, 0, 255);
+
+			p.set(pixelFormat.RGBToColor(r, g, b));
+		}
+
+		p += _width - width;
+	}
+
+}
+
 void Surface::putPixel(uint16 x, uint16 y, uint32 color) {
 	if ((x >= _width) || (y >= _height))
 		return;

Modified: scummvm/trunk/engines/gob/surface.h
===================================================================
--- scummvm/trunk/engines/gob/surface.h	2011-01-16 22:29:18 UTC (rev 55272)
+++ scummvm/trunk/engines/gob/surface.h	2011-01-16 22:29:49 UTC (rev 55273)
@@ -108,6 +108,9 @@
 	void fill(uint32 color);
 	void clear();
 
+	void shadeRect(uint16 left, uint16 top, uint16 right, uint16 bottom,
+			uint32 color, uint8 strength);
+
 	void putPixel(uint16 x, uint16 y, uint32 color);
 	void drawLine(uint16 x0, uint16 y0, uint16 x1, uint16 y1, uint32 color);
 	void drawCircle(uint16 x0, uint16 y0, uint16 radius, uint32 color, int16 pattern = 0);


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