From c2448c888126aa40991c96b875d955bb471ef6f0 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Tue, 18 Nov 2025 13:26:01 +0500 Subject: [PATCH] engine: imagelib: allow specifiying index for empty pixels when processing luma texture --- engine/common/imagelib/imagelib.h | 1 + engine/common/imagelib/img_main.c | 1 + engine/common/imagelib/img_utils.c | 4 ++-- engine/common/imagelib/img_wad.c | 11 ++++++----- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/engine/common/imagelib/imagelib.h b/engine/common/imagelib/imagelib.h index 3429c34f..d67fc6f6 100644 --- a/engine/common/imagelib/imagelib.h +++ b/engine/common/imagelib/imagelib.h @@ -85,6 +85,7 @@ typedef struct imglib_s uint *d_currentpal; // installed version of internal palette int d_rendermode; // palette rendermode byte *palette; // palette pointer + int black_pixel; // "free" index used for luma textures (0 for Quake as it's black, 255 for Half-Life as it's #0000FF) // global parms rgba_t fogParams; // some water textures has info about underwater fog diff --git a/engine/common/imagelib/img_main.c b/engine/common/imagelib/img_main.c index 49e74ff2..a7446cad 100644 --- a/engine/common/imagelib/img_main.c +++ b/engine/common/imagelib/img_main.c @@ -142,6 +142,7 @@ void Image_Reset( void ) image.fogParams[1] = 0; image.fogParams[2] = 0; image.fogParams[3] = 0; + image.black_pixel = 0; // pointers will be saved with prevoius picture struct // don't care about it diff --git a/engine/common/imagelib/img_utils.c b/engine/common/imagelib/img_utils.c index 9f63879a..72dd3b44 100644 --- a/engine/common/imagelib/img_utils.c +++ b/engine/common/imagelib/img_utils.c @@ -616,7 +616,7 @@ qboolean Image_Copy8bitRGBA( const byte *in, byte *out, int pixels ) if( image.flags & IMAGE_HAS_LUMA ) { for( i = 0; i < image.width * image.height; i++ ) - fin[i] = fin[i] < 224 ? fin[i] : 0; + fin[i] = fin[i] < 224 ? fin[i] : image.black_pixel; } // check for color @@ -1204,7 +1204,7 @@ static byte *Image_MakeLuma( byte *fin, int width, int height, int type, int fla case PF_INDEXED_32: out = image.tempbuffer = Mem_Realloc( host.imagepool, image.tempbuffer, width * height ); for( i = 0; i < width * height; i++ ) - *out++ = fin[i] >= 224 ? fin[i] : 0; + *out++ = fin[i] >= 224 ? fin[i] : image.black_pixel; break; default: // another formats does ugly result :( diff --git a/engine/common/imagelib/img_wad.c b/engine/common/imagelib/img_wad.c index 3f0d5740..50425e78 100644 --- a/engine/common/imagelib/img_wad.c +++ b/engine/common/imagelib/img_wad.c @@ -430,7 +430,8 @@ qboolean Image_LoadMIP( const char *name, const byte *buffer, fs_offset_t filesi { if( fin[i] > 224 ) { - image.flags |= IMAGE_HAS_LUMA; + SetBits( image.flags, IMAGE_HAS_LUMA ); + image.black_pixel = 0; break; } } @@ -464,15 +465,15 @@ qboolean Image_LoadMIP( const char *name, const byte *buffer, fs_offset_t filesi hl_texture = false; // check for luma and alpha pixels - if( !image.custom_palette ) + // don't apply luma to water surfaces because they have no lightmap + if( !image.custom_palette && mip.name[0] != '*' && mip.name != '!' ) { for( i = 0; i < image.width * image.height; i++ ) { if( fin[i] > 224 && fin[i] != 255 ) { - // don't apply luma to water surfaces because they have no lightmap - if( mip.name[0] != '*' && mip.name[0] != '!' ) - image.flags |= IMAGE_HAS_LUMA; + SetBits( image.flags, IMAGE_HAS_LUMA ); + image.black_pixel = 0; break; } }