move WritePCXfile to pcx.c, move the screenshot filname creation code to

COM_NextFilename in quakefs.c and fix up some remote screenshot snafus
This commit is contained in:
Bill Currie 2000-12-11 03:30:32 +00:00
parent 10e2d388db
commit a4f03b4c12
9 changed files with 121 additions and 208 deletions

View file

@ -636,25 +636,13 @@ void
SCR_ScreenShot_f (void)
{
byte *buffer;
char pcxname[80];
char checkname[MAX_OSPATH];
int i;
char pcxname[MAX_OSPATH];
//
// find a file name to save it to
//
strcpy (pcxname, "qf000.tga");
for (i = 0; i <= 999; i++) {
pcxname[2] = i / 100 + '0';
pcxname[3] = i / 10 % 10 + '0';
pcxname[4] = i % 10 + '0';
snprintf (checkname, sizeof (checkname), "%s/%s", com_gamedir, pcxname);
if (Sys_FileTime (checkname) == -1)
break; // file doesn't exist
}
if (i == 1000) {
Con_Printf ("SCR_ScreenShot_f: Couldn't create a PCX file\n");
if (!COM_NextFilename (pcxname, "qf", ".tga")) {
Con_Printf ("SCR_ScreenShot_f: Couldn't create a TGA file\n");
return;
}
@ -676,74 +664,6 @@ SCR_ScreenShot_f (void)
Con_Printf ("Wrote %s\n", pcxname);
}
/*
WritePCXfile
*/
void
WritePCXfile (char *filename, byte * data, int width, int height,
int rowbytes, byte * palette, qboolean upload)
{
int i, j, length;
pcx_t *pcx;
byte *pack;
pcx = Hunk_TempAlloc (width * height * 2 + 1000);
if (pcx == NULL) {
Con_Printf ("SCR_ScreenShot_f: not enough memory\n");
return;
}
pcx->manufacturer = 0x0a; // PCX id
pcx->version = 5; // 256 color
pcx->encoding = 1; // uncompressed
pcx->bits_per_pixel = 8; // 256 color
pcx->xmin = 0;
pcx->ymin = 0;
pcx->xmax = LittleShort ((short) (width - 1));
pcx->ymax = LittleShort ((short) (height - 1));
pcx->hres = LittleShort ((short) width);
pcx->vres = LittleShort ((short) height);
memset (pcx->palette, 0, sizeof (pcx->palette));
pcx->color_planes = 1; // chunky image
pcx->bytes_per_line = LittleShort ((short) width);
pcx->palette_type = LittleShort (2); // not a grey scale
memset (pcx->filler, 0, sizeof (pcx->filler));
// pack the image
pack = &pcx->data;
data += rowbytes * (height - 1);
for (i = 0; i < height; i++) {
for (j = 0; j < width; j++) {
if ((*data & 0xc0) != 0xc0)
*pack++ = *data++;
else {
*pack++ = 0xc1;
*pack++ = *data++;
}
}
data += rowbytes - width;
data -= rowbytes * 2;
}
// write the palette
*pack++ = 0x0c; // palette ID byte
for (i = 0; i < 768; i++)
*pack++ = *palette++;
// write output file
length = pack - (byte *) pcx;
if (upload)
CL_StartUpload ((void *) pcx, length);
else
COM_WriteFile (filename, pcx, length);
}
/*
Find closest color in the palette for named color
*/
@ -851,24 +771,7 @@ SCR_RSShot_f (void)
Con_Printf ("Remote screen shot requested.\n");
#if 0
//
// find a file name to save it to
//
strcpy (pcxname, "mquake00.pcx");
for (i = 0; i <= 99; i++) {
pcxname[6] = i / 10 + '0';
pcxname[7] = i % 10 + '0';
snprintf (checkname, sizeof (checkname), "%s/%s", com_gamedir, pcxname);
if (Sys_FileTime (checkname) == -1)
break; // file doesn't exist
}
if (i == 100) {
Con_Printf ("SCR_ScreenShot_f: Couldn't create a PCX");
return;
}
#endif
snprintf (pcxname, sizeof (pcxname), "rss.pcx");
//
// save the pcx file
@ -942,7 +845,7 @@ SCR_RSShot_f (void)
st[sizeof (st) - 1] = 0;
SCR_DrawStringToSnap (st, newbuf, w - strlen (st) * 8, h - 21, w);
WritePCXfile (pcxname, newbuf, w, h, w, host_basepal, true);
WritePCXfile (pcxname, newbuf, w, h, w, host_basepal, true, true);
free (newbuf);