]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - image.c
split model->DrawShadowVolume into CompileShadowVolume and DrawShadowVolume to simpli...
[xonotic/darkplaces.git] / image.c
diff --git a/image.c b/image.c
index 185c66d360732d772053180d35344fc60c8b50e4..a5eeeff67159e7829b52e4d1fd1286e03a6b6d9f 100644 (file)
--- a/image.c
+++ b/image.c
@@ -289,19 +289,7 @@ TargaHeader;
 
 void PrintTargaHeader(TargaHeader *t)
 {
-       Con_Print("TargaHeader:\n");
-       Con_Printf("uint8 id_length = %i;\n", t->id_length);
-       Con_Printf("uint8 colormap_type = %i;\n", t->colormap_type);
-       Con_Printf("uint8 image_type = %i;\n", t->image_type);
-       Con_Printf("uint16 colormap_index = %i;\n", t->colormap_index);
-       Con_Printf("uint16 colormap_length = %i;\n", t->colormap_length);
-       Con_Printf("uint8 colormap_size = %i;\n", t->colormap_size);
-       Con_Printf("uint16 x_origin = %i;\n", t->x_origin);
-       Con_Printf("uint16 y_origin = %i;\n", t->y_origin);
-       Con_Printf("uint16 width = %i;\n", t->width);
-       Con_Printf("uint16 height = %i;\n", t->height);
-       Con_Printf("uint8 pixel_size = %i;\n", t->pixel_size);
-       Con_Printf("uint8 attributes = %i;\n", t->attributes);
+       Con_Printf("TargaHeader:\nuint8 id_length = %i;\nuint8 colormap_type = %i;\nuint8 image_type = %i;\nuint16 colormap_index = %i;\nuint16 colormap_length = %i;\nuint8 colormap_size = %i;\nuint16 x_origin = %i;\nuint16 y_origin = %i;\nuint16 width = %i;\nuint16 height = %i;\nuint8 pixel_size = %i;\nuint8 attributes = %i;\n", t->id_length, t->colormap_type, t->image_type, t->colormap_index, t->colormap_length, t->colormap_size, t->x_origin, t->y_origin, t->width, t->height, t->pixel_size, t->attributes);
 }
 
 /*
@@ -314,8 +302,9 @@ qbyte *LoadTGA (const qbyte *f, int matchwidth, int matchheight)
        int x, y, row_inc, compressed, readpixelcount, red, green, blue, alpha, runlen, pindex, alphabits;
        qbyte *pixbuf, *image_rgba;
        const qbyte *fin, *enddata;
+       unsigned char *p;
        TargaHeader targa_header;
-       unsigned char palette[256*4], *p;
+       unsigned char palette[256*4];
 
        if (fs_filesize < 19)
                return NULL;
@@ -436,6 +425,14 @@ qbyte *LoadTGA (const qbyte *f, int matchwidth, int matchheight)
                return NULL;
        }
 
+       // number of attribute bits per pixel, we only support 0 or 8
+       alphabits = targa_header.attributes & 0x0F;
+       if (alphabits != 8 && alphabits != 0)
+       {
+               Con_Print("LoadTGA: only 0 or 8 attribute (alpha) bits supported\n");
+               return NULL;
+       }
+
        image_rgba = Mem_Alloc(tempmempool, image_width * image_height * 4);
        if (!image_rgba)
        {
@@ -455,14 +452,6 @@ qbyte *LoadTGA (const qbyte *f, int matchwidth, int matchheight)
                row_inc = 0;
        }
 
-       // number of attribute bits per pixel, we only support 0 or 8
-       alphabits = targa_header.attributes & 0x0F;
-       if (alphabits != 8 && alphabits != 0)
-       {
-               Con_Print("LoadTGA: only 0 or 8 attribute (alpha) bits supported\n");
-               return NULL;
-       }
-
        compressed = targa_header.image_type == 9 || targa_header.image_type == 10 || targa_header.image_type == 11;
        x = 0;
        y = 0;
@@ -568,7 +557,7 @@ qbyte *LoadLMP (const qbyte *f, int matchwidth, int matchheight, qboolean loadAs
        if ((matchwidth && image_width != matchwidth) || (matchheight && image_height != matchheight))
                return NULL;
 
-       if (fs_filesize < 8 + image_width * image_height)
+       if (fs_filesize < (fs_offset_t)(8 + image_width * image_height))
        {
                Con_Print("LoadLMP: invalid LMP file\n");
                return NULL;
@@ -690,7 +679,10 @@ qbyte *loadimagepixels (const char *filename, qboolean complain, int matchwidth,
        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
+       if (developer_texturelogging.integer)
+               Log_Printf("textures.log", "%s\n", filename);
+       strlcpy(basename, filename, sizeof(basename));
+       Image_StripImageExtension(basename, 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++)
                if (*c == '*')
@@ -1300,7 +1292,10 @@ Image_Resample
 void Image_Resample (const void *indata, int inwidth, int inheight, int indepth, void *outdata, int outwidth, int outheight, int outdepth, int bytesperpixel, int quality)
 {
        if (indepth != 1 || outdepth != 1)
-               Sys_Error("Image_Resample: 3D resampling not supported\n");
+       {
+               Con_Printf ("Image_Resample: 3D resampling not supported\n");
+               return;
+       }
        if (bytesperpixel == 4)
        {
                if (quality)
@@ -1316,7 +1311,7 @@ void Image_Resample (const void *indata, int inwidth, int inheight, int indepth,
                        Image_Resample24Nolerp(indata, inwidth, inheight, outdata, outwidth, outheight);
        }
        else
-               Sys_Error("Image_Resample: unsupported bytesperpixel %i\n", bytesperpixel);
+               Con_Printf ("Image_Resample: unsupported bytesperpixel %i\n", bytesperpixel);
 }
 
 // in can be the same as out
@@ -1324,7 +1319,10 @@ void Image_MipReduce(const qbyte *in, qbyte *out, int *width, int *height, int *
 {
        int x, y, nextrow;
        if (*depth != 1 || destdepth != 1)
-               Sys_Error("Image_Resample: 3D resampling not supported\n");
+       {
+               Con_Printf ("Image_Resample: 3D resampling not supported\n");
+               return;
+       }
        nextrow = *width * bytesperpixel;
        if (*width > destwidth)
        {
@@ -1365,7 +1363,7 @@ void Image_MipReduce(const qbyte *in, qbyte *out, int *width, int *height, int *
                                }
                        }
                        else
-                               Sys_Error("Image_MipReduce: unsupported bytesperpixel %i\n", bytesperpixel);
+                               Con_Printf ("Image_MipReduce: unsupported bytesperpixel %i\n", bytesperpixel);
                }
                else
                {
@@ -1400,7 +1398,7 @@ void Image_MipReduce(const qbyte *in, qbyte *out, int *width, int *height, int *
                                }
                        }
                        else
-                               Sys_Error("Image_MipReduce: unsupported bytesperpixel %i\n", bytesperpixel);
+                               Con_Printf ("Image_MipReduce: unsupported bytesperpixel %i\n", bytesperpixel);
                }
        }
        else
@@ -1441,10 +1439,10 @@ void Image_MipReduce(const qbyte *in, qbyte *out, int *width, int *height, int *
                                }
                        }
                        else
-                               Sys_Error("Image_MipReduce: unsupported bytesperpixel %i\n", bytesperpixel);
+                               Con_Printf ("Image_MipReduce: unsupported bytesperpixel %i\n", bytesperpixel);
                }
                else
-                       Sys_Error("Image_MipReduce: desired size already achieved\n");
+                       Con_Printf ("Image_MipReduce: desired size already achieved\n");
        }
 }
 
@@ -1492,8 +1490,8 @@ 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] = ((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[0] = ((p0[0] + p0[1] + p0[2]) - (p1[0] + p1[1] + p1[2]));
+                       n[1] = ((p2[0] + p2[1] + p2[2]) - (p0[0] + p0[1] + p0[2]));
                        n[2] = ibumpscale;
                        VectorNormalize(n);
                        /*
@@ -1519,7 +1517,8 @@ int image_loadskin(imageskin_t *s, char *shadername)
        qbyte *bumppixels;
        int bumppixels_width, bumppixels_height;
        char name[MAX_QPATH];
-       Image_StripImageExtension(shadername, name);
+       strlcpy(name, shadername, sizeof(name));
+       Image_StripImageExtension(name, name);
        memset(s, 0, sizeof(*s));
        s->basepixels = loadimagepixels(name, false, 0, 0);
        if (s->basepixels == NULL)