From 6abc2eef23f8062c5cbd880a681eb611b0b858a7 Mon Sep 17 00:00:00 2001 From: havoc Date: Tue, 3 Feb 2004 04:52:39 +0000 Subject: [PATCH] support tga's with incomplete colormaps (less than 256 colors), I HOPE this is correct git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@3867 d7cf8633-e32d-0410-b094-e92efae38249 --- image.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/image.c b/image.c index 92bfd18e..27fc7941 100644 --- a/image.c +++ b/image.c @@ -217,7 +217,7 @@ LoadTGA */ qbyte *LoadTGA (qbyte *f, int matchwidth, int matchheight) { - int x, y, row_inc, compressed, readpixelcount, red, green, blue, alpha, runlen; + int x, y, row_inc, compressed, readpixelcount, red, green, blue, alpha, runlen, pindex; qbyte *pixbuf, *image_rgba; qbyte *fin, *enddata; TargaHeader targa_header; @@ -270,9 +270,9 @@ qbyte *LoadTGA (qbyte *f, int matchwidth, int matchheight) PrintTargaHeader(&targa_header); return NULL; } - if (targa_header.colormap_length != 256) + if (targa_header.colormap_length > 256) { - Con_Printf ("LoadTGA: only 256 colormap_length supported\n"); + Con_Printf ("LoadTGA: only up to 256 colormap_length supported\n"); PrintTargaHeader(&targa_header); return NULL; } @@ -381,7 +381,10 @@ qbyte *LoadTGA (qbyte *f, int matchwidth, int matchheight) case 1: case 9: // colormapped - p = palette + (*fin++) * 4; + pindex = *fin++; + if (pindex >= targa_header.colormap_length) + pindex = 0; // error + p = palette + pindex * 4; red = p[0]; green = p[1]; blue = p[2]; -- 2.39.2