ref: 057aa6afc8274d0907981153155f41551bb73cde
parent: 00322a469a8ecd46effac78dfa6482d1ef469ebd
author: qwx <>
date: Sun Dec 16 12:49:02 EST 2018
screenshots: write plan9 images directly instead of pcx
--- a/dat.h
+++ b/dat.h
@@ -2100,6 +2100,8 @@
extern unsigned d_8to24table[256]; // base
extern mtexinfo_t *sky_texinfo[6];
+extern int dumpwin;
+
extern cvar_t *vid_fullscreen;
extern cvar_t *vid_gamma;
extern cvar_t *scr_viewsize;
--- a/r_misc.c
+++ b/r_misc.c
@@ -426,142 +426,7 @@
d_aflatcolor = 0;
}
-
-/*
-==============================================================================
-
- SCREEN SHOTS
-
-==============================================================================
-*/
-
-
-/*
-==============
-WritePCXfile
-==============
-*/
-void WritePCXfile (char *filename, byte *data, int width, int height,
- int rowbytes, byte *palette)
+void R_ScreenShot_f (void)
{
- int i, j, length;
- pcx_t *pcx;
- byte *pack;
- FILE *f;
-
- pcx = (pcx_t *)malloc (width*height*2+1000);
- if (!pcx)
- 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;
- f = fopen (filename, "wb");
- if (!f)
- ri.Con_Printf (PRINT_ALL, "Failed to open to %s\n", filename);
- else
- {
- fwrite ((void *)pcx, 1, length, f);
- fclose (f);
- }
-
- free (pcx);
+ dumpwin = 1;
}
-
-
-
-/*
-==================
-R_ScreenShot_f
-==================
-*/
-void R_ScreenShot_f (void)
-{
- int i;
- char pcxname[80];
- char checkname[MAX_OSPATH];
- FILE *f;
- byte palette[768];
-
- // create the scrnshots directory if it doesn't exist
- Com_sprintf (checkname, sizeof(checkname), "%s/scrnshot", ri.FS_Gamedir());
- mkdir(checkname);
-
-//
-// find a file name to save it to
-//
- strcpy(pcxname,"quake00.pcx");
-
- for (i=0 ; i<=99 ; i++)
- {
- pcxname[5] = i/10 + '0';
- pcxname[6] = i%10 + '0';
- Com_sprintf (checkname, sizeof(checkname), "%s/scrnshot/%s", ri.FS_Gamedir(), pcxname);
- f = fopen (checkname, "r");
- if (!f)
- break; // file doesn't exist
- fclose (f);
- }
- if (i==100)
- {
- ri.Con_Printf (PRINT_ALL, "R_ScreenShot_f: Couldn't create a PCX");
- return;
- }
-
- // turn the current 32 bit palette into a 24 bit palette
- for (i=0 ; i<256 ; i++)
- {
- palette[i*3+0] = sw_state.currentpalette[i*4+0];
- palette[i*3+1] = sw_state.currentpalette[i*4+1];
- palette[i*3+2] = sw_state.currentpalette[i*4+2];
- }
-
-//
-// save the pcx file
-//
-
- WritePCXfile (checkname, vid.buffer, vid.width, vid.height, vid.rowbytes,
- palette);
-
- ri.Con_Printf (PRINT_ALL, "Wrote %s\n", checkname);
-}
-
--- a/vid.c
+++ b/vid.c
@@ -7,7 +7,7 @@
#include "fns.h"
refexport_t re; /* exported functions from refresh DLL */
-int resized;
+int resized, dumpwin;
Point center;
Rectangle grabr;
@@ -50,6 +50,28 @@
}
}
+/* only exists to allow taking tear-free screenshots ingame... */
+static int
+writebit(void)
+{
+ int n, fd;
+ char *s;
+
+ mkdir(va("%s/scrnshot", ri.FS_Gamedir()));
+ s = va("%s/scrnshot/quake.%d.bit", ri.FS_Gamedir(), time(nil));
+ if(access(s, AEXIST) != -1){
+ fprint(2, "writebit: not overwriting %s\n", s);
+ return -1;
+ }
+ if(fd = create(s, OWRITE, 0644), fd < 0)
+ return -1;
+ n = writeimage(fd, fbi, 0);
+ close(fd);
+ if(n >= 0)
+ ri.Con_Printf(PRINT_ALL, "Wrote %s\n", s);
+ return n;
+}
+
static void
resetfb(void)
{
@@ -84,6 +106,11 @@
loadimage(fbi, fbi->r, fb, vid.height * vid.rowbytes);
draw(screen, screen->r, fbi, nil, ZP);
flushimage(display, 1);
+ if(dumpwin){
+ if(writebit() < 0)
+ ri.Con_Printf(PRINT_ALL, "Could not write screenshot\n");
+ dumpwin = 0;
+ }
}
void