]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - image.c
cruft removal, general cleanup, fix for delta compression bugs, generic targa writer
[xonotic/darkplaces.git] / image.c
diff --git a/image.c b/image.c
index a7f3b8ca37a7c6e6f2e688c2e68f5dbdf469e2d7..368bb1f802d79135c4b44c4a3eb00ec000f50107 100644 (file)
--- a/image.c
+++ b/image.c
@@ -511,3 +511,32 @@ int loadtextureimagewithmask (char* filename, int matchwidth, int matchheight, q
        free(data);
        return texnum;
 }
+
+void Image_WriteTGARGB (char *filename, int width, int height, byte *data)
+{
+       byte *buffer, *in, *out, *end;
+
+       buffer = malloc(width*height*3 + 18);
+
+       memset (buffer, 0, 18);
+       buffer[2] = 2;          // uncompressed type
+       buffer[12] = (width >> 0) & 0xFF;
+       buffer[13] = (width >> 8) & 0xFF;
+       buffer[14] = (height >> 0) & 0xFF;
+       buffer[15] = (height >> 8) & 0xFF;
+       buffer[16] = 24;        // pixel size
+
+       // swap rgb to bgr
+       in = data;
+       end = in + width*height*3;
+       out = buffer + 18;
+       for (;in < end;in += 3)
+       {
+               *out++ = in[2];
+               *out++ = in[1];
+               *out++ = in[0];
+       }
+       COM_WriteFile (filename, buffer, glwidth*glheight*3 + 18 );
+
+       free(buffer);
+}