From 85dfaaa2c2f8894204b9a6fb4e867dd54dfde219 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Fri, 19 Jul 2024 06:34:48 +0300 Subject: [PATCH] engine: imagelib: add LUMP_TEXGAMMA palette kind to only pass HL textures through texgamma, not Quake --- engine/common/imagelib/imagelib.h | 13 +++++++------ engine/common/imagelib/img_utils.c | 15 ++++++++++++--- engine/common/imagelib/img_wad.c | 12 +++++++++++- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/engine/common/imagelib/imagelib.h b/engine/common/imagelib/imagelib.h index 0182719d..71894961 100644 --- a/engine/common/imagelib/imagelib.h +++ b/engine/common/imagelib/imagelib.h @@ -108,12 +108,13 @@ typedef struct imglib_s enum { - LUMP_NORMAL = 0, // no alpha - LUMP_MASKED, // 1-bit alpha channel masked texture - LUMP_GRADIENT, // gradient image (decals) - LUMP_EXTENDED, // bmp images have extened palette with alpha-channel - LUMP_HALFLIFE, // get predefined half-life palette - LUMP_QUAKE1 // get predefined quake palette + LUMP_NORMAL = 0, // no alpha + LUMP_MASKED, // 1-bit alpha channel masked texture + LUMP_GRADIENT, // gradient image (decals) + LUMP_EXTENDED, // bmp images have extened palette with alpha-channel + LUMP_HALFLIFE, // get predefined half-life palette + LUMP_QUAKE1, // get predefined quake palette + LUMP_TEXGAMMA, // apply texgamma on top of palette, for half-life mips }; enum diff --git a/engine/common/imagelib/img_utils.c b/engine/common/imagelib/img_utils.c index f064cc79..d01f1e86 100644 --- a/engine/common/imagelib/img_utils.c +++ b/engine/common/imagelib/img_utils.c @@ -293,9 +293,18 @@ static void Image_SetPalette( const byte *pal, uint *d_table ) case LUMP_NORMAL: for( i = 0; i < 256; i++ ) { - rgba[0] = TextureToGamma( pal[i*3+0] ); - rgba[1] = TextureToGamma( pal[i*3+1] ); - rgba[2] = TextureToGamma( pal[i*3+2] ); + memcpy( rgba, &pal[i * 3], 3 ); + rgba[3] = 0xFF; + memcpy( &uirgba, rgba, sizeof( uirgba )); + d_table[i] = uirgba; + } + break; + case LUMP_TEXGAMMA: + for( i = 0; i < 256; i++ ) + { + rgba[0] = TextureToGamma( pal[i * 3 + 0] ); + rgba[1] = TextureToGamma( pal[i * 3 + 1] ); + rgba[2] = TextureToGamma( pal[i * 3 + 2] ); rgba[3] = 0xFF; memcpy( &uirgba, rgba, sizeof( uirgba )); d_table[i] = uirgba; diff --git a/engine/common/imagelib/img_wad.c b/engine/common/imagelib/img_wad.c index 42269187..094efaf7 100644 --- a/engine/common/imagelib/img_wad.c +++ b/engine/common/imagelib/img_wad.c @@ -427,8 +427,18 @@ qboolean Image_LoadMIP( const char *name, const byte *buffer, fs_offset_t filesi } if( pal_type == PAL_QUAKE1 ) + { SetBits( image.flags, IMAGE_QUAKEPAL ); - rendermode = LUMP_NORMAL; + + // if texture was converted from quake to half-life with no palette changes + // then applying texgamma might make it too dark or even outright broken + rendermode = LUMP_NORMAL; + } + else + { + // half-life mips need texgamma applied + rendermode = LUMP_TEXGAMMA; + } } Image_GetPaletteLMP( pal, rendermode );