From 0b6479c18b1b6e3c045a7261281a57752d3d87cf Mon Sep 17 00:00:00 2001 From: divverent Date: Mon, 27 Apr 2009 16:57:55 +0000 Subject: [PATCH] new modes for minimap: -black = black on transparent, -white = white on transparent, -gray = white on black git-svn-id: svn://svn.icculus.org/netradiant/trunk@347 61c419a2-8eb2-4b30-bcec-8cead039b335 --- tools/quake3/common/imagelib.c | 20 ++++++ tools/quake3/common/imagelib.h | 1 + tools/quake3/q3map2/game_darkplaces.h | 1 + tools/quake3/q3map2/game_dq.h | 1 + tools/quake3/q3map2/game_ef.h | 1 + tools/quake3/q3map2/game_etut.h | 1 + tools/quake3/q3map2/game_ja.h | 1 + tools/quake3/q3map2/game_jk2.h | 1 + tools/quake3/q3map2/game_nexuiz.h | 1 + tools/quake3/q3map2/game_prophecy.h | 1 + tools/quake3/q3map2/game_qfusion.h | 1 + tools/quake3/q3map2/game_quake3.h | 1 + tools/quake3/q3map2/game_quakelive.h | 1 + tools/quake3/q3map2/game_sof2.h | 1 + tools/quake3/q3map2/game_tenebrae.h | 1 + tools/quake3/q3map2/game_tremulous.h | 1 + tools/quake3/q3map2/game_wolf.h | 1 + tools/quake3/q3map2/game_wolfet.h | 1 + tools/quake3/q3map2/main.c | 96 +++++++++++++++++++++------ tools/quake3/q3map2/q3map2.h | 8 +++ 20 files changed, 120 insertions(+), 21 deletions(-) diff --git a/tools/quake3/common/imagelib.c b/tools/quake3/common/imagelib.c index 5971d81..9e52f1e 100644 --- a/tools/quake3/common/imagelib.c +++ b/tools/quake3/common/imagelib.c @@ -1181,6 +1181,26 @@ 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]; + int i; + int c; + 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); +} + /* ============================================================================ diff --git a/tools/quake3/common/imagelib.h b/tools/quake3/common/imagelib.h index 171332f..2371b48 100644 --- a/tools/quake3/common/imagelib.h +++ b/tools/quake3/common/imagelib.h @@ -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); void Load32BitImage (const char *name, unsigned **pixels, int *width, int *height); diff --git a/tools/quake3/q3map2/game_darkplaces.h b/tools/quake3/q3map2/game_darkplaces.h index ff936f9..04699d4 100644 --- a/tools/quake3/q3map2/game_darkplaces.h +++ b/tools/quake3/q3map2/game_darkplaces.h @@ -68,6 +68,7 @@ game_t struct 1.0f, /* minimap sharpener */ 0.0f, /* minimap border */ qtrue, /* minimap keep aspect */ + MINIMAP_MODE_GRAY, /* minimap mode */ "%s.tga", /* minimap name format */ "IBSP", /* bsp file prefix */ 46, /* bsp file version */ diff --git a/tools/quake3/q3map2/game_dq.h b/tools/quake3/q3map2/game_dq.h index 5671266..d9f7fd5 100644 --- a/tools/quake3/q3map2/game_dq.h +++ b/tools/quake3/q3map2/game_dq.h @@ -68,6 +68,7 @@ game_t struct 1.0f, /* minimap sharpener */ 0.0f, /* minimap border */ qtrue, /* minimap keep aspect */ + MINIMAP_MODE_GRAY, /* minimap mode */ "%s.tga", /* minimap name format */ "IBSP", /* bsp file prefix */ 46, /* bsp file version */ diff --git a/tools/quake3/q3map2/game_ef.h b/tools/quake3/q3map2/game_ef.h index a3b2950..3617180 100644 --- a/tools/quake3/q3map2/game_ef.h +++ b/tools/quake3/q3map2/game_ef.h @@ -127,6 +127,7 @@ game_t struct 1.0f, /* minimap sharpener */ 0.0f, /* minimap border */ qtrue, /* minimap keep aspect */ + MINIMAP_MODE_GRAY, /* minimap mode */ "%s.tga", /* minimap name format */ "IBSP", /* bsp file prefix */ 46, /* bsp file version */ diff --git a/tools/quake3/q3map2/game_etut.h b/tools/quake3/q3map2/game_etut.h index e4dbc6b..8f2f297 100644 --- a/tools/quake3/q3map2/game_etut.h +++ b/tools/quake3/q3map2/game_etut.h @@ -162,6 +162,7 @@ game_t struct 1.0f, /* minimap sharpener */ 0.0f, /* minimap border */ qtrue, /* minimap keep aspect */ + MINIMAP_MODE_GRAY, /* minimap mode */ "%s.tga", /* minimap name format */ "IBSP", /* bsp file prefix */ 46, /* bsp file version */ diff --git a/tools/quake3/q3map2/game_ja.h b/tools/quake3/q3map2/game_ja.h index 69597b2..f63429d 100644 --- a/tools/quake3/q3map2/game_ja.h +++ b/tools/quake3/q3map2/game_ja.h @@ -81,6 +81,7 @@ game_t struct 1.0f, /* minimap sharpener */ 0.0f, /* minimap border */ qtrue, /* minimap keep aspect */ + MINIMAP_MODE_GRAY, /* minimap mode */ "%s.tga", /* minimap name format */ "RBSP", /* bsp file prefix */ 1, /* bsp file version */ diff --git a/tools/quake3/q3map2/game_jk2.h b/tools/quake3/q3map2/game_jk2.h index 15cbf95..0ce673e 100644 --- a/tools/quake3/q3map2/game_jk2.h +++ b/tools/quake3/q3map2/game_jk2.h @@ -78,6 +78,7 @@ game_t struct 1.0f, /* minimap sharpener */ 0.0f, /* minimap border */ qtrue, /* minimap keep aspect */ + MINIMAP_MODE_GRAY, /* minimap mode */ "%s.tga", /* minimap name format */ "RBSP", /* bsp file prefix */ 1, /* bsp file version */ diff --git a/tools/quake3/q3map2/game_nexuiz.h b/tools/quake3/q3map2/game_nexuiz.h index 70258c4..2e205d2 100644 --- a/tools/quake3/q3map2/game_nexuiz.h +++ b/tools/quake3/q3map2/game_nexuiz.h @@ -77,6 +77,7 @@ game_t struct 1.0f, /* minimap sharpener */ 1.0f/66.0f, /* minimap border */ qtrue, /* minimap keep aspect */ + MINIMAP_MODE_GRAY, /* minimap mode */ "../gfx/%s_mini.tga", /* minimap name format */ "IBSP", /* bsp file prefix */ 46, /* bsp file version */ diff --git a/tools/quake3/q3map2/game_prophecy.h b/tools/quake3/q3map2/game_prophecy.h index 2db3956..f16a515 100644 --- a/tools/quake3/q3map2/game_prophecy.h +++ b/tools/quake3/q3map2/game_prophecy.h @@ -68,6 +68,7 @@ game_t struct 1.0f, /* minimap sharpener */ 0.0f, /* minimap border */ qtrue, /* minimap keep aspect */ + MINIMAP_MODE_GRAY, /* minimap mode */ "%s.tga", /* minimap name format */ "IBSP", /* bsp file prefix */ 46, /* bsp file version */ diff --git a/tools/quake3/q3map2/game_qfusion.h b/tools/quake3/q3map2/game_qfusion.h index cf4a99c..5b5b2df 100644 --- a/tools/quake3/q3map2/game_qfusion.h +++ b/tools/quake3/q3map2/game_qfusion.h @@ -129,6 +129,7 @@ game_t struct 0.0f, /* minimap sharpener */ 0.0f, /* minimap border */ qfalse, /* minimap keep aspect */ + MINIMAP_MODE_WHITE, /* minimap mode */ "../minimaps/%s.tga", /* minimap name format */ "FBSP", /* bsp file prefix */ 1, /* bsp file version */ diff --git a/tools/quake3/q3map2/game_quake3.h b/tools/quake3/q3map2/game_quake3.h index 2236f12..949cffd 100644 --- a/tools/quake3/q3map2/game_quake3.h +++ b/tools/quake3/q3map2/game_quake3.h @@ -126,6 +126,7 @@ game_t struct 1.0f, /* minimap sharpener */ 0.0f, /* minimap border */ qtrue, /* minimap keep aspect */ + MINIMAP_MODE_GRAY, /* minimap mode */ "%s.tga", /* minimap name format */ "IBSP", /* bsp file prefix */ 46, /* bsp file version */ diff --git a/tools/quake3/q3map2/game_quakelive.h b/tools/quake3/q3map2/game_quakelive.h index 34f5671..0a0e48c 100644 --- a/tools/quake3/q3map2/game_quakelive.h +++ b/tools/quake3/q3map2/game_quakelive.h @@ -78,6 +78,7 @@ game_t struct 1.0f, /* minimap sharpener */ 0.0f, /* minimap border */ qtrue, /* minimap keep aspect */ + MINIMAP_MODE_GRAY, /* minimap mode */ "%s.tga", /* minimap name format */ "IBSP", /* bsp file prefix */ 47, /* bsp file version */ diff --git a/tools/quake3/q3map2/game_sof2.h b/tools/quake3/q3map2/game_sof2.h index 1ef5e47..db96aa5 100644 --- a/tools/quake3/q3map2/game_sof2.h +++ b/tools/quake3/q3map2/game_sof2.h @@ -153,6 +153,7 @@ game_t struct 1.0f, /* minimap sharpener */ 0.0f, /* minimap border */ qtrue, /* minimap keep aspect */ + MINIMAP_MODE_GRAY, /* minimap mode */ "%s.tga", /* minimap name format */ "RBSP", /* bsp file prefix */ 1, /* bsp file version */ diff --git a/tools/quake3/q3map2/game_tenebrae.h b/tools/quake3/q3map2/game_tenebrae.h index d767718..e6d6637 100644 --- a/tools/quake3/q3map2/game_tenebrae.h +++ b/tools/quake3/q3map2/game_tenebrae.h @@ -126,6 +126,7 @@ game_t struct 1.0f, /* minimap sharpener */ 0.0f, /* minimap border */ qtrue, /* minimap keep aspect */ + MINIMAP_MODE_GRAY, /* minimap mode */ "%s.tga", /* minimap name format */ "IBSP", /* bsp file prefix */ 46, /* bsp file version */ diff --git a/tools/quake3/q3map2/game_tremulous.h b/tools/quake3/q3map2/game_tremulous.h index 6543d09..3228d64 100644 --- a/tools/quake3/q3map2/game_tremulous.h +++ b/tools/quake3/q3map2/game_tremulous.h @@ -84,6 +84,7 @@ game_t struct 1.0f, /* minimap sharpener */ 0.0f, /* minimap border */ qtrue, /* minimap keep aspect */ + MINIMAP_MODE_GRAY, /* minimap mode */ "%s.tga", /* minimap name format */ "IBSP", /* bsp file prefix */ 46, /* bsp file version */ diff --git a/tools/quake3/q3map2/game_wolf.h b/tools/quake3/q3map2/game_wolf.h index 816994a..2e7baf4 100644 --- a/tools/quake3/q3map2/game_wolf.h +++ b/tools/quake3/q3map2/game_wolf.h @@ -143,6 +143,7 @@ game_t struct 1.0f, /* minimap sharpener */ 0.0f, /* minimap border */ qtrue, /* minimap keep aspect */ + MINIMAP_MODE_GRAY, /* minimap mode */ "%s.tga", /* minimap name format */ "IBSP", /* bsp file prefix */ 46, /* bsp file version */ diff --git a/tools/quake3/q3map2/game_wolfet.h b/tools/quake3/q3map2/game_wolfet.h index d26a173..12173d3 100644 --- a/tools/quake3/q3map2/game_wolfet.h +++ b/tools/quake3/q3map2/game_wolfet.h @@ -80,6 +80,7 @@ game_t struct 1.0f, /* minimap sharpener */ 0.0f, /* minimap border */ qtrue, /* minimap keep aspect */ + MINIMAP_MODE_GRAY, /* minimap mode */ "%s.tga", /* minimap name format */ "IBSP", /* bsp file prefix */ 46, /* bsp file version */ diff --git a/tools/quake3/q3map2/main.c b/tools/quake3/q3map2/main.c index 7e9f3b2..057a549 100644 --- a/tools/quake3/q3map2/main.c +++ b/tools/quake3/q3map2/main.c @@ -66,8 +66,6 @@ static void ExitQ3Map( void ) /* minimap stuff */ -/* borrowed from light.c */ -void WriteTGA24( char *filename, byte *data, int width, int height, qboolean flip ); typedef struct minimap_s { bspModel_t *model; @@ -532,10 +530,11 @@ int MiniMapBSPMain( int argc, char **argv ) char relativeMinimapFilename[1024]; float minimapSharpen; float border; - byte *data3b, *p; + byte *data4b, *p; float *q; int x, y; int i; + miniMapMode_t mode; vec3_t mins, maxs; qboolean keepaspect; @@ -564,6 +563,7 @@ int MiniMapBSPMain( int argc, char **argv ) minimap.width = minimap.height = game->miniMapSize; border = game->miniMapBorder; keepaspect = game->miniMapKeepAspect; + mode = game->miniMapMode; minimap.samples = 1; minimap.sample_offsets = NULL; @@ -635,6 +635,21 @@ int MiniMapBSPMain( int argc, char **argv ) i += 6; Sys_Printf( "Map mins/maxs overridden\n" ); } + else if( !strcmp( argv[ i ], "-gray" ) ) + { + mode = MINIMAP_MODE_GRAY; + Sys_Printf( "Writing as white-on-black image\n" ); + } + else if( !strcmp( argv[ i ], "-black" ) ) + { + mode = MINIMAP_MODE_BLACK; + Sys_Printf( "Writing as black alpha image\n" ); + } + else if( !strcmp( argv[ i ], "-white" ) ) + { + mode = MINIMAP_MODE_WHITE; + Sys_Printf( "Writing as white alpha image\n" ); + } } MiniMapMakeMinsMaxs(mins, maxs, border, keepaspect); @@ -647,6 +662,8 @@ int MiniMapBSPMain( int argc, char **argv ) MergeRelativePath(minimapFilename, path, relativeMinimapFilename); Sys_Printf("Output file name automatically set to %s\n", minimapFilename); } + ExtractFilePath(minimapFilename, path); + Q_mkdir(path); if(minimapSharpen >= 0) { @@ -655,7 +672,7 @@ int MiniMapBSPMain( int argc, char **argv ) } minimap.data1f = safe_malloc(minimap.width * minimap.height * sizeof(*minimap.data1f)); - data3b = safe_malloc(minimap.width * minimap.height * 3); + data4b = safe_malloc(minimap.width * minimap.height * 4); if(minimapSharpen >= 0) minimap.sharpendata1f = safe_malloc(minimap.width * minimap.height * sizeof(*minimap.data1f)); @@ -692,24 +709,61 @@ int MiniMapBSPMain( int argc, char **argv ) } Sys_Printf( "\nConverting..."); - p = data3b; - for(y = 0; y < minimap.height; ++y) - for(x = 0; x < minimap.width; ++x) - { - byte b; - float v = *q++; - if(v < 0) v = 0; - if(v > 255.0/256.0) v = 255.0/256.0; - b = v * 256; - *p++ = b; - *p++ = b; - *p++ = b; - } - Sys_Printf( " writing to %s...", minimapFilename ); - ExtractFilePath(minimapFilename, path); - Q_mkdir(path); - WriteTGA24(minimapFilename, data3b, minimap.width, minimap.height, qfalse); + switch(mode) + { + case MINIMAP_MODE_GRAY: + p = data4b; + for(y = 0; y < minimap.height; ++y) + for(x = 0; x < minimap.width; ++x) + { + byte b; + float v = *q++; + if(v < 0) v = 0; + if(v > 255.0/256.0) v = 255.0/256.0; + b = v * 256; + *p++ = b; + } + Sys_Printf( " writing to %s...", minimapFilename ); + WriteTGAGray(minimapFilename, data4b, minimap.width, minimap.height); + break; + case MINIMAP_MODE_BLACK: + p = data4b; + for(y = 0; y < minimap.height; ++y) + for(x = 0; x < minimap.width; ++x) + { + byte b; + float v = *q++; + if(v < 0) v = 0; + if(v > 255.0/256.0) v = 255.0/256.0; + b = v * 256; + *p++ = 0; + *p++ = 0; + *p++ = 0; + *p++ = b; + } + Sys_Printf( " writing to %s...", minimapFilename ); + WriteTGA(minimapFilename, data4b, minimap.width, minimap.height); + break; + case MINIMAP_MODE_WHITE: + p = data4b; + for(y = 0; y < minimap.height; ++y) + for(x = 0; x < minimap.width; ++x) + { + byte b; + float v = *q++; + if(v < 0) v = 0; + if(v > 255.0/256.0) v = 255.0/256.0; + b = v * 256; + *p++ = 255; + *p++ = 255; + *p++ = 255; + *p++ = b; + } + Sys_Printf( " writing to %s...", minimapFilename ); + WriteTGA(minimapFilename, data4b, minimap.width, minimap.height); + break; + } Sys_Printf( " done.\n" ); diff --git a/tools/quake3/q3map2/q3map2.h b/tools/quake3/q3map2/q3map2.h index c4c6a4b..e47bf79 100644 --- a/tools/quake3/q3map2/q3map2.h +++ b/tools/quake3/q3map2/q3map2.h @@ -535,6 +535,13 @@ typedef struct surfaceParm_s } surfaceParm_t; +typedef enum +{ + MINIMAP_MODE_GRAY, + MINIMAP_MODE_BLACK, + MINIMAP_MODE_WHITE +} +miniMapMode_t; typedef struct game_s { @@ -565,6 +572,7 @@ typedef struct game_s float miniMapSharpen; /* minimap sharpening coefficient */ float miniMapBorder; /* minimap border amount */ qboolean miniMapKeepAspect; /* minimap keep aspect ratio by letterboxing */ + miniMapMode_t miniMapMode; /* minimap mode */ char *miniMapNameFormat; /* minimap name format */ char *bspIdent; /* 4-letter bsp file prefix */ int bspVersion; /* bsp version to use */ -- 2.39.2