]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
support tga's with incomplete colormaps (less than 256 colors), I HOPE this is correct
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 3 Feb 2004 04:52:39 +0000 (04:52 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 3 Feb 2004 04:52:39 +0000 (04:52 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@3867 d7cf8633-e32d-0410-b094-e92efae38249

image.c

diff --git a/image.c b/image.c
index 92bfd18e9cd98a670fdd225915dcca4d3f5b5721..27fc794148762ed70fa2e4beeac839f3c76c0833 100644 (file)
--- 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];