[Scummvm-git-logs] scummvm master -> f2d857a882582d2f785345d0a5e6518eb89bb71f

ccawley2011 noreply at scummvm.org
Wed Jan 11 12:57:57 UTC 2023


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

Summary:
cf70814cbd SURFACESDL: Initial support for 32-bit screen output
f2d857a882 GRAPHICS: Support more pixel formats with the HQ2x and HQ3x scalers


Commit: cf70814cbd91f5bafd3dcc152ad2d5c381ac35ff
    https://github.com/scummvm/scummvm/commit/cf70814cbd91f5bafd3dcc152ad2d5c381ac35ff
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2023-01-11T12:57:53Z

Commit Message:
SURFACESDL: Initial support for 32-bit screen output

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


diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
index 28b5a044bac..93cbecd3d59 100644
--- a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
+++ b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
@@ -125,7 +125,7 @@ SurfaceSdlGraphicsManager::SurfaceSdlGraphicsManager(SdlEventSource *sdlEventSou
 	_useOldSrc(false),
 	_overlayscreen(nullptr), _tmpscreen2(nullptr),
 	_screenChangeCount(0),
-	_mouseData(nullptr), _mouseSurface(nullptr),
+	_mouseSurface(nullptr), _mouseScaler(nullptr),
 	_mouseOrigSurface(nullptr), _cursorDontScale(false), _cursorPaletteDisabled(true),
 	_currentShakeXOffset(0), _currentShakeYOffset(0),
 	_paletteDirtyStart(0), _paletteDirtyEnd(0),
@@ -183,7 +183,6 @@ SurfaceSdlGraphicsManager::~SurfaceSdlGraphicsManager() {
 	}
 	free(_currentPalette);
 	free(_cursorPalette);
-	delete[] _mouseData;
 }
 
 bool SurfaceSdlGraphicsManager::hasFeature(OSystem::Feature f) const {
@@ -837,7 +836,7 @@ bool SurfaceSdlGraphicsManager::loadGFXMode() {
 	setupHardwareSize();
 
 	//
-	// Create the surface that contains the 8 bit game data
+	// Create the surface that contains the game data
 	//
 
 	const Graphics::PixelFormat &format = _screenFormat;
@@ -919,7 +918,7 @@ bool SurfaceSdlGraphicsManager::loadGFXMode() {
 	// Need some extra bytes around when using 2xSaI
 	_tmpscreen = SDL_CreateRGBSurface(SDL_SWSURFACE, _videoMode.screenWidth + _maxExtraPixels * 2,
 						_videoMode.screenHeight + _maxExtraPixels * 2,
-						16,
+						_hwScreen->format->BitsPerPixel,
 						_hwScreen->format->Rmask,
 						_hwScreen->format->Gmask,
 						_hwScreen->format->Bmask,
@@ -935,7 +934,7 @@ bool SurfaceSdlGraphicsManager::loadGFXMode() {
 	}
 
 	_overlayscreen = SDL_CreateRGBSurface(SDL_SWSURFACE, _videoMode.overlayWidth, _videoMode.overlayHeight,
-						16,
+						_hwScreen->format->BitsPerPixel,
 						_hwScreen->format->Rmask,
 						_hwScreen->format->Gmask,
 						_hwScreen->format->Bmask,
@@ -948,7 +947,7 @@ bool SurfaceSdlGraphicsManager::loadGFXMode() {
 
 	_tmpscreen2 = SDL_CreateRGBSurface(SDL_SWSURFACE, _videoMode.overlayWidth + _maxExtraPixels * 2,
 						_videoMode.overlayHeight + _maxExtraPixels * 2,
-						16,
+						_hwScreen->format->BitsPerPixel,
 						_hwScreen->format->Rmask,
 						_hwScreen->format->Gmask,
 						_hwScreen->format->Bmask,
@@ -1161,7 +1160,7 @@ void SurfaceSdlGraphicsManager::internUpdateScreen() {
 	// we have to redraw the mouse, or if the cursor is alpha-blended since
 	// alpha-blended cursors will happily blend into themselves if the surface
 	// under the cursor is not reset first
-	if (_cursorNeedsRedraw || _cursorFormat.bytesPerPixel == 4)
+	if (_cursorNeedsRedraw || _cursorFormat.aBits() > 1)
 		undrawMouse();
 
 #ifdef USE_OSD
@@ -1182,7 +1181,7 @@ void SurfaceSdlGraphicsManager::internUpdateScreen() {
 	if (_numDirtyRects > 0 || _cursorNeedsRedraw) {
 		SDL_Rect *r;
 		SDL_Rect dst;
-		uint32 srcPitch, dstPitch;
+		uint32 bpp, srcPitch, dstPitch;
 		SDL_Rect *lastRect = _dirtyRectList + _numDirtyRects;
 
 		for (r = _dirtyRectList; r != lastRect; ++r) {
@@ -1197,6 +1196,7 @@ void SurfaceSdlGraphicsManager::internUpdateScreen() {
 		SDL_LockSurface(srcSurf);
 		SDL_LockSurface(_hwScreen);
 
+		bpp = _hwScreen->format->BytesPerPixel;
 		srcPitch = srcSurf->pitch;
 		dstPitch = _hwScreen->pitch;
 
@@ -1227,8 +1227,8 @@ void SurfaceSdlGraphicsManager::internUpdateScreen() {
 				if (_videoMode.aspectRatioCorrection && !_overlayInGUI)
 					dst_y = real2Aspect(dst_y);
 
-				_scaler->scale((byte *)srcSurf->pixels + (r->x + _maxExtraPixels) * 2 + (r->y + _maxExtraPixels) * srcPitch, srcPitch,
-					(byte *)_hwScreen->pixels + dst_x * 2 + dst_y * dstPitch, dstPitch, r->w, dst_h, r->x, r->y);
+				_scaler->scale((byte *)srcSurf->pixels + (r->x + _maxExtraPixels) * bpp + (r->y + _maxExtraPixels) * srcPitch, srcPitch,
+					(byte *)_hwScreen->pixels + dst_x * bpp + dst_y * dstPitch, dstPitch, r->w, dst_h, r->x, r->y);
 			}
 
 			r->x = dst_x;
@@ -1702,7 +1702,7 @@ void SurfaceSdlGraphicsManager::clearOverlay() {
 	SDL_LockSurface(_tmpscreen);
 	SDL_LockSurface(_overlayscreen);
 
-	_scaler->scale((byte *)(_tmpscreen->pixels) + _maxExtraPixels * _tmpscreen->pitch + _maxExtraPixels * 2, _tmpscreen->pitch,
+	_scaler->scale((byte *)(_tmpscreen->pixels) + _maxExtraPixels * _tmpscreen->pitch + _maxExtraPixels * _tmpscreen->format->BytesPerPixel, _tmpscreen->pitch,
 	(byte *)_overlayscreen->pixels, _overlayscreen->pitch, _videoMode.screenWidth, _videoMode.screenHeight, 0, 0);
 
 #ifdef USE_ASPECT
@@ -1728,12 +1728,12 @@ void SurfaceSdlGraphicsManager::grabOverlay(Graphics::Surface &surface) const {
 
 	assert(surface.w >= _videoMode.overlayWidth);
 	assert(surface.h >= _videoMode.overlayHeight);
-	assert(surface.format.bytesPerPixel == 2);
+	assert(surface.format.bytesPerPixel == _overlayFormat.bytesPerPixel);
 
 	byte *src = (byte *)_overlayscreen->pixels;
 	byte *dst = (byte *)surface.getPixels();
 	Graphics::copyBlit(dst, src, surface.pitch, _overlayscreen->pitch,
-		_videoMode.overlayWidth, _videoMode.overlayHeight, 2);
+		_videoMode.overlayWidth, _videoMode.overlayHeight, _overlayFormat.bytesPerPixel);
 
 	SDL_UnlockSurface(_overlayscreen);
 }
@@ -1745,11 +1745,12 @@ void SurfaceSdlGraphicsManager::copyRectToOverlay(const void *buf, int pitch, in
 		return;
 
 	const byte *src = (const byte *)buf;
+	uint bpp = _overlayscreen->format->BytesPerPixel;
 
 	// Clip the coordinates
 	if (x < 0) {
 		w += x;
-		src -= x * 2;
+		src -= x * bpp;
 		x = 0;
 	}
 
@@ -1776,9 +1777,9 @@ void SurfaceSdlGraphicsManager::copyRectToOverlay(const void *buf, int pitch, in
 	if (SDL_LockSurface(_overlayscreen) == -1)
 		error("SDL_LockSurface failed: %s", SDL_GetError());
 
-	byte *dst = (byte *)_overlayscreen->pixels + y * _overlayscreen->pitch + x * 2;
+	byte *dst = (byte *)_overlayscreen->pixels + y * _overlayscreen->pitch + x * bpp;
 	do {
-		memcpy(dst, src, w * 2);
+		memcpy(dst, src, w * bpp);
 		dst += _overlayscreen->pitch;
 		src += pitch;
 	} while (--h);
@@ -1820,7 +1821,7 @@ void SurfaceSdlGraphicsManager::setMouseCursor(const void *buf, uint w, uint h,
 
 	_cursorDontScale = dontScale;
 
-	if (_mouseCurState.w != (int)w || _mouseCurState.h != (int)h || formatChanged) {
+	if (_mouseCurState.w != (int)w || _mouseCurState.h != (int)h || formatChanged || !_mouseOrigSurface) {
 		_mouseCurState.w = w;
 		_mouseCurState.h = h;
 
@@ -1834,7 +1835,7 @@ void SurfaceSdlGraphicsManager::setMouseCursor(const void *buf, uint w, uint h,
 			_mouseOrigSurface = nullptr;
 		}
 
-		if ((formatChanged || _cursorFormat.bytesPerPixel == 4) && _mouseSurface) {
+		if (formatChanged && _mouseSurface) {
 			SDL_FreeSurface(_mouseSurface);
 			_mouseSurface = nullptr;
 		}
@@ -1843,48 +1844,42 @@ void SurfaceSdlGraphicsManager::setMouseCursor(const void *buf, uint w, uint h,
 			return;
 		}
 
-		if (_cursorFormat.bytesPerPixel == 4) {
-			assert(!_mouseSurface);
-			assert(!_mouseOrigSurface);
+		assert(!_mouseOrigSurface);
 
-			const Uint32 rMask = ((0xFF >> format->rLoss) << format->rShift);
-			const Uint32 gMask = ((0xFF >> format->gLoss) << format->gShift);
-			const Uint32 bMask = ((0xFF >> format->bLoss) << format->bShift);
-			const Uint32 aMask = ((0xFF >> format->aLoss) << format->aShift);
-			_mouseSurface = _mouseOrigSurface = SDL_CreateRGBSurfaceFrom(const_cast<void *>(buf), w, h, format->bytesPerPixel * 8, w * format->bytesPerPixel, rMask, gMask, bMask, aMask);
-		} else {
-			assert(!_mouseOrigSurface);
-
-			// Allocate bigger surface because scalers will read past the boudaries.
-			_mouseOrigSurface = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA,
-							_mouseCurState.w + _maxExtraPixels * 2,
-							_mouseCurState.h + _maxExtraPixels * 2,
-							16,
-							_hwScreen->format->Rmask,
-							_hwScreen->format->Gmask,
-							_hwScreen->format->Bmask,
-							_hwScreen->format->Amask);
-		}
+		// Allocate bigger surface because scalers will read past the boudaries.
+		_mouseOrigSurface = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA,
+						_mouseCurState.w + _maxExtraPixels * 2,
+						_mouseCurState.h + _maxExtraPixels * 2,
+						_cursorFormat.bytesPerPixel * 8,
+						((0xFF >> _cursorFormat.rLoss) << _cursorFormat.rShift),
+						((0xFF >> _cursorFormat.gLoss) << _cursorFormat.gShift),
+						((0xFF >> _cursorFormat.bLoss) << _cursorFormat.bShift),
+						((0xFF >> _cursorFormat.aLoss) << _cursorFormat.aShift));
 
 		if (_mouseOrigSurface == nullptr) {
 			error("Allocating _mouseOrigSurface failed");
 		}
 
-		if (_cursorFormat.bytesPerPixel == 4) {
-			SDL_SetColorKey(_mouseOrigSurface, SDL_SRCCOLORKEY | SDL_SRCALPHA, _mouseKeyColor);
-		} else {
-			SDL_SetColorKey(_mouseOrigSurface, SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA, kMouseColorKey);
+#ifdef USE_SCALERS
+		if (_mouseScaler != nullptr) {
+			delete _mouseScaler;
+			_mouseScaler = nullptr;
 		}
+		if (_scalerPlugin) {
+			_mouseScaler = _scalerPlugin->createInstance(_cursorFormat);
+		}
+#endif
 	}
 
-	delete[] _mouseData;
-	if (_cursorFormat.bytesPerPixel == 4) {
-		_mouseData = nullptr;
-	} else {
-		_mouseData = new byte[w * h * _cursorFormat.bytesPerPixel];
-		assert(_mouseData);
-		memcpy(_mouseData, buf, w * h * _cursorFormat.bytesPerPixel);
-	}
+	SDL_SetColorKey(_mouseOrigSurface, SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA, _mouseKeyColor);
+
+	SDL_LockSurface(_mouseOrigSurface);
+
+	// Draw from [_maxExtraPixels,_maxExtraPixels] since scalers will read past boudaries
+	Graphics::copyBlit((byte *)_mouseOrigSurface->pixels + _mouseOrigSurface->pitch * _maxExtraPixels + _maxExtraPixels * _mouseOrigSurface->format->BytesPerPixel,
+	                   (const byte *)buf, _mouseOrigSurface->pitch, w * _cursorFormat.bytesPerPixel, w, h, _cursorFormat.bytesPerPixel);
+
+	SDL_UnlockSurface(_mouseOrigSurface);
 
 	blitCursor();
 }
@@ -1897,7 +1892,7 @@ void SurfaceSdlGraphicsManager::blitCursor() {
 		return;
 	}
 
-	if (_cursorFormat.bytesPerPixel != 4 && !_mouseData) {
+	if (!_mouseOrigSurface) {
 		return;
 	}
 
@@ -1942,107 +1937,6 @@ void SurfaceSdlGraphicsManager::blitCursor() {
 		sizeChanged = true;
 	}
 
-	if (_cursorFormat.bytesPerPixel == 4) {
-		if (_mouseSurface != _mouseOrigSurface) {
-			SDL_FreeSurface(_mouseSurface);
-		}
-
-		if (cursorScale == 1) {
-			_mouseSurface = _mouseOrigSurface;
-			return;
-		}
-
-		SDL_PixelFormat *format = _mouseOrigSurface->format;
-		_mouseSurface = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_SRCCOLORKEY | SDL_SRCALPHA,
-											 rW, rH,
-											 format->BitsPerPixel,
-											 format->Rmask,
-											 format->Gmask,
-											 format->Bmask,
-											 format->Amask);
-
-		SDL_SetColorKey(_mouseSurface, SDL_SRCCOLORKEY | SDL_SRCALPHA, _mouseKeyColor);
-
-		// At least SDL 2.0.4 on Windows apparently has a broken SDL_BlitScaled
-		// implementation, and SDL 1 has no such API at all, and our other
-		// scalers operate exclusively at 16bpp, so here is a scrappy 32bpp
-		// point scaler
-		SDL_LockSurface(_mouseOrigSurface);
-		SDL_LockSurface(_mouseSurface);
-
-		const byte *src = (const byte *)_mouseOrigSurface->pixels;
-		byte *dst = (byte *)_mouseSurface->pixels;
-		for (int y = 0; y < _mouseOrigSurface->h; ++y) {
-			uint32 *rowDst = (uint32 *)dst;
-			const uint32 *rowSrc = (const uint32 *)src;
-			for (int x = 0; x < _mouseOrigSurface->w; ++x) {
-				for (int scaleX = 0; scaleX < cursorScale; ++scaleX) {
-					*rowDst++ = *rowSrc;
-				}
-				++rowSrc;
-			}
-			for (int scaleY = 0; scaleY < cursorScale - 1; ++scaleY) {
-				memcpy(dst + _mouseSurface->pitch, dst, _mouseSurface->pitch);
-				dst += _mouseSurface->pitch;
-			}
-			dst += _mouseSurface->pitch;
-			src += _mouseOrigSurface->pitch;
-		}
-
-		SDL_UnlockSurface(_mouseSurface);
-		SDL_UnlockSurface(_mouseOrigSurface);
-		return;
-	}
-
-	SDL_LockSurface(_mouseOrigSurface);
-
-	byte *dstPtr;
-	const byte *srcPtr = _mouseData;
-	uint32 color;
-
-	// Make whole surface transparent
-	for (uint i = 0; i < h + _maxExtraPixels * 2; i++) {
-		dstPtr = (byte *)_mouseOrigSurface->pixels + _mouseOrigSurface->pitch * i;
-		for (uint j = 0; j < w + _maxExtraPixels * 2; j++) {
-			*(uint16 *)dstPtr = kMouseColorKey;
-			dstPtr += _mouseOrigSurface->format->BytesPerPixel;
-		}
-	}
-
-	// Draw from [_maxExtraPixels,_maxExtraPixels] since scalers will read past boudaries
-	dstPtr = (byte *)_mouseOrigSurface->pixels + _mouseOrigSurface->pitch * _maxExtraPixels + _maxExtraPixels * _mouseOrigSurface->format->BytesPerPixel;
-
-	SDL_Color *palette;
-
-	if (_cursorPaletteDisabled)
-		palette = _currentPalette;
-	else
-		palette = _cursorPalette;
-
-	for (int i = 0; i < h; i++) {
-		for (int j = 0; j < w; j++) {
-			if (_cursorFormat.bytesPerPixel == 2) {
-				color = *(const uint16 *)srcPtr;
-				if (color != _mouseKeyColor) {
-					uint8 r, g, b;
-					_cursorFormat.colorToRGB(color, r, g, b);
-					*(uint16 *)dstPtr = SDL_MapRGB(_mouseOrigSurface->format, r, g, b);
-				}
-				dstPtr += _mouseOrigSurface->format->BytesPerPixel;
-				srcPtr += _cursorFormat.bytesPerPixel;
-			} else {
-				color = *srcPtr;
-				if (color != _mouseKeyColor) {
-					*(uint16 *)dstPtr = SDL_MapRGB(_mouseOrigSurface->format,
-						palette[color].r, palette[color].g, palette[color].b);
-				}
-				dstPtr += 2;
-				srcPtr++;
-			}
-		}
-		dstPtr += _mouseOrigSurface->pitch - w * _mouseOrigSurface->format->BytesPerPixel;
-	}
-
 	if (sizeChanged || !_mouseSurface) {
 		if (_mouseSurface)
 			SDL_FreeSurface(_mouseSurface);
@@ -2050,18 +1944,20 @@ void SurfaceSdlGraphicsManager::blitCursor() {
 		_mouseSurface = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA,
 						_mouseCurState.rW,
 						_mouseCurState.rH,
-						16,
-						_hwScreen->format->Rmask,
-						_hwScreen->format->Gmask,
-						_hwScreen->format->Bmask,
-						_hwScreen->format->Amask);
+						_mouseOrigSurface->format->BitsPerPixel,
+						_mouseOrigSurface->format->Rmask,
+						_mouseOrigSurface->format->Gmask,
+						_mouseOrigSurface->format->Bmask,
+						_mouseOrigSurface->format->Amask);
 
 		if (_mouseSurface == nullptr)
 			error("Allocating _mouseSurface failed");
-
-		SDL_SetColorKey(_mouseSurface, SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA, kMouseColorKey);
 	}
 
+	SDL_SetColors(_mouseSurface, _cursorPaletteDisabled ? _currentPalette : _cursorPalette, 0, 256);
+	SDL_SetColorKey(_mouseSurface, SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA, _mouseKeyColor);
+
+	SDL_LockSurface(_mouseOrigSurface);
 	SDL_LockSurface(_mouseSurface);
 
 	// If possible, use the same scaler for the cursor as for the rest of
@@ -2071,8 +1967,9 @@ void SurfaceSdlGraphicsManager::blitCursor() {
 #ifdef USE_SCALERS
 		// HACK: AdvMame4x requires a height of at least 4 pixels, so we
 		// fall back on the Normal scaler when a smaller cursor is supplied.
-		if (_scalerPlugin->canDrawCursor() && (uint)_mouseCurState.h >= _extraPixels) {
-			_scaler->scale(
+		if (_mouseScaler && _scalerPlugin->canDrawCursor() && (uint)_mouseCurState.h >= _extraPixels) {
+			_mouseScaler->setFactor(_videoMode.scaleFactor);
+			_mouseScaler->scale(
 					(byte *)_mouseOrigSurface->pixels + _mouseOrigSurface->pitch * _maxExtraPixels + _maxExtraPixels * _mouseOrigSurface->format->BytesPerPixel,
 					_mouseOrigSurface->pitch, (byte *)_mouseSurface->pixels, _mouseSurface->pitch,
 					_mouseCurState.w, _mouseCurState.h, 0, 0);
@@ -2231,7 +2128,7 @@ void SurfaceSdlGraphicsManager::displayMessageOnOSD(const Common::U32String &msg
 
 	_osdMessageSurface = SDL_CreateRGBSurface(
 		SDL_SWSURFACE | SDL_RLEACCEL | SDL_SRCALPHA,
-		width, height, 16, _hwScreen->format->Rmask, _hwScreen->format->Gmask, _hwScreen->format->Bmask, _hwScreen->format->Amask
+		width, height, _hwScreen->format->BitsPerPixel, _hwScreen->format->Rmask, _hwScreen->format->Gmask, _hwScreen->format->Bmask, _hwScreen->format->Amask
 	);
 
 	// Lock the surface
@@ -2624,13 +2521,15 @@ SDL_Surface *SurfaceSdlGraphicsManager::SDL_SetVideoMode(int width, int height,
 
 	SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, _videoMode.filtering ? "linear" : "nearest");
 
-	_screenTexture = SDL_CreateTexture(_renderer, SDL_PIXELFORMAT_RGB565, SDL_TEXTUREACCESS_STREAMING, width, height);
+	Uint32 format = SDL_PIXELFORMAT_RGB565;
+
+	_screenTexture = SDL_CreateTexture(_renderer, format, SDL_TEXTUREACCESS_STREAMING, width, height);
 	if (!_screenTexture) {
 		deinitializeRenderer();
 		return nullptr;
 	}
 
-	SDL_Surface *screen = SDL_CreateRGBSurface(0, width, height, 16, 0xF800, 0x7E0, 0x1F, 0);
+	SDL_Surface *screen = SDL_CreateRGBSurfaceWithFormat(0, width, height, SDL_BITSPERPIXEL(format), format);
 	if (!screen) {
 		deinitializeRenderer();
 		return nullptr;
diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.h b/backends/graphics/surfacesdl/surfacesdl-graphics.h
index e6c1edad8c3..8c1a6910f9f 100644
--- a/backends/graphics/surfacesdl/surfacesdl-graphics.h
+++ b/backends/graphics/surfacesdl/surfacesdl-graphics.h
@@ -324,7 +324,7 @@ protected:
 
 	const PluginList &_scalerPlugins;
 	ScalerPluginObject *_scalerPlugin;
-	Scaler *_scaler;
+	Scaler *_scaler, *_mouseScaler;
 	uint _maxExtraPixels;
 	uint _extraPixels;
 
@@ -363,7 +363,6 @@ protected:
 			{ }
 	};
 
-	byte *_mouseData;
 	SDL_Rect _mouseBackup;
 	MousePos _mouseCurState;
 #ifdef USE_RGB_COLOR
@@ -375,9 +374,6 @@ protected:
 	bool _cursorPaletteDisabled;
 	SDL_Surface *_mouseOrigSurface;
 	SDL_Surface *_mouseSurface;
-	enum {
-		kMouseColorKey = 1
-	};
 
 	// Shake mode
 	// This is always set to 0 when building with SDL2.


Commit: f2d857a882582d2f785345d0a5e6518eb89bb71f
    https://github.com/scummvm/scummvm/commit/f2d857a882582d2f785345d0a5e6518eb89bb71f
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2023-01-11T12:57:53Z

Commit Message:
GRAPHICS: Support more pixel formats with the HQ2x and HQ3x scalers

Changed paths:
    graphics/colormasks.h
    graphics/scaler/hq.cpp
    graphics/scaler/hq.h


diff --git a/graphics/colormasks.h b/graphics/colormasks.h
index cead631a495..4e5da823405 100644
--- a/graphics/colormasks.h
+++ b/graphics/colormasks.h
@@ -286,6 +286,42 @@ struct ColorMasks<8888> {
 	typedef uint32 PixelType;
 };
 
+template<>
+struct ColorMasks<-8888> {
+	enum {
+		kBytesPerPixel = 4,
+
+		kAlphaBits  = 8,
+		kRedBits    = 8,
+		kGreenBits  = 8,
+		kBlueBits   = 8,
+
+		kAlphaShift = 0,
+		kRedShift   = kAlphaBits,
+		kGreenShift = kRedBits+kAlphaBits,
+		kBlueShift  = kGreenBits+kRedBits+kAlphaBits,
+
+		kAlphaMask = ((1u << kAlphaBits) - 1) << kAlphaShift,
+		kRedMask   = ((1u << kRedBits) - 1) << kRedShift,
+		kGreenMask = ((1u << kGreenBits) - 1) << kGreenShift,
+		kBlueMask  = ((1u << kBlueBits) - 1) << kBlueShift,
+
+		kRedBlueMask = kRedMask | kBlueMask,
+
+		kLowBits    = (1 << kRedShift) | (1 << kGreenShift) | (1 << kBlueShift) | (1 << kAlphaShift),
+		kLow2Bits   = (3 << kRedShift) | (3 << kGreenShift) | (3 << kBlueShift) | (3 << kAlphaShift),
+		kLow3Bits   = (7 << kRedShift) | (7 << kGreenShift) | (7 << kBlueShift) | (7 << kAlphaShift),
+		kLow4Bits   = (15 << kRedShift) | (15 << kGreenShift) | (15 << kBlueShift) | (15 << kAlphaShift),
+
+		kLowBitsMask = kLowBits,
+		kHighBitsMask = ~kLowBits,
+		qlowBits = kLow2Bits,
+		qhighBits = ~kLow2Bits
+	};
+
+	typedef uint32 PixelType;
+};
+
 } // End of namespace Graphics
 
 #endif
diff --git a/graphics/scaler/hq.cpp b/graphics/scaler/hq.cpp
index e96b2b05eb5..9510be8598f 100644
--- a/graphics/scaler/hq.cpp
+++ b/graphics/scaler/hq.cpp
@@ -5003,6 +5003,38 @@ void HQScaler::HQ3x16(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint3
 }
 #endif
 
+void HQScaler::HQ2x32(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height) {
+	if (_format.aLoss == 0) {
+		if (_format.aShift == 0) {
+			HQ2x_implementation<Graphics::ColorMasks<-8888> >(srcPtr, srcPitch, dstPtr,
+					dstPitch, width, height, _RGBtoYUV);
+		} else {
+			HQ2x_implementation<Graphics::ColorMasks<8888> >(srcPtr, srcPitch, dstPtr,
+					dstPitch, width, height, _RGBtoYUV);
+		}
+	} else {
+		assert((_format.rMax() | _format.gMax() | _format.bMax()) <= 0xffffff);
+		HQ2x_implementation<Graphics::ColorMasks<888> >(srcPtr, srcPitch, dstPtr,
+				dstPitch, width, height, _RGBtoYUV);
+	}
+}
+
+void HQScaler::HQ3x32(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height) {
+	if (_format.aLoss == 0) {
+		if (_format.aShift == 0) {
+			HQ3x_implementation<Graphics::ColorMasks<-8888> >(srcPtr, srcPitch, dstPtr,
+					dstPitch, width, height, _RGBtoYUV);
+		} else {
+			HQ3x_implementation<Graphics::ColorMasks<8888> >(srcPtr, srcPitch, dstPtr,
+					dstPitch, width, height, _RGBtoYUV);
+		}
+	} else {
+		assert((_format.rMax() | _format.gMax() | _format.bMax()) <= 0xffffff);
+		HQ3x_implementation<Graphics::ColorMasks<888> >(srcPtr, srcPitch, dstPtr,
+				dstPitch, width, height, _RGBtoYUV);
+	}
+}
+
 void HQScaler::scaleIntern(const uint8 *srcPtr, uint32 srcPitch,
 							uint8 *dstPtr, uint32 dstPitch, int width, int height, int x, int y) {
 	if (_format.bytesPerPixel == 2) {
@@ -5017,20 +5049,10 @@ void HQScaler::scaleIntern(const uint8 *srcPtr, uint32 srcPitch,
 	} else {
 		switch (_factor) {
 		case 2:
-			if (_format.aLoss == 0)
-				HQ2x_implementation<Graphics::ColorMasks<8888> >(srcPtr, srcPitch, dstPtr,
-						dstPitch, width, height, _RGBtoYUV);
-			else
-				HQ2x_implementation<Graphics::ColorMasks<888> >(srcPtr, srcPitch, dstPtr,
-						dstPitch, width, height, _RGBtoYUV);
+			HQ2x32(srcPtr, srcPitch, dstPtr, dstPitch, width, height);
 			break;
 		case 3:
-			if (_format.aLoss == 0)
-				HQ3x_implementation<Graphics::ColorMasks<8888> >(srcPtr, srcPitch, dstPtr,
-						dstPitch, width, height, _RGBtoYUV);
-			else
-				HQ3x_implementation<Graphics::ColorMasks<888> >(srcPtr, srcPitch, dstPtr,
-						dstPitch, width, height, _RGBtoYUV);
+			HQ3x32(srcPtr, srcPitch, dstPtr, dstPitch, width, height);
 			break;
 		}
 	}
diff --git a/graphics/scaler/hq.h b/graphics/scaler/hq.h
index f9c725826a3..031a43dde79 100644
--- a/graphics/scaler/hq.h
+++ b/graphics/scaler/hq.h
@@ -40,6 +40,8 @@ protected:
 	void initLUT(Graphics::PixelFormat format);
 	inline void HQ2x16(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height);
 	inline void HQ3x16(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height);
+	inline void HQ2x32(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height);
+	inline void HQ3x32(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height);
 
 	uint32 *_RGBtoYUV;
 #ifdef USE_NASM




More information about the Scummvm-git-logs mailing list