X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=tools%2Fquake3%2Fq3data%2Fimages.c;h=bae43f75c1f698df97d91ef651544757231ec24f;hb=131c36f6be58bba507a42f767533b061b721dfec;hp=5009ae3832ed74c76863ba5f4ce79af58219a380;hpb=bfc8a12a6b315ae261101a34db8ba1b682c67bb7;p=xonotic%2Fnetradiant.git diff --git a/tools/quake3/q3data/images.c b/tools/quake3/q3data/images.c index 5009ae38..bae43f75 100644 --- a/tools/quake3/q3data/images.c +++ b/tools/quake3/q3data/images.c @@ -1,187 +1,188 @@ /* -Copyright (C) 1999-2006 Id Software, Inc. and contributors. -For a list of contributors, see the accompanying CONTRIBUTORS file. + 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. + 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 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. + 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 -*/ + 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 "q3data.h" -byte *byteimage, *lbmpalette; -int byteimagewidth, byteimageheight; +byte *byteimage, *lbmpalette; +int byteimagewidth, byteimageheight; -char mip_prefix[1024]; // directory to dump the textures in +char mip_prefix[1024]; // directory to dump the textures in -qboolean colormap_issued; -byte colormap_palette[768]; +qboolean colormap_issued; +byte colormap_palette[768]; /* -============== -Cmd_Grab - -$grab filename x y width height -============== -*/ -void Cmd_Grab (void) -{ - int xl,yl,w,h,y; - byte *cropped; - char savename[1024]; - char dest[1024]; - - GetToken (qfalse); - - if (token[0] == '/' || token[0] == '\\') - sprintf (savename, "%s%s.pcx", writedir, token+1); - else - sprintf (savename, "%spics/%s.pcx", writedir, token); - - if (g_release) - { - if (token[0] == '/' || token[0] == '\\') - sprintf (dest, "%s.pcx", token+1); - else - sprintf (dest, "pics/%s.pcx", token); + ============== + Cmd_Grab + + $grab filename x y width height + ============== + */ +void Cmd_Grab( void ){ + int xl,yl,w,h,y; + byte *cropped; + char savename[1024]; + char dest[1024]; + + GetToken( qfalse ); + + if ( token[0] == '/' || token[0] == '\\' ) { + sprintf( savename, "%s%s.pcx", writedir, token + 1 ); + } + else{ + sprintf( savename, "%spics/%s.pcx", writedir, token ); + } - ReleaseFile (dest); + if ( g_release ) { + if ( token[0] == '/' || token[0] == '\\' ) { + sprintf( dest, "%s.pcx", token + 1 ); + } + else{ + sprintf( dest, "pics/%s.pcx", token ); + } + + ReleaseFile( dest ); return; } - GetToken (qfalse); - xl = atoi (token); - GetToken (qfalse); - yl = atoi (token); - GetToken (qfalse); - w = atoi (token); - GetToken (qfalse); - h = atoi (token); - - if (xl<0 || yl<0 || w<0 || h<0 || xl+w>byteimagewidth || yl+h>byteimageheight) - Error ("GrabPic: Bad size: %i, %i, %i, %i",xl,yl,w,h); + GetToken( qfalse ); + xl = atoi( token ); + GetToken( qfalse ); + yl = atoi( token ); + GetToken( qfalse ); + w = atoi( token ); + GetToken( qfalse ); + h = atoi( token ); + + if ( xl < 0 || yl < 0 || w < 0 || h < 0 || xl + w > byteimagewidth || yl + h > byteimageheight ) { + Error( "GrabPic: Bad size: %i, %i, %i, %i",xl,yl,w,h ); + } // crop it to the proper size - cropped = malloc (w*h); - for (y=0 ; ybyteimagewidth || yl+h>byteimageheight) - Error ("GrabPic: Bad size: %i, %i, %i, %i",xl,yl,w,h); + GetToken( qfalse ); + xl = atoi( token ); + GetToken( qfalse ); + yl = atoi( token ); + GetToken( qfalse ); + w = atoi( token ); + GetToken( qfalse ); + h = atoi( token ); + + if ( xl < 0 || yl < 0 || w < 0 || h < 0 || xl + w > byteimagewidth || yl + h > byteimageheight ) { + Error( "GrabPic: Bad size: %i, %i, %i, %i",xl,yl,w,h ); + } // crop it to the proper size - cropped = malloc (w*h); - for (y=0 ; y 255) + ============= + FindColor + ============= + */ +int FindColor( int r, int g, int b ){ + int bestcolor; + + if ( r > 255 ) { r = 255; - if (r < 0) + } + if ( r < 0 ) { r = 0; - if (g > 255) + } + if ( g > 255 ) { g = 255; - if (g < 0) + } + if ( g < 0 ) { g = 0; - if (b > 255) + } + if ( b > 255 ) { b = 255; - if (b < 0) + } + if ( b < 0 ) { b = 0; + } #ifndef TABLECOLORS - bestcolor = BestColor (r, g, b, 0, 254); + bestcolor = BestColor( r, g, b, 0, 254 ); #else - bestcolor = palmap[r>>3][g>>3][b>>3]; + bestcolor = palmap[r >> 3][g >> 3][b >> 3]; #endif return bestcolor; } -void BuildPalmap (void) -{ +void BuildPalmap( void ){ #ifdef TABLECOLORS - int r, g, b; - int bestcolor; + int r, g, b; + int bestcolor; - if (palmap_built) + if ( palmap_built ) { return; + } palmap_built = qtrue; - for (r=4 ; r<256 ; r+=8) + for ( r = 4 ; r < 256 ; r += 8 ) { - for (g=4 ; g<256 ; g+=8) + for ( g = 4 ; g < 256 ; g += 8 ) { - for (b=4 ; b<256 ; b+=8) + for ( b = 4 ; b < 256 ; b += 8 ) { - bestcolor = BestColor (r, g, b, 1, 254); - palmap[r>>3][g>>3][b>>3] = bestcolor; + bestcolor = BestColor( r, g, b, 1, 254 ); + palmap[r >> 3][g >> 3][b >> 3] = bestcolor; } } } #endif - if (!colormap_issued) - Error ("You must issue a $colormap command first"); + if ( !colormap_issued ) { + Error( "You must issue a $colormap command first" ); + } } /* -============= -AveragePixels -============= -*/ -byte AveragePixels (int count) -{ - int r,g,b; - int i; - int vis; - int pix; - int bestcolor; - byte *pal; - int fullbright; - + ============= + AveragePixels + ============= + */ +byte AveragePixels( int count ){ + int r,g,b; + int i; + int vis; + int pix; + int bestcolor; + byte *pal; + vis = 0; r = g = b = 0; - fullbright = 0; - for (i=0 ; i