]> git.xonotic.org Git - xonotic/netradiant.git/commitdiff
support for writing greyscale TGA files (for minimap)
authorRudolf Polzer <divverent@alientrap.org>
Wed, 23 Feb 2011 09:50:31 +0000 (10:50 +0100)
committerRudolf Polzer <divverent@alientrap.org>
Wed, 23 Feb 2011 09:52:11 +0000 (10:52 +0100)
tools/quake3/common/imagelib.c
tools/quake3/common/imagelib.h

index fa588321b2a6a89103e810e40752f80bf56414ee..5bc248b06c164b7fe29389c00eda1af957331635 100644 (file)
@@ -1182,6 +1182,24 @@ void WriteTGA (const char *filename, byte *data, int width, int height) {
        free (buffer);
 }
 
+void WriteTGAGray (const char *filename, byte *data, int width, int height) {
+       byte    buffer[18];
+       FILE    *f;
+
+       memset (buffer, 0, 18);
+       buffer[2] = 3;          // uncompressed type
+       buffer[12] = width&255;
+       buffer[13] = width>>8;
+       buffer[14] = height&255;
+       buffer[15] = height>>8;
+       buffer[16] = 8; // pixel size
+
+       f = fopen (filename, "wb");
+       fwrite (buffer, 1, 18, f);
+       fwrite (data, 1, width * height, f);
+       fclose (f);
+}
+
 /*
 ============================================================================
 
index 1379427de8c6fe92a1331767669f3ef55b11980a..8ac02e1e9bb56256efc0bc66f620fc87ee751ff9 100644 (file)
@@ -39,6 +39,7 @@ void Save256Image (const char *name, byte *pixels, byte *palette,
 void LoadTGA (const char *filename, byte **pixels, int *width, int *height);
 void LoadTGABuffer ( const byte *buffer, const byte* enddata, byte **pic, int *width, int *height);
 void WriteTGA (const char *filename, byte *data, int width, int height);
+void WriteTGAGray (const char *filename, byte *data, int width, int height);
 int LoadJPGBuff( void *src_buffer, int src_size, unsigned char **pic, int *width, int *height );
 
 void Load32BitImage (const char *name, unsigned **pixels, int *width, int *height);