imagelib: support for 16-bit transparent tga

This commit is contained in:
mittorn 2019-09-27 02:12:35 +07:00
parent 13c1e807ad
commit 9a1414505a

View File

@ -111,7 +111,7 @@ qboolean Image_LoadTGA( const char *name, const byte *buffer, fs_offset_t filesi
else if( targa_header.image_type == 3 || targa_header.image_type == 11 ) else if( targa_header.image_type == 3 || targa_header.image_type == 11 )
{ {
// uncompressed greyscale // uncompressed greyscale
if( targa_header.pixel_size != 8 ) if( targa_header.pixel_size != 8 && targa_header.pixel_size != 16 )
{ {
Con_DPrintf( S_ERROR "Image_LoadTGA: (%s) Only 8 bit images supported for type 3 and 11\n", name ); Con_DPrintf( S_ERROR "Image_LoadTGA: (%s) Only 8 bit images supported for type 3 and 11\n", name );
return false; return false;
@ -160,11 +160,14 @@ qboolean Image_LoadTGA( const char *name, const byte *buffer, fs_offset_t filesi
case 9: case 9:
// colormapped image // colormapped image
blue = *buf_p++; blue = *buf_p++;
if( blue < targa_header.colormap_length )
{
red = palette[blue][0]; red = palette[blue][0];
green = palette[blue][1]; green = palette[blue][1];
alpha = palette[blue][3]; alpha = palette[blue][3];
blue = palette[blue][2]; blue = palette[blue][2];
if( alpha != 255 ) image.flags |= IMAGE_HAS_ALPHA; if( alpha != 255 ) image.flags |= IMAGE_HAS_ALPHA;
}
break; break;
case 2: case 2:
case 10: case 10:
@ -184,6 +187,13 @@ qboolean Image_LoadTGA( const char *name, const byte *buffer, fs_offset_t filesi
case 11: case 11:
// greyscale image // greyscale image
blue = green = red = *buf_p++; blue = green = red = *buf_p++;
if( targa_header.pixel_size == 16 )
{
alpha = *buf_p++;
if( alpha != 255 )
image.flags |= IMAGE_HAS_ALPHA;
}
else
alpha = 255; alpha = 255;
break; break;
} }