engine: imagelib: allow specifiying index for empty pixels when processing luma texture

This commit is contained in:
Alibek Omarov
2025-11-18 13:26:01 +05:00
parent 26df99ae41
commit c2448c8881
4 changed files with 10 additions and 7 deletions

View File

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

View File

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

View File

@@ -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 :(

View File

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