]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - image.c
TEU uses teu.rc, not quake.rc
[xonotic/darkplaces.git] / image.c
diff --git a/image.c b/image.c
index c1615d4c4f3c31c9ac9e8115153a78350e023787..192cb568d9eded768e0ab86197fb6be4b9959d57 100644 (file)
--- a/image.c
+++ b/image.c
@@ -7,6 +7,44 @@
 int            image_width;
 int            image_height;
 
+void Image_CopyMux(qbyte *outpixels, const qbyte *inpixels, int width, int height, int flipx, int flipy, int flipdiagonal, int numincomponents, int numoutcomponents, int *inputcomponentindices)
+{
+       int index, c, x, y;
+       const qbyte *in, *inrow, *incolumn;
+       if (flipdiagonal)
+       {
+               for (y = 0;y < height;y++)
+               {
+                       incolumn = inpixels + (flipx ? width - 1 - y : y) * numincomponents;
+                       for (x = 0;x < width;x++)
+                       {
+                               in = incolumn + (flipy ? height - 1 - x : x) * width * numincomponents;
+                               for (c = 0;c < numoutcomponents;c++)
+                               {
+                                       index = inputcomponentindices[c];
+                                       *outpixels++ = (index & 0x80000000) ? (index - 0x8000000) : in[index];
+                               }
+                       }
+               }
+       }
+       else
+       {
+               for (y = 0;y < height;y++)
+               {
+                       inrow = inpixels + (flipy ? height - 1 - y : y) * width * numincomponents;
+                       for (x = 0;x < width;x++)
+                       {
+                               in = inrow + (flipx ? width - 1 - x : x) * numincomponents;
+                               for (c = 0;c < numoutcomponents;c++)
+                               {
+                                       index = inputcomponentindices[c];
+                                       *outpixels++ = (index & 0x80000000) ? (index - 0x8000000) : in[index];
+                               }
+                       }
+               }
+       }
+}
+
 void Image_GammaRemapRGB(const qbyte *in, qbyte *out, int pixels, const qbyte *gammar, const qbyte *gammag, const qbyte *gammab)
 {
        while (pixels--)
@@ -217,7 +255,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 +308,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 +419,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];
@@ -565,7 +606,11 @@ void Image_StripImageExtension (const char *in, char *out)
        if ((end - in) >= 4)
        {
                temp = end - 4;
-               if (strcmp(temp, ".tga") == 0 || strcmp(temp, ".pcx") == 0 || strcmp(temp, ".lmp") == 0)
+               if (strcmp(temp, ".tga") == 0
+                || strcmp(temp, ".pcx") == 0
+                || strcmp(temp, ".lmp") == 0
+                || strcmp(temp, ".png") == 0
+                || strcmp(temp, ".jpg") == 0)
                        end = temp;
                while (in < end)
                        *out++ = *in++;
@@ -600,6 +645,8 @@ qbyte *loadimagepixels (const char *filename, qboolean complain, int matchwidth,
        int i;
        qbyte *f, *data = NULL;
        char basename[MAX_QPATH], name[MAX_QPATH], *c;
+       if (developer_memorydebug.integer)
+               Mem_CheckSentinelsGlobal();
        Image_StripImageExtension(filename, basename); // strip filename extensions to allow replacement by other types
        // replace *'s with #, so commandline utils don't get confused when dealing with the external files
        for (c = basename;*c;c++)
@@ -612,6 +659,8 @@ qbyte *loadimagepixels (const char *filename, qboolean complain, int matchwidth,
                {
                        Mem_Free(f);
                        Con_DPrintf("loaded image %s (%dx%d)\n", name, image_width, image_height);
+                       if (developer_memorydebug.integer)
+                               Mem_CheckSentinelsGlobal();
                        return data;
                }
        }
@@ -624,6 +673,8 @@ qbyte *loadimagepixels (const char *filename, qboolean complain, int matchwidth,
                        Con_Printf (i == 0 ? "\"%s\"" : (imageformats[i+1].formatstring ? ", \"%s\"" : " or \"%s\".\n"), imageformats[i].formatstring);
                }
        }
+       if (developer_memorydebug.integer)
+               Mem_CheckSentinelsGlobal();
        return NULL;
 }
 
@@ -1385,7 +1436,7 @@ void Image_HeightmapToNormalmap(const unsigned char *inpixels, unsigned char *ou
                        /*
                        dv[0][0] = iwidth;
                        dv[0][1] = 0;
-                       dv[0][2] = ((p1[0] + p1[1] + p1[2]) * ibumpscale) - ((p0[0] + p0[1] + p0[2]) * ibumpscale);
+                       dv[0][2] = ((p0[0] + p0[1] + p0[2]) * ibumpscale) - ((p1[0] + p1[1] + p1[2]) * ibumpscale);
                        dv[1][0] = 0;
                        dv[1][1] = iheight;
                        dv[1][2] = ((p2[0] + p2[1] + p2[2]) * ibumpscale) - ((p0[0] + p0[1] + p0[2]) * ibumpscale);
@@ -1393,14 +1444,14 @@ void Image_HeightmapToNormalmap(const unsigned char *inpixels, unsigned char *ou
                        n[1] = dv[0][2]*dv[1][0]-dv[0][0]*dv[1][2];
                        n[2] = dv[0][0]*dv[1][1]-dv[0][1]*dv[1][0];
                        */
-                       n[0] = ((p0[0] + p0[1] + p0[2]) - (p1[0] + p1[1] + p1[2]));
+                       n[0] = ((p1[0] + p1[1] + p1[2]) - (p0[0] + p0[1] + p0[2]));
                        n[1] = ((p0[0] + p0[1] + p0[2]) - (p2[0] + p2[1] + p2[2]));
                        n[2] = ibumpscale;
                        VectorNormalize(n);
                        /*
                        // this should work for the bottom right triangle if anyone wants
                        // code for that for some reason
-                       n[0] = ((p1[0] + p1[1] + p1[2]) - (p3[0] + p3[1] + p3[2]));
+                       n[0] = ((p3[0] + p3[1] + p3[2]) - (p1[0] + p1[1] + p1[2]));
                        n[1] = ((p2[0] + p2[1] + p2[2]) - (p3[0] + p3[1] + p3[2]));
                        n[2] = ibumpscale;
                        VectorNormalize(n);
@@ -1414,11 +1465,13 @@ void Image_HeightmapToNormalmap(const unsigned char *inpixels, unsigned char *ou
        }
 }
 
-int image_loadskin(imageskin_t *s, char *name)
+int image_loadskin(imageskin_t *s, char *shadername)
 {
        int j;
        qbyte *bumppixels;
        int bumppixels_width, bumppixels_height;
+       char name[MAX_QPATH];
+       Image_StripImageExtension(shadername, name);
        memset(s, 0, sizeof(*s));
        s->basepixels = loadimagepixels(name, false, 0, 0);
        if (s->basepixels == NULL)