From 7e0ce3d3dfc58abb1c8e290ee98252519bcabc49 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Fri, 21 Mar 2003 06:08:17 +0000 Subject: [PATCH] skip over any present colormap for non-colormap types --- libs/util/tga.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/libs/util/tga.c b/libs/util/tga.c index f215e5ba6..33828d5d9 100644 --- a/libs/util/tga.c +++ b/libs/util/tga.c @@ -231,6 +231,17 @@ setup_pixrow_span (TargaHeader *targa, tex_t *tex, byte **_pixrow, int *_span) *_span = span; } +static byte * +skip_colormap (TargaHeader *targa, byte *data) +{ + int bpe; + if (!targa->colormap_type) + return data; + Sys_DPrintf ("LoadTGA: skipping colormap\n"); + bpe = (targa->pixel_size +7) / 8; + return data + bpe * targa->colormap_length; +} + static cmap_t * parse_colormap (TargaHeader *targa, byte **dataByte) { @@ -502,6 +513,8 @@ decode_truecolor_32_rle (TargaHeader *targa, tex_t *tex, byte *dataByte) static void decode_truecolor (TargaHeader *targa, tex_t *tex, byte *dataByte) { + dataByte = skip_colormap (targa, dataByte); + switch (targa->pixel_size) { case 24: tex->format = tex_rgb; @@ -519,6 +532,8 @@ decode_truecolor (TargaHeader *targa, tex_t *tex, byte *dataByte) static void decode_truecolor_rle (TargaHeader *targa, tex_t *tex, byte *dataByte) { + dataByte = skip_colormap (targa, dataByte); + switch (targa->pixel_size) { case 24: tex->format = tex_rgb; @@ -539,6 +554,8 @@ decode_greyscale (TargaHeader *targa, tex_t *tex, byte *dataByte) byte *pixcol, *pixrow; int column, columns, rows, span; + dataByte = skip_colormap (targa, dataByte); + if (targa->pixel_size != 8) Sys_Error ("LoadTGA: unsupported truecolor pixel size"); tex->format = tex_la;