From 419d91edc5ded36345458385d69271ac9fe9d7d5 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Wed, 4 May 2022 13:50:55 +0900 Subject: [PATCH] [image] Set texture type for no-load tga images I might need to do similar for other formats, but i ran into the problem of the texture type being tex_palette instead of the expected tex_rgba when pre-(no-)loading a tga image resulting in Vulkan not liking my attempt at generating mipmaps. --- include/QF/tga.h | 11 +++++++++++ libs/image/tga.c | 31 +++++++++++++++++++++---------- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/include/QF/tga.h b/include/QF/tga.h index 08d610d95..a5a133da3 100644 --- a/include/QF/tga.h +++ b/include/QF/tga.h @@ -44,6 +44,17 @@ # endif #endif +typedef enum { + targa_colormap = 1, + targa_truecolor = 2, + targa_greyscale = 3, + targa_colormap_rle = 9, + targa_truecolor_rle = 10, + targa_greyscale_rle = 11, + + targa_max_image_type = 15 +} TargaImageType; + typedef struct _TargaHeader { unsigned char id_length; // __attribute__((packed)); unsigned char colormap_type; // __attribute__((packed)); diff --git a/libs/image/tga.c b/libs/image/tga.c index 20db43ddd..03368ce6f 100644 --- a/libs/image/tga.c +++ b/libs/image/tga.c @@ -605,19 +605,25 @@ decode_greyscale_rle (TargaHeader *targa, tex_t *tex, byte *dataByte) typedef void (*decoder_t) (TargaHeader *, tex_t *, byte *); static decoder_t decoder_functions[] = { - 0, // 0 invalid - decode_colormap, - decode_truecolor, - decode_greyscale, - 0, 0, 0, 0, // 5-7 invalid - 0, // 8 invalid - decode_colormap_rle, - decode_truecolor_rle, - decode_greyscale_rle, - 0, 0, 0, 0, // 12-15 invalid + [targa_colormap] = decode_colormap, + [targa_truecolor] = decode_truecolor, + [targa_greyscale] = decode_greyscale, + [targa_colormap_rle] = decode_colormap_rle, + [targa_truecolor_rle] = decode_truecolor_rle, + [targa_greyscale_rle] = decode_greyscale_rle, + [targa_max_image_type] = 0 }; #define NUM_DECODERS (sizeof (decoder_functions) \ / sizeof (decoder_functions[0])) +static QFFormat targa_formats[] = { + [targa_colormap] = tex_palette, + [targa_truecolor] = tex_rgba, + [targa_greyscale] = tex_l, + [targa_colormap_rle] = tex_palette, + [targa_truecolor_rle] = tex_rgba, + [targa_greyscale_rle] = tex_l, + [targa_max_image_type] = 0 +}; struct tex_s * LoadTGA (QFile *fin, int load) @@ -669,6 +675,11 @@ LoadTGA (QFile *fin, int load) dataByte += targa->id_length; decode (targa, tex, dataByte); + } else { + //FIXME + // assume the format is valid so we can return a format type without + // having to check individial image type specific data + tex->format = targa_formats[targa->image_type]; } Hunk_FreeToLowMark (0, targa_mark);