diff --git a/src/i_video.c b/src/i_video.c index c1e32ad..29c5421 100644 --- a/src/i_video.c +++ b/src/i_video.c @@ -88,7 +88,7 @@ static int vid_window_title_short = 1; #ifndef CRISPY_TRUECOLOR static SDL_Surface *screenbuffer = NULL; #endif -static SDL_Surface *argbbuffer = NULL; +SDL_Surface *argbbuffer = NULL; static SDL_Texture *texture = NULL; static SDL_Texture *texture_upscaled = NULL; @@ -2291,9 +2291,12 @@ void I_BindVideoVariables(void) M_BindIntVariable("mouse_grab", &mouse_grab); } +// [PN] Original human-readable mapping function from Crispy Doom +/* #ifdef CRISPY_TRUECOLOR const pixel_t I_MapRGB (const uint8_t r, const uint8_t g, const uint8_t b) { return SDL_MapRGB(argbbuffer->format, r, g, b); } #endif +*/ diff --git a/src/i_video.h b/src/i_video.h index d5f2f40..e08e2ab 100644 --- a/src/i_video.h +++ b/src/i_video.h @@ -21,6 +21,7 @@ #ifndef __I_VIDEO__ #define __I_VIDEO__ +#include "SDL.h" #include "doomtype.h" #include "i_truecolor.h" #include "m_fixed.h" @@ -97,7 +98,24 @@ void I_SetPalette (byte* palette); int I_GetPaletteIndex(int r, int g, int b); #else void I_SetPalette (int palette); -extern const pixel_t I_MapRGB (const uint8_t r, const uint8_t g, const uint8_t b); + +// [PN] We define a macro that manually assembles a 32-bit pixel from separate R/G/B values. +// It applies the format's shift and loss adjustments, then merges all components (and alpha mask) with bitwise OR. +// This avoids the overhead of the SDL_MapRGB() function call. +// +// Original human-readable mapping function from Crispy Doom is preserved as commented example in i_video.c file. +// extern inline const pixel_t I_MapRGB (const uint8_t r, const uint8_t g, const uint8_t b); + +extern SDL_Surface *argbbuffer; + +#define I_MapRGB(r, g, b) ( \ + (pixel_t)( \ + (((uint32_t)(r) >> argbbuffer->format->Rloss) << argbbuffer->format->Rshift) | \ + (((uint32_t)(g) >> argbbuffer->format->Gloss) << argbbuffer->format->Gshift) | \ + (((uint32_t)(b) >> argbbuffer->format->Bloss) << argbbuffer->format->Bshift) | \ + (argbbuffer->format->Amask) \ + ) \ +) #endif void I_FinishUpdate (void);