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