#include "qlumpy.h" typedef struct { short ofs, length; } row_t; typedef struct { int width, height; int widthbits, heightbits; unsigned char data[4]; } qtex_t; typedef struct { int width, height; byte data[4]; // variably sized } qpic_t; #define SCRN(x,y) (*(byteimage+(y)*byteimagewidth+x)) /* ============== GrabRaw filename RAW x y width height ============== */ void GrabRaw (void) { int x,y,xl,yl,xh,yh,w,h; byte *screen_p; int linedelta; GetToken (false); xl = atoi (token); GetToken (false); yl = atoi (token); GetToken (false); w = atoi (token); GetToken (false); h = atoi (token); xh = xl+w; yh = yl+h; screen_p = byteimage + yl*byteimagewidth + xl; linedelta = byteimagewidth - w; for (y=yl ; y319 || yh>199) Error ("GrabPic: Bad size: %i, %i, %i, %i",xl,yl,xh,yh); transcolor = 255; // // fill in header // header = (qpic_t *)lump_p; width = xh-xl+1; header->width = LittleLong(width); header->height = LittleLong(yh-yl+1); // // start grabbing posts // lump_p = (byte *)header->data; for (y=yl ; y<= yh ; y++) for (x=xl ; x<=xh ; x++) *lump_p++ = SCRN(x,y); } /* ============================================================================= COLORMAP GRABBING ============================================================================= */ /* =============== BestColor =============== */ byte BestColor (int r, int g, int b, int start, int stop) { int i; int dr, dg, db; int bestdistortion, distortion; int bestcolor; byte *pal; // // let any color go to 0 as a last resort // bestdistortion = ( (int)r*r + (int)g*g + (int)b*b )*2; bestcolor = 0; pal = lbmpalette + start*3; for (i=start ; i<= stop ; i++) { dr = r - (int)pal[0]; dg = g - (int)pal[1]; db = b - (int)pal[2]; pal += 3; distortion = dr*dr + dg*dg + db*db; if (distortion < bestdistortion) { if (!distortion) return i; // perfect match bestdistortion = distortion; bestcolor = i; } } return bestcolor; } /* ============== GrabColormap filename COLORMAP levels fullbrights the first map is an identiy 0-255 the final map is all black except for the fullbrights the remaining maps are evenly spread fullbright colors start at the top of the palette. ============== */ void GrabColormap (void) { int levels, brights; int l, c; float frac, red, green, blue; GetToken (false); levels = atoi (token); GetToken (false); brights = atoi (token); // identity lump for (l=0 ; l<256 ; l++) *lump_p++ = l; // shaded levels for (l=1;l= 240) { return pix; if (!fullbright) { fullbright = true; r = 0; g = 0; b = 0; } } else { if (fullbright) continue; } r += lbmpalette[pix*3]; g += lbmpalette[pix*3+1]; b += lbmpalette[pix*3+2]; vis++; } if (fullbright == 2) return 255; r /= vis; g /= vis; b /= vis; if (!fullbright) { r += d_red; g += d_green; b += d_blue; } // // find the best color // bestdistortion = r*r + g*g + b*b; bestcolor = 0; if (fullbright) { i = 240; e = 255; } else { i = 0; e = 240; } for ( ; i< e ; i++) { pix = i; //pixdata[i]; pal = lbmpalette + pix*3; dr = r - (int)pal[0]; dg = g - (int)pal[1]; db = b - (int)pal[2]; distortion = dr*dr + dg*dg + db*db; if (distortion < bestdistortion) { if (!distortion) { d_red = d_green = d_blue = 0; // no distortion yet return pix; // perfect match } bestdistortion = distortion; bestcolor = pix; } } if (!fullbright) { // error diffusion pal = lbmpalette + bestcolor*3; d_red = r - (int)pal[0]; d_green = g - (int)pal[1]; d_blue = b - (int)pal[2]; } return bestcolor; } /* ============== GrabMip filename MIP x y width height must be multiples of sixteen ============== */ void GrabMip (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; 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); xh = xl+w; yh = yl+h; qtex = (miptex_t *)lump_p; qtex->width = LittleLong(w); qtex->height = LittleLong(h); strcpy (qtex->name, lumpname); lump_p = (byte *)&qtex->offsets[4]; 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<