2007-11-04 03:34:51 +00:00
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
Copyright (C) 1999-2007 id Software, Inc. and contributors.
|
|
|
|
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
This file is part of GtkRadiant.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GtkRadiant is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GtkRadiant is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with GtkRadiant; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
#include "qdata.h"
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
byte *byteimage, *lbmpalette;
|
|
|
|
int byteimagewidth, byteimageheight;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
qboolean TrueColorImage;
|
|
|
|
unsigned *longimage;
|
|
|
|
int longimagewidth, longimageheight;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
char pic_prefix[1024];
|
|
|
|
extern char *g_outputDir;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
===============
|
|
|
|
Cmd_Pic
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
|
|
|
|
void Cmd_Pic( void ){
|
|
|
|
int xl,yl,xh,yh,w,h;
|
2007-11-04 03:34:51 +00:00
|
|
|
byte *dest, *source;
|
2012-03-17 20:01:54 +00:00
|
|
|
int flags, value, contents;
|
|
|
|
char lumpname[128];
|
|
|
|
char animname[128];
|
|
|
|
byte buffer[256 * 256];
|
|
|
|
unsigned bufferl[256 * 256];
|
|
|
|
char filename[1024];
|
2007-11-04 03:34:51 +00:00
|
|
|
unsigned *destl, *sourcel;
|
2012-03-17 20:01:54 +00:00
|
|
|
int linedelta, x, y;
|
|
|
|
int size;
|
|
|
|
miptex_t *qtex;
|
|
|
|
miptex32_t *qtex32;
|
|
|
|
float scale_x, scale_y;
|
|
|
|
|
|
|
|
GetScriptToken( false );
|
|
|
|
strcpy( lumpname, token );
|
|
|
|
|
|
|
|
GetScriptToken( false );
|
|
|
|
xl = atoi( token );
|
|
|
|
GetScriptToken( false );
|
|
|
|
yl = atoi( token );
|
|
|
|
GetScriptToken( false );
|
|
|
|
w = atoi( token );
|
|
|
|
GetScriptToken( false );
|
|
|
|
h = atoi( token );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
total_x += w;
|
|
|
|
total_y += h;
|
|
|
|
total_textures++;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ( w & 7 ) || ( h & 7 ) ) {
|
|
|
|
Error( "line %i: miptex sizes must be multiples of 8", scriptline );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
flags = 0;
|
|
|
|
contents = 0;
|
|
|
|
value = 0;
|
|
|
|
|
|
|
|
animname[0] = 0;
|
|
|
|
|
|
|
|
scale_x = scale_y = 0.5;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( TrueColorImage ) {
|
|
|
|
sprintf( filename, "%spics/%s/%s.m32", g_outputDir, pic_prefix, lumpname );
|
|
|
|
if ( g_release ) {
|
|
|
|
return; // textures are only released by $maps
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
xh = xl + w;
|
|
|
|
yh = yl + h;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( xl >= longimagewidth || xh > longimagewidth ||
|
|
|
|
yl >= longimageheight || yh > longimageheight ) {
|
|
|
|
Error( "line %i: bad clip dimmensions (%d,%d) (%d,%d) > image (%d,%d)", scriptline, xl,yl,w,h,longimagewidth,longimageheight );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
sourcel = longimage + ( yl * longimagewidth ) + xl;
|
2007-11-04 03:34:51 +00:00
|
|
|
destl = bufferl;
|
2012-03-17 20:01:54 +00:00
|
|
|
linedelta = ( longimagewidth - w );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( y = yl ; y < yh ; y++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( x = xl ; x < xh ; x++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
*destl++ = *sourcel++; // RGBA
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
sourcel += linedelta;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
qtex32 = CreateMip32( bufferl, w, h, &size, false );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
qtex32->flags |= LittleLong( flags );
|
2007-11-04 03:34:51 +00:00
|
|
|
qtex32->contents = contents;
|
|
|
|
qtex32->value = value;
|
|
|
|
qtex32->scale_x = scale_x;
|
|
|
|
qtex32->scale_y = scale_y;
|
2012-03-17 20:01:54 +00:00
|
|
|
sprintf( qtex32->name, "%s/%s", pic_prefix, lumpname );
|
|
|
|
if ( animname[0] ) {
|
|
|
|
sprintf( qtex32->animname, "%s/%s", pic_prefix, animname );
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// write it out
|
|
|
|
//
|
|
|
|
printf( "writing %s\n", filename );
|
|
|
|
SaveFile( filename, (byte *)qtex32, size );
|
|
|
|
|
|
|
|
free( qtex32 );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
sprintf( filename, "%spics/%s/%s.m8", g_outputDir, pic_prefix, lumpname );
|
|
|
|
if ( g_release ) {
|
|
|
|
return; // textures are only released by $maps
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
xh = xl + w;
|
|
|
|
yh = yl + h;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( xl >= byteimagewidth || xh > byteimagewidth ||
|
|
|
|
yl >= byteimageheight || yh > byteimageheight ) {
|
|
|
|
Error( "line %i: bad clip dimmensions (%d,%d) (%d,%d) > image (%d,%d)", scriptline, xl,yl,w,h,byteimagewidth,byteimageheight );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
source = byteimage + yl * byteimagewidth + xl;
|
2007-11-04 03:34:51 +00:00
|
|
|
dest = buffer;
|
|
|
|
linedelta = byteimagewidth - w;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( y = yl ; y < yh ; y++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( x = xl ; x < xh ; x++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
*dest++ = *source++;
|
|
|
|
}
|
|
|
|
source += linedelta;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
qtex = CreateMip( buffer, w, h, lbmpalette, &size, false );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
qtex->flags = flags;
|
|
|
|
qtex->contents = contents;
|
|
|
|
qtex->value = value;
|
2012-03-17 20:01:54 +00:00
|
|
|
sprintf( qtex->name, "%s/%s", pic_prefix, lumpname );
|
|
|
|
if ( animname[0] ) {
|
|
|
|
sprintf( qtex->animname, "%s/%s", pic_prefix, animname );
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// write it out
|
|
|
|
//
|
|
|
|
printf( "writing %s\n", filename );
|
|
|
|
SaveFile( filename, (byte *)qtex, size );
|
|
|
|
|
|
|
|
free( qtex );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
===============
|
|
|
|
Cmd_picdir
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
void Cmd_Picdir( void ){
|
|
|
|
char filename[1024];
|
|
|
|
|
|
|
|
GetScriptToken( false );
|
|
|
|
strcpy( pic_prefix, token );
|
2007-11-04 03:34:51 +00:00
|
|
|
// create the directory if needed
|
2012-03-17 20:01:54 +00:00
|
|
|
sprintf( filename, "%sPics", g_outputDir );
|
|
|
|
Q_mkdir( filename );
|
|
|
|
sprintf( filename, "%sPics/%s", g_outputDir, pic_prefix );
|
|
|
|
Q_mkdir( filename );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|