From 1f7a7fd9319e39f3b662a610dbce4f7e8c33affa Mon Sep 17 00:00:00 2001 From: Cameron Cawley Date: Sat, 17 Sep 2022 21:30:40 +0100 Subject: [PATCH] haiku: Combine HAIKU_ColorSpaceToBitsPerPixel and HAIKU_BPPToSDLPxFormat --- src/video/haiku/SDL_bframebuffer.cc | 3 +- src/video/haiku/SDL_bmodes.cc | 69 ++++++++--------------------- src/video/haiku/SDL_bmodes.h | 3 +- 3 files changed, 21 insertions(+), 54 deletions(-) diff --git a/src/video/haiku/SDL_bframebuffer.cc b/src/video/haiku/SDL_bframebuffer.cc index 971231924..f303177cb 100644 --- a/src/video/haiku/SDL_bframebuffer.cc +++ b/src/video/haiku/SDL_bframebuffer.cc @@ -60,8 +60,7 @@ int HAIKU_CreateWindowFramebuffer(_THIS, SDL_Window * window, /* format */ display_mode bmode; bscreen.GetMode(&bmode); - int32 bpp = HAIKU_ColorSpaceToBitsPerPixel(bmode.space); - *format = HAIKU_BPPToSDLPxFormat(bpp); + *format = HAIKU_ColorSpaceToSDLPxFormat(bmode.space); /* Create the new bitmap object */ BBitmap *bitmap = bwin->GetBitmap(); diff --git a/src/video/haiku/SDL_bmodes.cc b/src/video/haiku/SDL_bmodes.cc index 0cbc56b0f..586e2a93b 100644 --- a/src/video/haiku/SDL_bmodes.cc +++ b/src/video/haiku/SDL_bmodes.cc @@ -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) { - case B_CMAP8: - bitsperpixel = 8; - break; - case B_RGB15: - case B_RGBA15: - case B_RGB15_BIG: - case B_RGBA15_BIG: - bitsperpixel = 15; - break; - case B_RGB16: - case B_RGB16_BIG: - bitsperpixel = 16; - break; - case B_RGB32: - case B_RGBA32: - case B_RGB32_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; - 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: + case B_CMAP8: return SDL_PIXELFORMAT_INDEX8; break; - case 4: /* May not be supported by Haiku */ - return SDL_PIXELFORMAT_INDEX4LSB; + case B_RGB15: + case B_RGBA15: + case B_RGB15_BIG: + case B_RGBA15_BIG: + return SDL_PIXELFORMAT_RGB555; + break; + case B_RGB16: + case B_RGB16_BIG: + return SDL_PIXELFORMAT_RGB565; + break; + case B_RGB32: + case B_RGBA32: + case B_RGB32_BIG: + case B_RGBA32_BIG: + return SDL_PIXELFORMAT_RGB888; break; } /* May never get here, but safer and needed to shut up compiler */ - SDL_SetError("Invalid bpp value"); + SDL_SetError("Invalid color space"); return 0; } @@ -210,8 +180,7 @@ static void _BDisplayModeToSdlDisplayMode(display_mode *bmode, #endif /* Set the format */ - int32 bpp = HAIKU_ColorSpaceToBitsPerPixel(bmode->space); - mode->format = HAIKU_BPPToSDLPxFormat(bpp); + mode->format = HAIKU_ColorSpaceToSDLPxFormat(bmode->space); } /* Later, there may be more than one monitor available */ diff --git a/src/video/haiku/SDL_bmodes.h b/src/video/haiku/SDL_bmodes.h index 56fa14488..5b4041833 100644 --- a/src/video/haiku/SDL_bmodes.h +++ b/src/video/haiku/SDL_bmodes.h @@ -28,8 +28,7 @@ extern "C" { #include "../SDL_sysvideo.h" -extern int32 HAIKU_ColorSpaceToBitsPerPixel(uint32 colorspace); -extern int32 HAIKU_BPPToSDLPxFormat(int32 bpp); +extern int32 HAIKU_ColorSpaceToSDLPxFormat(uint32 colorspace); extern int HAIKU_InitModes(_THIS); extern int HAIKU_QuitModes(_THIS);