shithub: qk1

Download patch

ref: 7064c581f9159b45529e49c7cbeeb779f5bc0452
parent: 91c079724e36fdcf6a8a00262ff12f678ee50a22
author: Konstantinn Bonnet <qu7uux@gmail.com>
date: Sat Mar 11 06:54:15 EST 2017

screenshots: use writeimage(2) instead of pcx

--- a/dat.h
+++ b/dat.h
@@ -35,3 +35,5 @@
 	Spktvol = 255
 };
 #define Spktatt 1.0
+
+extern int dumpwin;
--- a/screen.c
+++ b/screen.c
@@ -44,10 +44,6 @@
 
 qboolean	block_drawing;
 
-static int writepcx;
-
-void SCR_ScreenShot_f (void);
-
 /*
 ===============================================================================
 
@@ -288,13 +284,12 @@
 	vid.recalc_refdef = 1;
 }
 
-//============================================================================
+static void
+screenshot(void) 
+{ 
+	dumpwin++;
+}
 
-/*
-==================
-SCR_Init
-==================
-*/
 void SCR_Init (void)
 {
 	Cvar_RegisterVariable (&scr_fov);
@@ -305,11 +300,7 @@
 	Cvar_RegisterVariable (&scr_showpause);
 	Cvar_RegisterVariable (&scr_centertime);
 	Cvar_RegisterVariable (&scr_printspeed);
-
-//
-// register our commands
-//
-	Cmd_AddCommand ("screenshot",SCR_ScreenShot_f);
+	Cmd_AddCommand("screenshot", screenshot);
 	Cmd_AddCommand ("sizeup",SCR_SizeUp_f);
 	Cmd_AddCommand ("sizedown",SCR_SizeDown_f);
 
@@ -496,111 +487,6 @@
 	}
 }
 
-
-/* 
-============================================================================== 
- 
-						SCREEN SHOTS 
- 
-============================================================================== 
-*/ 
-
-void
-SCR_ScreenShot_f(void) 
-{ 
-	writepcx++;
-}
-
-static void
-pcxout(char *path, byte *src, int dx, int dy, int xlen, byte *pal)
-{
-	int i, j;
-	uchar *buf, *p;
-
-	if((buf = Hunk_TempAlloc(dx * dy * 2 + 1000)) == nil){
-		Con_Printf("writepcx: not enough memory\n");
-		return;
-	}
-	p = buf;
-
-	/* pcx header */
-	memset(p, 0, 128);
-	p[0] = 0x0a;
-	p[1] = 5;	/* version: 24bit pcx */
-	p[2] = 1;
-	p[3] = 8;	/* bits per pixel */
-	p[8] = dx - 1;
-	p[9] = dx - 1 >> 8;
-	p[10] = dy - 1;
-	p[11] = dy - 1 >> 8;
-	p[12] = dx;	/* HDpi and VDpi */
-	p[13] = dx >> 8;
-	p[14] = dy;
-	p[15] = dy >> 8;
-	p[65] = 1;	/* number of color planes */
-	p[66] = dx;	/* scanline length */
-	p[67] = dx >> 8;
-	p[68] = 2;	/* palette type: not-greyscale greyscale */
-
-	p = buf + 128;
-	for(i=0; i<dy; i++){
-		for(j=0; j<dx; j++){
-			if((*src & 0xc0) != 0xc0)
-				*p++ = *src++;
-			else{
-				*p++ = 0xc1;
-				*p++ = *src++;
-			}
-		}
-		src += xlen - dx;
-	}
-
-	/* palette */
-	*p++ = 0x0c;
-	for(i=0; i<3*256; i++)
-		*p++ = *pal++;
-
-	USED(path);
-	/*COM_WriteFile(path, buf, p - buf);*/
-} 
-
-static void
-dopcx(void)
-{
-	int i; 
-	char pcxname[12], checkname[Nfspath];
-
-	writepcx = 0;
-
-	/* find a file name to save it to */
-	strcpy(pcxname, "quake00.pcx");
-	for(i=0; i<100; i++){
-		pcxname[5] = i / 10 + '0';
-		pcxname[6] = i % 10 + '0';
-		sprint(checkname, "%s/%s", fsdir, pcxname);
-		if(access(checkname, AEXIST) == -1)
-			break;
-	}
-	if(i == 100){
-		Con_Printf("dopcx: no free slots\n"); 
-		return;
- 	}
-
-	/* save the pcx file */
-	D_EnableBackBufferAccess();
-	pcxout(pcxname, vid.buffer, vid.width, vid.height, vid.rowbytes,
-		host_basepal);
-	/* for adapters that can't stay mapped in for linear writes all the
-	 * time */
-	D_DisableBackBufferAccess();
-
-	Con_Printf("Wrote %s\n", pcxname);
-} 
-
-
-//=============================================================================
-
-
 /*
 ===============
 SCR_BeginLoadingPlaque
@@ -885,10 +771,6 @@
 	}
 
 	V_UpdatePalette ();
-
-	/* needs to be done before vid.buffer is transformed in st3_fixup */
-	if(writepcx)
-		dopcx();
 
 //
 // update one of three areas
--- a/vid.c
+++ b/vid.c
@@ -7,6 +7,7 @@
 
 viddef_t vid;		/* global video state */
 int resized;
+int dumpwin;
 Point center;		/* of window */
 int d_con_indirect;
 void (*vid_menudrawfn)(void);
@@ -191,6 +192,31 @@
 	freeimage(fbim);
 }
 
+/* only exists to allow taking tear-free screenshots ingame... */
+static int
+writebit(void)
+{
+	int n, fd;
+	char *s;
+
+	for(n=0, s=nil; n<100; n++){
+		s = va("%s/quake%02d.bit", fsdir, n);
+		if(access(s, AEXIST) == -1)
+			break;
+	}
+	if(n == 100){
+		werrstr("at static file limit");
+		return -1;
+	}
+	if(fd = create(s, OWRITE, 0644), fd < 0)
+		return -1;
+	n = writeimage(fd, fbim, 0);
+	close(fd);
+	if(n >= 0)
+		Con_Printf("Wrote %s\n", s);
+	return n;
+}
+
 /* flush given rectangles from view buffer to the screen */
 void
 VID_Update(vrect_t *rects)
@@ -217,6 +243,11 @@
 	loadimage(fbim, fbim->r, framebuf, vid.height * vid.rowbytes);
 	draw(screen, screen->r, fbim, nil, ZP);
 	flushimage(display, 1);
+	if(dumpwin){
+		if(writebit() < 0)
+			Con_Printf("writebit: %r\n");
+		dumpwin = 0;
+	}
 }
 
 /* direct drawing of the "accessing disk" icon */