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

This commit is contained in:
Cameron Cawley 2019-03-01 16:13:13 +00:00 committed by Bastien Bouclet
parent 4c708dc97f
commit 342733cee6
3 changed files with 19 additions and 30 deletions

View file

@ -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++) {

View file

@ -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;

View file

@ -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);