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

@ -73,8 +73,6 @@ extern int snprintf(char * s, size_t maxlen, const char *format, ...);
extern int vsnprintf(char *s, size_t maxlen, const char *format, va_list arg);
#endif
#endif // _COMPAT_H
/* String utility functions */
#if !defined(strequal)
# define strequal(a,b) (strcmp (a, b) == 0)
@ -88,3 +86,5 @@ extern int vsnprintf(char *s, size_t maxlen, const char *format, va_list arg);
#if !defined(strncaseequal)
# define strncaseequal(a,b,c) (strncasecmp (a, b, c) == 0)
#endif
#endif // _COMPAT_H

View file

@ -29,6 +29,8 @@
#ifndef __pcx_h
#define __pcx_h
#include "quakeio.h"
typedef struct
{
char manufacturer;
@ -46,4 +48,9 @@ typedef struct
unsigned char data; // unbounded
} pcx_t;
void WritePCXfile (char *filename, byte * data, int width, int height,
int rowbytes, byte * palette, qboolean upload,
qboolean flip);
void LoadPCX (QFile *f);
#endif // __pcx_h

View file

@ -31,9 +31,6 @@
#ifndef _QDEFS_H
#define _QDEFS_H
#include <stdio.h>
#include <sys/types.h>
#define MAX_QPATH 64
#define MAX_CL_STATS 32
#define NUM_CSHIFTS 4

View file

@ -33,8 +33,9 @@
#include <stdio.h>
#include <sys/types.h>
#include <qdefs.h>
#include <compat.h>
#include "qdefs.h"
#include "compat.h"
#define MAX_QPATH 64

View file

@ -57,6 +57,8 @@ void COM_FileBase (char *in, char *out);
void COM_DefaultExtension (char *path, char *extension);
char *COM_SkipPath (char *pathname);
void COM_StripExtension (char *in, char *out);
int COM_NextFilename (char *filename, const char *prefix, const char *ext);
byte *COM_LoadStackFile (char *path, void *buffer, int bufsize);
byte *COM_LoadTempFile (char *path);

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);

View file

@ -30,11 +30,13 @@
# include "config.h"
#endif
#include "cl_parse.h"
#include "console.h"
#include "pcx.h"
#include "qendian.h"
#include "qtypes.h"
#include "quakefs.h"
#include "zone.h"
byte *pcx_rgb;
@ -106,3 +108,71 @@ LoadPCX (QFile *f)
}
}
}
/*
WritePCXfile
*/
void
WritePCXfile (char *filename, byte * data, int width, int height,
int rowbytes, byte * palette, qboolean upload, qboolean flip)
{
int i, j, length;
pcx_t *pcx;
byte *pack;
pcx = Hunk_TempAlloc (width * height * 2 + 1000);
if (pcx == NULL) {
Con_Printf ("WritePCXfile: 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;
if (flip)
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;
if (flip)
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);
}

View file

@ -1143,3 +1143,30 @@ COM_DefaultExtension (char *path, char *extension)
strncat (path, extension, MAX_OSPATH - strlen (path));
}
/*
COM_NextFileName
*/
int
COM_NextFilename (char *filename, const char *prefix, const char *ext)
{
char *digits;
char checkname [MAX_OSPATH];
int i;
strncpy (filename, prefix, MAX_OSPATH - 4);
filename [MAX_OSPATH - 4] = 0;
digits = filename + strlen (filename);
strcat (filename, "000");
strncat (filename, ext, MAX_OSPATH - strlen (filename));
for (i = 0; i <= 999; i++) {
digits[0] = i / 100 + '0';
digits[1] = i / 10 % 10 + '0';
digits[2] = i % 10 + '0';
snprintf (checkname, sizeof (checkname), "%s/%s", com_gamedir, filename);
if (Sys_FileTime (checkname) == -1)
return 1; // file doesn't exist
}
return 0;
}

View file

@ -661,95 +661,18 @@ SCR_DrawConsole (void)
*/
/*
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;
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;
}
// 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);
}
/*
SCR_ScreenShot_f
*/
void
SCR_ScreenShot_f (void)
{
int i;
char pcxname[80];
char checkname[MAX_OSPATH];
char pcxname[MAX_OSPATH];
//
// find a file name to save it to
//
strcpy (pcxname, "qf000.pcx");
for (i = 0; i <= 99; 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) {
if (!COM_NextFilename (pcxname, "qf", ".pcx")) {
Con_Printf ("SCR_ScreenShot_f: Couldn't create a PCX");
return;
}
@ -761,7 +684,7 @@ SCR_ScreenShot_f (void)
// buffer
WritePCXfile (pcxname, vid.buffer, vid.width, vid.height, vid.rowbytes,
host_basepal, false);
host_basepal, false, false);
D_DisableBackBufferAccess (); // for adapters that can't stay
// mapped in
@ -877,24 +800,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
@ -957,7 +863,7 @@ SCR_RSShot_f (void)
st[sizeof (st) - 1] = 0;
SCR_DrawStringToSnap (st, newbuf, w - strlen (st) * 8, 20, w);
WritePCXfile (pcxname, newbuf, w, h, w, host_basepal, true);
WritePCXfile (pcxname, newbuf, w, h, w, host_basepal, true, false);
free (newbuf);