/* Copyright (C) 1999-2006 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 "q3data.h" byte *byteimage, *lbmpalette; int byteimagewidth, byteimageheight; char mip_prefix[1024]; // directory to dump the textures in 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); 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); // 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); // crop it to the proper size cropped = malloc (w*h); for (y=0 ; y 255) r = 255; if (r < 0) r = 0; if (g > 255) g = 255; if (g < 0) g = 0; if (b > 255) b = 255; if (b < 0) b = 0; #ifndef TABLECOLORS bestcolor = BestColor (r, g, b, 0, 254); #else bestcolor = palmap[r>>3][g>>3][b>>3]; #endif return bestcolor; } void BuildPalmap (void) { #ifdef TABLECOLORS int r, g, b; int bestcolor; if (palmap_built) return; palmap_built = qtrue; for (r=4 ; r<256 ; r+=8) { for (g=4 ; g<256 ; g+=8) { for (b=4 ; b<256 ; b+=8) { 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"); } /* ============= AveragePixels ============= */ byte AveragePixels (int count) { int r,g,b; int i; int vis; int pix; int bestcolor; byte *pal; int fullbright; vis = 0; r = g = b = 0; fullbright = 0; for (i=0 ; i