[Scummvm-git-logs] scummvm master -> 342733cee6c9dc3db94ff88cb2278a501150bc1c

bgK bastien.bouclet at gmail.com
Sun Mar 3 13:44:14 CET 2019


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
342733cee6 SDL: Add a function to convert from SDL_PixelFormat to Graphics::PixelFormat


Commit: 342733cee6c9dc3db94ff88cb2278a501150bc1c
    https://github.com/scummvm/scummvm/commit/342733cee6c9dc3db94ff88cb2278a501150bc1c
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2019-03-03T13:44:10+01:00

Commit Message:
SDL: Add a function to convert from SDL_PixelFormat to Graphics::PixelFormat

Changed paths:
    backends/graphics/surfacesdl/surfacesdl-graphics.cpp
    backends/graphics/surfacesdl/surfacesdl-graphics.h
    backends/graphics/wincesdl/wincesdl-graphics.cpp


diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
index dd334f3..37965d0 100644
--- a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
+++ b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
@@ -493,6 +493,14 @@ static void maskToBitCount(Uint32 mask, uint8 &numBits, uint8 &shift) {
 }
 #endif
 
+Graphics::PixelFormat SurfaceSdlGraphicsManager::convertSDLPixelFormat(SDL_PixelFormat *in) const {
+	return Graphics::PixelFormat(in->BytesPerPixel,
+		8 - in->Rloss, 8 - in->Gloss,
+		8 - in->Bloss, 8 - in->Aloss,
+		in->Rshift, in->Gshift,
+		in->Bshift, in->Ashift);
+}
+
 void SurfaceSdlGraphicsManager::detectSupportedFormats() {
 	_supportedFormats.clear();
 
@@ -570,11 +578,7 @@ void SurfaceSdlGraphicsManager::detectSupportedFormats() {
 
 	if (_hwScreen) {
 		// Get our currently set hardware format
-		Graphics::PixelFormat hwFormat(_hwScreen->format->BytesPerPixel,
-			8 - _hwScreen->format->Rloss, 8 - _hwScreen->format->Gloss,
-			8 - _hwScreen->format->Bloss, 8 - _hwScreen->format->Aloss,
-			_hwScreen->format->Rshift, _hwScreen->format->Gshift,
-			_hwScreen->format->Bshift, _hwScreen->format->Ashift);
+		Graphics::PixelFormat hwFormat = convertSDLPixelFormat(_hwScreen->format);
 
 		// Workaround to SDL not providing an accurate Aloss value on Mac OS X.
 		if (_hwScreen->format->Amask == 0)
@@ -1041,17 +1045,7 @@ bool SurfaceSdlGraphicsManager::loadGFXMode() {
 	if (_overlayscreen == NULL)
 		error("allocating _overlayscreen failed");
 
-	_overlayFormat.bytesPerPixel = _overlayscreen->format->BytesPerPixel;
-
-	_overlayFormat.rLoss = _overlayscreen->format->Rloss;
-	_overlayFormat.gLoss = _overlayscreen->format->Gloss;
-	_overlayFormat.bLoss = _overlayscreen->format->Bloss;
-	_overlayFormat.aLoss = _overlayscreen->format->Aloss;
-
-	_overlayFormat.rShift = _overlayscreen->format->Rshift;
-	_overlayFormat.gShift = _overlayscreen->format->Gshift;
-	_overlayFormat.bShift = _overlayscreen->format->Bshift;
-	_overlayFormat.aShift = _overlayscreen->format->Ashift;
+	_overlayFormat = convertSDLPixelFormat(_overlayscreen->format);
 
 	_tmpscreen2 = SDL_CreateRGBSurface(SDL_SWSURFACE, _videoMode.overlayWidth + 3, _videoMode.overlayHeight + 3,
 						16,
@@ -2362,11 +2356,7 @@ void SurfaceSdlGraphicsManager::displayMessageOnOSD(const char *msg) {
 
 	Graphics::Surface dst;
 	dst.init(_osdMessageSurface->w, _osdMessageSurface->h, _osdMessageSurface->pitch, _osdMessageSurface->pixels,
-		Graphics::PixelFormat(_osdMessageSurface->format->BytesPerPixel,
-			8 - _osdMessageSurface->format->Rloss, 8 - _osdMessageSurface->format->Gloss,
-			8 - _osdMessageSurface->format->Bloss, 8 - _osdMessageSurface->format->Aloss,
-			_osdMessageSurface->format->Rshift, _osdMessageSurface->format->Gshift,
-			_osdMessageSurface->format->Bshift, _osdMessageSurface->format->Ashift));
+		convertSDLPixelFormat(_osdMessageSurface->format));
 
 	// Render the message, centered, and in white
 	for (i = 0; i < lines.size(); i++) {
diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.h b/backends/graphics/surfacesdl/surfacesdl-graphics.h
index 3866bc3..3315533 100644
--- a/backends/graphics/surfacesdl/surfacesdl-graphics.h
+++ b/backends/graphics/surfacesdl/surfacesdl-graphics.h
@@ -118,6 +118,12 @@ protected:
 	virtual void setPalette(const byte *colors, uint start, uint num) override;
 	virtual void grabPalette(byte *colors, uint start, uint num) const override;
 
+	/**
+	 * Convert from the SDL pixel format to Graphics::PixelFormat
+	 * @param in    The SDL pixel format to convert
+	 * @param out   A pixel format to be written to
+	 */
+	Graphics::PixelFormat convertSDLPixelFormat(SDL_PixelFormat *in) const;
 public:
 	virtual void copyRectToScreen(const void *buf, int pitch, int x, int y, int w, int h) override;
 	virtual Graphics::Surface *lockScreen() override;
diff --git a/backends/graphics/wincesdl/wincesdl-graphics.cpp b/backends/graphics/wincesdl/wincesdl-graphics.cpp
index 1677eca..8e51f43 100644
--- a/backends/graphics/wincesdl/wincesdl-graphics.cpp
+++ b/backends/graphics/wincesdl/wincesdl-graphics.cpp
@@ -883,15 +883,8 @@ bool WINCESdlGraphicsManager::loadGFXMode() {
 		InitScalers(555);
 	else
 		InitScalers(565);
-	_overlayFormat.bytesPerPixel = _hwscreen->format->BytesPerPixel;
-	_overlayFormat.rLoss = _hwscreen->format->Rloss;
-	_overlayFormat.gLoss = _hwscreen->format->Gloss;
-	_overlayFormat.bLoss = _hwscreen->format->Bloss;
-	_overlayFormat.aLoss = _hwscreen->format->Aloss;
-	_overlayFormat.rShift = _hwscreen->format->Rshift;
-	_overlayFormat.gShift = _hwscreen->format->Gshift;
-	_overlayFormat.bShift = _hwscreen->format->Bshift;
-	_overlayFormat.aShift = _hwscreen->format->Ashift;
+
+	_overlayFormat = convertSDLPixelFormat(_hwscreen->format);
 
 	// Need some extra bytes around when using 2xSaI
 	_tmpscreen = SDL_CreateRGBSurface(SDL_SWSURFACE, _videoMode.screenWidth + 3, _videoMode.screenHeight + 3, 16, _hwscreen->format->Rmask, _hwscreen->format->Gmask, _hwscreen->format->Bmask, _hwscreen->format->Amask);





More information about the Scummvm-git-logs mailing list