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
This commit is contained in:
divverent 2009-04-27 16:57:55 +00:00 committed by Thomas Debesse
parent 75ba6b77ec
commit 0375a83f2b
17 changed files with 117 additions and 21 deletions

View file

@ -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);
}
/*
============================================================================

View file

@ -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 );

View file

@ -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 */

View file

@ -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 */

View file

@ -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 */

View file

@ -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 */

View file

@ -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 */

View file

@ -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 */

View file

@ -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 */

View file

@ -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 */

View file

@ -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 */

View file

@ -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 */

View file

@ -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 */

View file

@ -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 */

View file

@ -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 */

View file

@ -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,7 +737,11 @@ int MiniMapBSPMain( int argc, char **argv )
}
Sys_Printf( "\nConverting...");
p = data3b;
switch(mode)
{
case MINIMAP_MODE_GRAY:
p = data4b;
for(y = 0; y < minimap.height; ++y)
for(x = 0; x < minimap.width; ++x)
{
@ -730,14 +751,47 @@ int MiniMapBSPMain( int argc, char **argv )
if(v > 255.0/256.0) v = 255.0/256.0;
b = v * 256;
*p++ = b;
*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 );
ExtractFilePath(minimapFilename, path);
Q_mkdir(path);
WriteTGA24(minimapFilename, data3b, minimap.width, minimap.height, qfalse);
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" );

View file

@ -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 */