haiku: Combine HAIKU_ColorSpaceToBitsPerPixel and HAIKU_BPPToSDLPxFormat

This commit is contained in:
Cameron Cawley 2022-09-17 21:30:40 +01:00 committed by Ryan C. Gordon
parent dd51787e07
commit 1f7a7fd931
3 changed files with 21 additions and 54 deletions

View File

@ -60,8 +60,7 @@ int HAIKU_CreateWindowFramebuffer(_THIS, SDL_Window * window,
/* format */ /* format */
display_mode bmode; display_mode bmode;
bscreen.GetMode(&bmode); bscreen.GetMode(&bmode);
int32 bpp = HAIKU_ColorSpaceToBitsPerPixel(bmode.space); *format = HAIKU_ColorSpaceToSDLPxFormat(bmode.space);
*format = HAIKU_BPPToSDLPxFormat(bpp);
/* Create the new bitmap object */ /* Create the new bitmap object */
BBitmap *bitmap = bwin->GetBitmap(); BBitmap *bitmap = bwin->GetBitmap();

View File

@ -132,62 +132,32 @@ void _SpoutModeData(display_mode *bmode) {
int32 HAIKU_ColorSpaceToBitsPerPixel(uint32 colorspace) int32 HAIKU_ColorSpaceToSDLPxFormat(uint32 colorspace)
{ {
int bitsperpixel;
bitsperpixel = 0;
switch (colorspace) { switch (colorspace) {
case B_CMAP8: case B_CMAP8:
bitsperpixel = 8; return SDL_PIXELFORMAT_INDEX8;
break; break;
case B_RGB15: case B_RGB15:
case B_RGBA15: case B_RGBA15:
case B_RGB15_BIG: case B_RGB15_BIG:
case B_RGBA15_BIG: case B_RGBA15_BIG:
bitsperpixel = 15; return SDL_PIXELFORMAT_RGB555;
break; break;
case B_RGB16: case B_RGB16:
case B_RGB16_BIG: case B_RGB16_BIG:
bitsperpixel = 16; return SDL_PIXELFORMAT_RGB565;
break; break;
case B_RGB32: case B_RGB32:
case B_RGBA32: case B_RGBA32:
case B_RGB32_BIG: case B_RGB32_BIG:
case B_RGBA32_BIG: case B_RGBA32_BIG:
bitsperpixel = 32;
break;
default:
break;
}
return(bitsperpixel);
}
int32 HAIKU_BPPToSDLPxFormat(int32 bpp) {
/* Translation taken from SDL_windowsmodes.c */
switch (bpp) {
case 32:
return SDL_PIXELFORMAT_RGB888; return SDL_PIXELFORMAT_RGB888;
break; break;
case 24: /* May not be supported by Haiku */
return SDL_PIXELFORMAT_RGB24;
break;
case 16:
return SDL_PIXELFORMAT_RGB565;
break;
case 15:
return SDL_PIXELFORMAT_RGB555;
break;
case 8:
return SDL_PIXELFORMAT_INDEX8;
break;
case 4: /* May not be supported by Haiku */
return SDL_PIXELFORMAT_INDEX4LSB;
break;
} }
/* May never get here, but safer and needed to shut up compiler */ /* May never get here, but safer and needed to shut up compiler */
SDL_SetError("Invalid bpp value"); SDL_SetError("Invalid color space");
return 0; return 0;
} }
@ -210,8 +180,7 @@ static void _BDisplayModeToSdlDisplayMode(display_mode *bmode,
#endif #endif
/* Set the format */ /* Set the format */
int32 bpp = HAIKU_ColorSpaceToBitsPerPixel(bmode->space); mode->format = HAIKU_ColorSpaceToSDLPxFormat(bmode->space);
mode->format = HAIKU_BPPToSDLPxFormat(bpp);
} }
/* Later, there may be more than one monitor available */ /* Later, there may be more than one monitor available */

View File

@ -28,8 +28,7 @@ extern "C" {
#include "../SDL_sysvideo.h" #include "../SDL_sysvideo.h"
extern int32 HAIKU_ColorSpaceToBitsPerPixel(uint32 colorspace); extern int32 HAIKU_ColorSpaceToSDLPxFormat(uint32 colorspace);
extern int32 HAIKU_BPPToSDLPxFormat(int32 bpp);
extern int HAIKU_InitModes(_THIS); extern int HAIKU_InitModes(_THIS);
extern int HAIKU_QuitModes(_THIS); extern int HAIKU_QuitModes(_THIS);