[Scummvm-cvs-logs] SF.net SVN: scummvm:[35993] scummvm/trunk

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Thu Jan 22 05:35:10 CET 2009


Revision: 35993
          http://scummvm.svn.sourceforge.net/scummvm/?rev=35993&view=rev
Author:   fingolfin
Date:     2009-01-22 04:35:10 +0000 (Thu, 22 Jan 2009)

Log Message:
-----------
Moved Graphics::PixelFormat into its own header file; turned RGBToColor etc. into methods, and added an operator==

Modified Paths:
--------------
    scummvm/trunk/backends/platform/sdl/graphics.cpp
    scummvm/trunk/backends/vkeybd/virtual-keyboard-parser.cpp
    scummvm/trunk/common/system.h
    scummvm/trunk/engines/sword1/animation.cpp
    scummvm/trunk/engines/sword2/animation.cpp
    scummvm/trunk/graphics/colormasks.h
    scummvm/trunk/graphics/imagedec.cpp
    scummvm/trunk/graphics/thumbnail.cpp
    scummvm/trunk/graphics/video/mpeg_player.cpp
    scummvm/trunk/gui/ThemeEngine.cpp
    scummvm/trunk/gui/widget.cpp

Added Paths:
-----------
    scummvm/trunk/graphics/pixelformat.h

Modified: scummvm/trunk/backends/platform/sdl/graphics.cpp
===================================================================
--- scummvm/trunk/backends/platform/sdl/graphics.cpp	2009-01-21 23:28:17 UTC (rev 35992)
+++ scummvm/trunk/backends/platform/sdl/graphics.cpp	2009-01-22 04:35:10 UTC (rev 35993)
@@ -410,12 +410,6 @@
 	// Create the surface used for the graphics in 16 bit before scaling, and also the overlay
 	//
 
-	// Distinguish 555 and 565 mode
-	if (_hwscreen->format->Rmask == 0x7C00)
-		InitScalers(555);
-	else
-		InitScalers(565);
-
 	// Need some extra bytes around when using 2xSaI
 	_tmpscreen = SDL_CreateRGBSurface(SDL_SWSURFACE, _videoMode.screenWidth + 3, _videoMode.screenHeight + 3,
 						16,
@@ -479,6 +473,12 @@
 	_km.delay_time = 25;
 	_km.last_time = 0;
 
+	// Distinguish 555 and 565 mode
+	if (_hwscreen->format->Rmask == 0x7C00)
+		InitScalers(555);
+	else
+		InitScalers(565);
+
 	return true;
 }
 

Modified: scummvm/trunk/backends/vkeybd/virtual-keyboard-parser.cpp
===================================================================
--- scummvm/trunk/backends/vkeybd/virtual-keyboard-parser.cpp	2009-01-21 23:28:17 UTC (rev 35992)
+++ scummvm/trunk/backends/vkeybd/virtual-keyboard-parser.cpp	2009-01-22 04:35:10 UTC (rev 35993)
@@ -273,7 +273,7 @@
 		g = 0;
 		b = 255;
 	}
-	_mode->transparentColor = Graphics::RGBToColor(r, g, b, format);
+	_mode->transparentColor = format.RGBToColor(r, g, b);
 
 	if (node->values.contains("display_font_color")) {
 		if (!parseIntegerKey(node->values["display_font_color"].c_str(), 3, &r, &g, &b))
@@ -281,7 +281,7 @@
 	} else {
 		r = g = b = 0; // default to black
 	}
-	_mode->displayFontColor = Graphics::RGBToColor(r, g, b, format);
+	_mode->displayFontColor = format.RGBToColor(r, g, b);
 
 	_layoutParsed = true;
 

Modified: scummvm/trunk/common/system.h
===================================================================
--- scummvm/trunk/common/system.h	2009-01-21 23:28:17 UTC (rev 35992)
+++ scummvm/trunk/common/system.h	2009-01-22 04:35:10 UTC (rev 35993)
@@ -31,7 +31,7 @@
 #include "common/noncopyable.h"
 #include "common/rect.h"
 
-#include "graphics/colormasks.h"
+#include "graphics/pixelformat.h"
 
 namespace Audio {
 	class Mixer;

Modified: scummvm/trunk/engines/sword1/animation.cpp
===================================================================
--- scummvm/trunk/engines/sword1/animation.cpp	2009-01-21 23:28:17 UTC (rev 35992)
+++ scummvm/trunk/engines/sword1/animation.cpp	2009-01-22 04:35:10 UTC (rev 35993)
@@ -544,7 +544,7 @@
 		_introPal = (OverlayColor *)malloc(256 * sizeof(OverlayColor));
 		Graphics::PixelFormat format = _system->getOverlayFormat();
 		for (uint16 cnt = 0; cnt < 256; cnt++)
-			_introPal[cnt] = Graphics::RGBToColor(pal[cnt * 3 + 0], pal[cnt * 3 + 1], pal[cnt * 3 + 2], format);
+			_introPal[cnt] = format.RGBToColor(pal[cnt * 3 + 0], pal[cnt * 3 + 1], pal[cnt * 3 + 2]);
 	}
 
 	return true;

Modified: scummvm/trunk/engines/sword2/animation.cpp
===================================================================
--- scummvm/trunk/engines/sword2/animation.cpp	2009-01-21 23:28:17 UTC (rev 35992)
+++ scummvm/trunk/engines/sword2/animation.cpp	2009-01-22 04:35:10 UTC (rev 35993)
@@ -670,8 +670,8 @@
 	OverlayColor *dst = _overlay + textY * moviePitch + textX;
 
 	Graphics::PixelFormat format = _sys->getOverlayFormat();
-	OverlayColor pen = Graphics::RGBToColor(255, 255, 255, format);
-	OverlayColor border = Graphics::RGBToColor(0, 0, 0, format);
+	OverlayColor pen = format.RGBToColor(255, 255, 255);
+	OverlayColor border = format.RGBToColor(0, 0, 0);
 
 	// TODO: Use the AdvMame scalers for the text? Pre-scale it?
 
@@ -719,7 +719,7 @@
 	memset(_vm->_screen->getScreen(), 0, _movieWidth * _movieHeight);
 #else
 	Graphics::PixelFormat format = _sys->getOverlayFormat();
-	OverlayColor black = Graphics::RGBToColor(0, 0, 0, format);
+	OverlayColor black = format.RGBToColor(0, 0, 0);
 
 	for (int i = 0; i < _movieScale * _movieWidth * _movieScale * _movieHeight; i++)
 		_overlay[i] = black;

Modified: scummvm/trunk/graphics/colormasks.h
===================================================================
--- scummvm/trunk/graphics/colormasks.h	2009-01-21 23:28:17 UTC (rev 35992)
+++ scummvm/trunk/graphics/colormasks.h	2009-01-22 04:35:10 UTC (rev 35993)
@@ -26,6 +26,8 @@
 #ifndef GRAPHICS_COLORMASKS_H
 #define GRAPHICS_COLORMASKS_H
 
+#include "graphics/pixelformat.h"
+
 namespace Graphics {
 
 template<int bitFormat>
@@ -81,7 +83,7 @@
 		kGreenBits  = 6,
 		kBlueBits   = 5,
 
-		kAlphaShift = kRedBits+kGreenBits+kBlueBits,
+		kAlphaShift = 0,
 		kRedShift   = kGreenBits+kBlueBits,
 		kGreenShift = kBlueBits,
 		kBlueShift  = 0,
@@ -112,7 +114,7 @@
 		kGreenBits  = 5,
 		kBlueBits   = 5,
 
-		kAlphaShift = kRedBits+kGreenBits+kBlueBits,
+		kAlphaShift = 0,
 		kRedShift   = kGreenBits+kBlueBits,
 		kGreenShift = kBlueBits,
 		kBlueShift  = 0,
@@ -184,7 +186,7 @@
 		kGreenBits  = 8,
 		kBlueBits   = 8,
 
-		kAlphaShift = kRedBits+kGreenBits+kBlueBits,
+		kAlphaShift = 0,
 		kRedShift   = kGreenBits+kBlueBits,
 		kGreenShift = kBlueBits,
 		kBlueShift  = 0,
@@ -253,27 +255,12 @@
 	b = ((color & T::kBlueMask) >> T::kBlueShift) << (8 - T::kBlueBits);
 }
 
-/**
- * A pixel format description.
- *
- * Like ColorMasks it includes the given values to create colors from RGB
- * values and to retrieve RGB values from colors.
- *
- * Unlike ColorMasks it is not dependend on knowing the exact pixel format
- * on compile time.
- *
- * A minor difference between ColorMasks and PixelFormat is that ColorMasks
- * stores the bit count per channel in 'kFooBits', while PixelFormat stores
- * the loss compared to 8 bits per channel in '#Loss'. It also doesn't
- * contain mask values.
- */
-struct PixelFormat {
-	byte bytesPerPixel; /**< Number of bytes used in the pixel format. */
 
-	byte rLoss, gLoss, bLoss, aLoss; /**< Precision loss of each color component. */
-	byte rShift, gShift, bShift, aShift; /**< Binary left shift of each color component in the pixel value. */
-};
 
+/**
+ * Convert a 'bitFormat' as defined by one of the ColorMasks
+ * into a PixelFormat.
+ */
 template<int bitFormat>
 PixelFormat createPixelFormat() {
 	PixelFormat format;
@@ -293,35 +280,7 @@
 	return format;
 }
 
-inline uint32 RGBToColor(uint8 r, uint8 g, uint8 b, const PixelFormat &fmt) {
-	return
-		((0xFF >> fmt.aLoss) << fmt.aShift) |
-		((   r >> fmt.rLoss) << fmt.rShift) |
-		((   g >> fmt.gLoss) << fmt.gShift) |
-		((   b >> fmt.bLoss) << fmt.bShift);
-}
 
-inline uint32 ARGBToColor(uint8 a, uint8 r, uint8 g, uint8 b, const PixelFormat &fmt) {
-	return
-		((a >> fmt.aLoss) << fmt.aShift) |
-		((r >> fmt.rLoss) << fmt.rShift) |
-		((g >> fmt.gLoss) << fmt.gShift) |
-		((b >> fmt.bLoss) << fmt.bShift);
-}
-
-inline void colorToRGB(uint32 color, uint8 &r, uint8 &g, uint8 &b, const PixelFormat &fmt) {
-	r = ((color >> fmt.rShift) << fmt.rLoss) & 0xFF;
-	g = ((color >> fmt.gShift) << fmt.gLoss) & 0xFF;
-	b = ((color >> fmt.bShift) << fmt.bLoss) & 0xFF;
-}
-
-inline void colorToARGB(uint32 color, uint8 &a, uint8 &r, uint8 &g, uint8 &b, const PixelFormat &fmt) {
-	a = ((color >> fmt.aShift) << fmt.aLoss) & 0xFF;
-	r = ((color >> fmt.rShift) << fmt.rLoss) & 0xFF;
-	g = ((color >> fmt.gShift) << fmt.gLoss) & 0xFF;
-	b = ((color >> fmt.bShift) << fmt.bLoss) & 0xFF;
-}
-
 } // end of namespace Graphics
 
 #endif

Modified: scummvm/trunk/graphics/imagedec.cpp
===================================================================
--- scummvm/trunk/graphics/imagedec.cpp	2009-01-21 23:28:17 UTC (rev 35992)
+++ scummvm/trunk/graphics/imagedec.cpp	2009-01-22 04:35:10 UTC (rev 35993)
@@ -127,7 +127,7 @@
 			b = stream.readByte();
 			g = stream.readByte();
 			r = stream.readByte();
-			*curPixel = RGBToColor(r, g, b, overlayFormat);
+			*curPixel = overlayFormat.RGBToColor(r, g, b);
 			++curPixel;
 		}
 		stream.seek(pitchAdd, SEEK_CUR);

Added: scummvm/trunk/graphics/pixelformat.h
===================================================================
--- scummvm/trunk/graphics/pixelformat.h	                        (rev 0)
+++ scummvm/trunk/graphics/pixelformat.h	2009-01-22 04:35:10 UTC (rev 35993)
@@ -0,0 +1,89 @@
+/* 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_PIXELFORMAT_H
+#define GRAPHICS_PIXELFORMAT_H
+
+namespace Graphics {
+
+
+/**
+ * A pixel format description.
+ *
+ * Like ColorMasks it includes the given values to create colors from RGB
+ * values and to retrieve RGB values from colors.
+ *
+ * Unlike ColorMasks it is not dependend on knowing the exact pixel format
+ * on compile time.
+ *
+ * A minor difference between ColorMasks and PixelFormat is that ColorMasks
+ * stores the bit count per channel in 'kFooBits', while PixelFormat stores
+ * the loss compared to 8 bits per channel in '#Loss'. It also doesn't
+ * contain mask values.
+ */
+struct PixelFormat {
+	byte bytesPerPixel; /**< Number of bytes used in the pixel format. */
+
+	byte rLoss, gLoss, bLoss, aLoss; /**< Precision loss of each color component. */
+	byte rShift, gShift, bShift, aShift; /**< Binary left shift of each color component in the pixel value. */
+
+	inline bool operator==(const PixelFormat &fmt) const {
+		// TODO: If aLoss==8, then the value of aShift is irrelevant, and should be ignored.
+		return 0 == memcmp(this, &fmt, sizeof(PixelFormat));
+	}
+
+	inline uint32 RGBToColor(uint8 r, uint8 g, uint8 b) const {
+		return
+			((0xFF >> aLoss) << aShift) |
+			((   r >> rLoss) << rShift) |
+			((   g >> gLoss) << gShift) |
+			((   b >> bLoss) << bShift);
+	}
+
+	inline uint32 ARGBToColor(uint8 a, uint8 r, uint8 g, uint8 b) const {
+		return
+			((a >> aLoss) << aShift) |
+			((r >> rLoss) << rShift) |
+			((g >> gLoss) << gShift) |
+			((b >> bLoss) << bShift);
+	}
+
+	inline void colorToRGB(uint32 color, uint8 &r, uint8 &g, uint8 &b) const {
+		r = ((color >> rShift) << rLoss) & 0xFF;
+		g = ((color >> gShift) << gLoss) & 0xFF;
+		b = ((color >> bShift) << bLoss) & 0xFF;
+	}
+
+	inline void colorToARGB(uint32 color, uint8 &a, uint8 &r, uint8 &g, uint8 &b) const {
+		a = ((color >> aShift) << aLoss) & 0xFF;
+		r = ((color >> rShift) << rLoss) & 0xFF;
+		g = ((color >> gShift) << gLoss) & 0xFF;
+		b = ((color >> bShift) << bLoss) & 0xFF;
+	}
+};
+
+} // end of namespace Graphics
+
+#endif


Property changes on: scummvm/trunk/graphics/pixelformat.h
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Rev Author URL Id
Added: svn:eol-style
   + native

Modified: scummvm/trunk/graphics/thumbnail.cpp
===================================================================
--- scummvm/trunk/graphics/thumbnail.cpp	2009-01-21 23:28:17 UTC (rev 35992)
+++ scummvm/trunk/graphics/thumbnail.cpp	2009-01-22 04:35:10 UTC (rev 35993)
@@ -24,6 +24,7 @@
 
 #include "graphics/thumbnail.h"
 #include "graphics/scaler.h"
+#include "graphics/colormasks.h"
 #include "common/endian.h"
 #include "common/system.h"
 
@@ -115,7 +116,7 @@
 			colorToRGB<ColorMasks<565> >(in.readUint16BE(), r, g, b);
 
 			// converting to current OSystem Color
-			*pixels++ = Graphics::RGBToColor(r, g, b, format);
+			*pixels++ = format.RGBToColor(r, g, b);
 		}
 	}
 

Modified: scummvm/trunk/graphics/video/mpeg_player.cpp
===================================================================
--- scummvm/trunk/graphics/video/mpeg_player.cpp	2009-01-21 23:28:17 UTC (rev 35992)
+++ scummvm/trunk/graphics/video/mpeg_player.cpp	2009-01-22 04:35:10 UTC (rev 35993)
@@ -391,9 +391,9 @@
 	// Set up entries 0-255 in rgb-to-pixel value tables.
 	Graphics::PixelFormat format = _sys->getOverlayFormat();
 	for (i = 0; i < 256; i++) {
-		r_2_pix_alloc[i + 256] = Graphics::RGBToColor(i, 0, 0, format);
-		g_2_pix_alloc[i + 256] = Graphics::RGBToColor(0, i, 0, format);
-		b_2_pix_alloc[i + 256] = Graphics::RGBToColor(0, 0, i, format);
+		r_2_pix_alloc[i + 256] = format.RGBToColor(i, 0, 0);
+		g_2_pix_alloc[i + 256] = format.RGBToColor(0, i, 0);
+		b_2_pix_alloc[i + 256] = format.RGBToColor(0, 0, i);
 	}
 
 	// Spread out the values we have to the rest of the array so that we do

Modified: scummvm/trunk/gui/ThemeEngine.cpp
===================================================================
--- scummvm/trunk/gui/ThemeEngine.cpp	2009-01-21 23:28:17 UTC (rev 35992)
+++ scummvm/trunk/gui/ThemeEngine.cpp	2009-01-22 04:35:10 UTC (rev 35993)
@@ -1041,7 +1041,7 @@
 	charArea.clip(_screen.w, _screen.h);
 
 	Graphics::PixelFormat format = _system->getOverlayFormat();
-	uint32 color = Graphics::RGBToColor(_texts[kTextDataDefault]->_color.r, _texts[kTextDataDefault]->_color.g, _texts[kTextDataDefault]->_color.b, format);
+	uint32 color = format.RGBToColor(_texts[kTextDataDefault]->_color.r, _texts[kTextDataDefault]->_color.g, _texts[kTextDataDefault]->_color.b);
 
 	restoreBackground(charArea);
 	font->drawChar(&_screen, ch, charArea.left, charArea.top, color);
@@ -1150,7 +1150,7 @@
 	for (uint y = 0; y < _cursorHeight; ++y) {
 		for (uint x = 0; x < _cursorWidth; ++x) {
 			byte r, g, b;
-			Graphics::colorToRGB(src[x], r, g, b, format);
+			format.colorToRGB(src[x], r, g, b);
 			const int col = (r << 16) | (g << 8) | b;
 
 			// Skip transparency (the transparent color actually is 0xFF00FF,

Modified: scummvm/trunk/gui/widget.cpp
===================================================================
--- scummvm/trunk/gui/widget.cpp	2009-01-21 23:28:17 UTC (rev 35992)
+++ scummvm/trunk/gui/widget.cpp	2009-01-22 04:35:10 UTC (rev 35993)
@@ -399,7 +399,7 @@
 
 	OverlayColor *dst = (OverlayColor*)_gfx.pixels;
 	Graphics::PixelFormat overlayFormat = g_system->getOverlayFormat();
-	OverlayColor fillCol = Graphics::RGBToColor(r, g, b, overlayFormat);
+	OverlayColor fillCol = overlayFormat.RGBToColor(r, g, b);
 	while (h--) {
 		for (int i = 0; i < w; ++i) {
 			*dst++ = fillCol;


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