From 0375a83f2bce9f8f67525ca71b8c86c3b80a43e9 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_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_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 +++ 17 files changed, 117 insertions(+), 21 deletions(-) diff --git a/tools/quake3/common/imagelib.c b/tools/quake3/common/imagelib.c index b6fba38d..dfe16168 100644 --- a/tools/quake3/common/imagelib.c +++ b/tools/quake3/common/imagelib.c @@ -1169,6 +1169,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 37277170..f313881a 100644 --- a/tools/quake3/common/imagelib.h +++ b/tools/quake3/common/imagelib.h @@ -40,5 +40,6 @@ 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 ); int LoadJPGBuff( void *src_buffer, int src_size, unsigned char **pic, 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_ef.h b/tools/quake3/q3map2/game_ef.h index b37c3584..0a8168a0 100644 --- a/tools/quake3/q3map2/game_ef.h +++ b/tools/quake3/q3map2/game_ef.h @@ -118,6 +118,7 @@ 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 d8609e10..1f0a8962 100644 --- a/tools/quake3/q3map2/game_etut.h +++ b/tools/quake3/q3map2/game_etut.h @@ -153,6 +153,7 @@ 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_ja.h b/tools/quake3/q3map2/game_ja.h index 8069ed31..f4778043 100644 --- a/tools/quake3/q3map2/game_ja.h +++ b/tools/quake3/q3map2/game_ja.h @@ -72,6 +72,7 @@ 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 410dc585..90351e0f 100644 --- a/tools/quake3/q3map2/game_jk2.h +++ b/tools/quake3/q3map2/game_jk2.h @@ -69,6 +69,7 @@ 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 8aed61d4..e79a386c 100644 --- a/tools/quake3/q3map2/game_nexuiz.h +++ b/tools/quake3/q3map2/game_nexuiz.h @@ -68,6 +68,7 @@ 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_qfusion.h b/tools/quake3/q3map2/game_qfusion.h index b73be53f..46ca4918 100644 --- a/tools/quake3/q3map2/game_qfusion.h +++ b/tools/quake3/q3map2/game_qfusion.h @@ -117,6 +117,7 @@ 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 2065dce1..07a1c9a2 100644 --- a/tools/quake3/q3map2/game_quake3.h +++ b/tools/quake3/q3map2/game_quake3.h @@ -117,6 +117,7 @@ 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 ec4c5622..78b1329d 100644 --- a/tools/quake3/q3map2/game_quakelive.h +++ b/tools/quake3/q3map2/game_quakelive.h @@ -81,6 +81,7 @@ 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 25b31975..91b26df4 100644 --- a/tools/quake3/q3map2/game_sof2.h +++ b/tools/quake3/q3map2/game_sof2.h @@ -144,6 +144,7 @@ 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 b2141848..57e45eca 100644 --- a/tools/quake3/q3map2/game_tenebrae.h +++ b/tools/quake3/q3map2/game_tenebrae.h @@ -117,6 +117,7 @@ 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 2ff8c8ac..0f6d050f 100644 --- a/tools/quake3/q3map2/game_tremulous.h +++ b/tools/quake3/q3map2/game_tremulous.h @@ -75,6 +75,7 @@ 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 21702502..6fed3761 100644 --- a/tools/quake3/q3map2/game_wolf.h +++ b/tools/quake3/q3map2/game_wolf.h @@ -134,6 +134,7 @@ 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_wolfet.h b/tools/quake3/q3map2/game_wolfet.h index aba6cb67..57151e29 100644 --- a/tools/quake3/q3map2/game_wolfet.h +++ b/tools/quake3/q3map2/game_wolfet.h @@ -71,6 +71,7 @@ 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/main.c b/tools/quake3/q3map2/main.c index a864ff0a..a4e446d6 100644 --- a/tools/quake3/q3map2/main.c +++ b/tools/quake3/q3map2/main.c @@ -94,8 +94,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; @@ -560,10 +558,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; @@ -592,6 +591,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; @@ -663,6 +663,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); @@ -675,6 +690,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) { @@ -683,7 +700,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)); @@ -720,24 +737,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 7045c92e..42c94659 100644 --- a/tools/quake3/q3map2/q3map2.h +++ b/tools/quake3/q3map2/q3map2.h @@ -549,6 +549,13 @@ typedef struct surfaceParm_s } surfaceParm_t; +typedef enum +{ + MINIMAP_MODE_GRAY, + MINIMAP_MODE_BLACK, + MINIMAP_MODE_WHITE +} +miniMapMode_t; typedef struct game_s { @@ -570,6 +577,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 */