/* =========================================================================== Copyright (C) 1997-2006 Id Software, Inc. This file is part of Quake 2 Tools source code. Quake 2 Tools source code 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. Quake 2 Tools source code 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 Quake 2 Tools source code; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA =========================================================================== */ #include "qdata.h" char mip_prefix[1024]; // directory to dump the textures in qboolean colormap_issued; byte colormap_palette[768]; /* ============== RemapZero Replaces all 0 bytes in an image with the closest palette entry. This is because NT won't let us change index 0, so any palette animation leaves those pixels untouched. ============== */ void RemapZero (byte *pixels, byte *palette, int width, int height) { int i, c; int alt_zero; int value, best; alt_zero = 0; best = 9999999; for (i=1 ; i<255 ; i++) { value = palette[i*3+0]+palette[i*3+1]+palette[i*3+2]; if (value < best) { best = value; alt_zero = i; } } c = width*height; for (i=0 ; ibyteimagewidth || 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 = true; 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 must be multiples of sixteen SURF_WINDOW ============== */ void Cmd_Mip (void) { int x,y,xl,yl,xh,yh,w,h; byte *screen_p, *source; int linedelta; miptex_t *qtex; int miplevel, mipstep; int xx, yy, pix; int count; int flags, value, contents; mipparm_t *mp; char lumpname[64]; byte *lump_p; char filename[1024]; char animname[64]; GetToken (false); strcpy (lumpname, token); GetToken (false); xl = atoi (token); GetToken (false); yl = atoi (token); GetToken (false); w = atoi (token); GetToken (false); h = atoi (token); if ( (w & 15) || (h & 15) ) Error ("line %i: miptex sizes must be multiples of 16", scriptline); flags = 0; contents = 0; value = 0; animname[0] = 0; // get optional flags and values while (TokenAvailable ()) { GetToken (false); for (mp=mipparms ; mp->name ; mp++) { if (!strcmp(mp->name, token)) { switch (mp->type) { case pt_animvalue: GetToken (false); // specify the next animation frame strcpy (animname, token); break; case pt_flags: flags |= mp->flags; break; case pt_contents: contents |= mp->flags; break; case pt_flagvalue: flags |= mp->flags; GetToken (false); // specify the light value value = atoi(token); break; } break; } } if (!mp->name) Error ("line %i: unknown parm %s", scriptline, token); } sprintf (filename, "%stextures/%s/%s.wal", gamedir, mip_prefix, lumpname); if (g_release) return; // textures are only released by $maps xh = xl+w; yh = yl+h; qtex = malloc (sizeof(miptex_t) + w*h*2); memset (qtex, 0, sizeof(miptex_t)); qtex->width = LittleLong(w); qtex->height = LittleLong(h); qtex->flags = LittleLong(flags); qtex->contents = LittleLong(contents); qtex->value = LittleLong(value); sprintf (qtex->name, "%s/%s", mip_prefix, lumpname); if (animname[0]) sprintf (qtex->animname, "%s/%s", mip_prefix, animname); lump_p = (byte *)(&qtex->value+1); screen_p = byteimage + yl*byteimagewidth + xl; linedelta = byteimagewidth - w; source = lump_p; qtex->offsets[0] = LittleLong(lump_p - (byte *)qtex); for (y=yl ; yoffsets[miplevel] = LittleLong(lump_p - (byte *)qtex); mipstep = 1<