Example #1
0
/*
==================
SCR_ScreenShot_f -- johnfitz -- rewritten to use Image_WriteTGA
==================
*/
void SCR_ScreenShot_f (void)
{
	byte	*buffer;
	char	tganame[16];  //johnfitz -- was [80]
	char	checkname[MAX_OSPATH];
	int	i;

// find a file name to save it to
	for (i=0; i<10000; i++)
	{
		q_snprintf (tganame, sizeof(tganame), "spasm%04i.tga", i);	// "fitz%04i.tga"
		q_snprintf (checkname, sizeof(checkname), "%s/%s", com_gamedir, tganame);
		if (Sys_FileTime(checkname) == -1)
			break;	// file doesn't exist
	}
	if (i == 10000)
	{
		Con_Printf ("SCR_ScreenShot_f: Couldn't find an unused filename\n");
		return;
 	}

//get data
	buffer = (byte *) malloc(glwidth*glheight*3);
	glReadPixels (glx, gly, glwidth, glheight, GL_RGB, GL_UNSIGNED_BYTE, buffer);

// now write the file
	if (Image_WriteTGA (tganame, buffer, glwidth, glheight, 24, false))
		Con_Printf ("Wrote %s\n", tganame);
	else
		Con_Printf ("SCR_ScreenShot_f: Couldn't create a TGA file\n");

	free (buffer);
}
Example #2
0
/* 
================== 
SCR_ScreenShot_f
================== 
*/  
void SCR_ScreenShot_f (void) 
{ 
	int     	i; 
	char		pcxname[80]; 
	char		checkname[MAX_OSPATH];

// 
// find a file name to save it to 
// 
#if defined (__APPLE__) || defined (MACOSX)
        qboolean	success = false;

	strcpy(pcxname,"quake00.png");
#else
	strcpy(pcxname,"quake00.pcx");
#endif /* __APPLE__ || MACOSX */
		
	for (i=0 ; i<=99 ; i++) 
	{ 
		pcxname[5] = i/10 + '0'; 
		pcxname[6] = i%10 + '0'; 
#if defined (__APPLE__) || defined (MACOSX)
		snprintf (checkname, MAX_OSPATH, "%s/%s", com_gamedir, pcxname);
#else
		sprintf (checkname, "%s/%s", com_gamedir, pcxname);
#endif /* __APPLE__ || MACOSX */
		if (Sys_FileTime(checkname) == -1)
			break;	// file doesn't exist
	} 
	if (i==100) 
	{
#if defined (__APPLE__) || defined (MACOSX)
		Con_Printf ("SCR_ScreenShot_f: Couldn't create a PNG file\n");
#else
		Con_Printf ("SCR_ScreenShot_f: Couldn't create a PCX file\n");
#endif /* __APPLE__ || MACOSX */
		return;
	}
 
// 
// save the pcx file 
// 
	D_EnableBackBufferAccess ();	// enable direct drawing of console to back
									//  buffer

#if defined (__APPLE__) || defined (MACOSX)
        success = WritePNGFile (checkname, vid.buffer, vid.width, vid.height, vid.rowbytes, host_basepal);
	D_DisableBackBufferAccess ();	// for adapters that can't stay mapped in
                                        //  for linear writes all the time
        if (success == true)
        {
            Con_Printf ("Wrote %s\n", pcxname);
        }
#else
	WritePCXfile (pcxname, vid.buffer, vid.width, vid.height, vid.rowbytes, host_basepal);
	D_DisableBackBufferAccess ();	// for adapters that can't stay mapped in
                                        //  for linear writes all the time
	Con_Printf ("Wrote %s\n", pcxname);
#endif /* __APPLE__ ||ÊMACOSX */
} 
Example #3
0
void SV_Snap (int uid)
{
	client_t *cl;
	char		pcxname[80]; 
	char		checkname[MAX_OSPATH];
	int			i;

	for (i = 0, cl = svs.clients; i < MAX_CLIENTS; i++, cl++)
	{
		if (!cl->state)
			continue;
		if (cl->userid == uid)
			break;
	}
	if (i >= MAX_CLIENTS) {
		Con_Printf ("userid not found\n");
		return;
	}

	sprintf(pcxname, "%d-00.pcx", uid);

	sprintf(checkname, "%s/snap", gamedirfile);
	Sys_mkdir(gamedirfile);
	Sys_mkdir(checkname);
		
	for (i=0 ; i<=99 ; i++) 
	{ 
		pcxname[strlen(pcxname) - 6] = i/10 + '0'; 
		pcxname[strlen(pcxname) - 5] = i%10 + '0'; 
		sprintf (checkname, "%s/snap/%s", gamedirfile, pcxname);
		if (Sys_FileTime(checkname) == -1)
			break;	// file doesn't exist
	} 
	if (i==100) 
	{
		Con_Printf ("Snap: Couldn't create a file, clean some out.\n"); 
		return;
	}
	strcpy(cl->uploadfn, checkname);

	memcpy(&cl->snap_from, &net_from, sizeof(net_from));
	if (sv_redirected != RD_NONE)
		cl->remote_snap = true;
	else
		cl->remote_snap = false;

	ClientReliableWrite_Begin (cl, svc_stufftext, 24);
	ClientReliableWrite_String (cl, "cmd snap");
	Con_Printf ("Requesting snap from user %d...\n", uid);
}
Example #4
0
void quake::screen::screenshot(const quake::common::argv & argv) {
    std::string name { "/quake00.png" };
    for (int i = 0; i <= 99; i++) {
        name[6] = '0' + (i / 10);
        name[7] = '0' + (i % 10);

        std::string fullname = com_gamedir + name;
        if (Sys_FileTime(fullname.c_str()) == -1) {
            _take_shot_named(fullname);
            return;
        }
    }
    Con_Printf("SCR_ScreenShot_f: Couldn't create a PNG file\n");
}
Example #5
0
void Movie_Start_f (void)
{
    char	name[MAX_OSPATH], path[256]; //qb: jqavi was MAX_FILELENGTH
    int     i;

    if (Cmd_Argc() != 2) //qb: autogenerate file name if none is given.
    {
        Q_strcpy(name,"qbs8_000.avi"); //qb: screenshots dir

        for (i=0 ; i<=999 ; i++)
        {
            name[5] = i/100 + '0';
            name[6] = (i/10)%10 + '0';
            name[7] = i%10 + '0';
            sprintf (path, "%s/%s/%s", com_gamedir, "screenshots", name);
            if (Sys_FileTime(path) == -1)
                break;	// file doesn't exist
        }
        if (i==1000)
        {
            Con_Printf ("Movie_Start_f: Too many AVI files in directory.\n");
            return;
        }
    }
    else
    {
        Q_strncpyz (name, Cmd_Argv(1), sizeof(name));
        COM_ForceExtension (name, ".avi");
    }

    hack_ctr = capture_hack.value;
    Q_snprintfz (path, sizeof(path), "%s/%s/%s", com_gamedir, "screenshots", name);
    if (!(moviefile = fopen(path, "wb")))
    {
        COM_CreatePath (path);
        if (!(moviefile = fopen(path, "wb")))
        {
            Con_Printf ("ERROR: Couldn't open %s\n", name);
            return;
        }
    }
    movie_is_capturing = Capture_Open (path);
    if (movie_is_capturing)
        Con_DPrintf("Capturing video %s\n", path);  //qb: is printed on the vid, so only in debug mode.
    else
        Con_Printf("Movie_Start_f: Movie capture open failed.\n");
}
Example #6
0
void L_CaptureCubeMap(void)
{
    char filename[100];
    int i;
    sprintf(filename,"%s/cubemaps/cube00_top.pcx",com_gamedir);
    int len = strlen(filename);
    for (i=0; i<99; ++i)
    {
        filename[len-10] = i/10 + '0';
        filename[len-9] = i%10 + '0';
        if (Sys_FileTime(filename) == -1)
            break;
    }
    if (i == 100)
    {
        Con_Printf("Too many saved cubemaps, reached limit of 100\n");
        return;
    }

    extern void WritePCXfile(char *filename, byte *data, int width, int height, int rowbytes, byte *palette);

#define SET_FILE_FACE(face) sprintf(filename,"cubemaps/cube%02d_" face ".pcx",i);
#define WRITE_FILE(n) WritePCXfile(filename,cubemap+cubesize*cubesize*n,cubesize,cubesize,cubesize,host_basepal);

    SET_FILE_FACE("front");
    WRITE_FILE(BOX_FRONT);
    SET_FILE_FACE("right");
    WRITE_FILE(BOX_RIGHT);
    SET_FILE_FACE("behind");
    WRITE_FILE(BOX_BEHIND);
    SET_FILE_FACE("left");
    WRITE_FILE(BOX_LEFT);
    SET_FILE_FACE("top");
    WRITE_FILE(BOX_TOP);
    SET_FILE_FACE("bottom");
    WRITE_FILE(BOX_BOTTOM);

#undef SET_FILE_FACE
#undef WRITE_FILE

    Con_Printf("Saved cubemap to cube%02d_XXXX.pcx\n",i);
}
Example #7
0
/* 
================== 
SCR_ScreenShot_f
================== 
*/  
void SCR_ScreenShot_f (void) 
{ 
	int     i; 
	char		pcxname[80]; 
	char		checkname[MAX_OSPATH];

	sprintf (checkname, "%s/shots", com_gamedir);
	Sys_mkdir (checkname);
// 
// find a file name to save it to 
// 
	strcpy(pcxname,"shots/hexen00.pcx");
		
	for (i=0 ; i<=99 ; i++) 
	{ 
		pcxname[11] = i/10 + '0'; 
		pcxname[12] = i%10 + '0'; 
		sprintf (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 file\n"); 
		return;
 	}

// 
// save the pcx file 
// 
	D_EnableBackBufferAccess ();	// enable direct drawing of console to back
									//  buffer

	WritePCXfile (pcxname, vid.buffer, vid.width, vid.height, vid.rowbytes,
				  host_basepal);

	D_DisableBackBufferAccess ();	// for adapters that can't stay mapped in
									//  for linear writes all the time

	Con_Printf ("Wrote %s\n", pcxname);
} 
Example #8
0
/* 
================== 
SCR_ScreenShot_f
================== 
*/  
void SCR_ScreenShot_f (void) 
{
	byte		*buffer;
	char		tganame[16]; 
	char		checkname[MAX_OSPATH];
	int			i;

//
// find a file name to save it to 
//
	for (i=0; i<10000; i++)
	{ 
		sprintf (tganame, "quake%04i.tga", i);
		sprintf (checkname, "%s/%s", com_gamedir, tganame);
		if (Sys_FileTime(checkname) == -1)
			break;	// file doesn't exist
	} 
	if (i == 10000)
	{
		Con_Printf ("SCR_ScreenShot_f: Couldn't find an unused filename\n"); 
		return;
	}

//
// get data
//
	buffer = malloc(glwidth * glheight * 4);

	glReadPixels (glx, gly, glwidth, glheight, GL_RGBA, GL_UNSIGNED_BYTE, buffer);

//
// now write the file
//
	if (Image_WriteTGA (tganame, buffer, glwidth, glheight, 32, false))
		Con_Printf ("Wrote %s\n", tganame);
	else
		Con_Printf ("SCR_ScreenShot_f: Couldn't create a TGA file\n");

	free (buffer);
} 
void SCR_ScreenShot_f (void)
{
	uint8_t	*buffer;
	char	tganame[32], checkname[PLATFORM_MAX_PATH];
	int		i;

	if (!plCreateDirectory(va("%s/%s", com_gamedir, g_state.cScreenshotPath)))
		Sys_Error("Failed to create directory!\n%s", plGetError());

	// find a file name to save it to
	for (i = 0; i < 10000; i++)
	{
		sprintf(tganame, "%s%04i.tga", g_state.cScreenshotPath, i);
		sprintf(checkname,"%s/%s",com_gamedir,tganame);
		if(Sys_FileTime(checkname) == -1)
			break;	// file doesn't exist
	}

	if(i >= 10000)
	{
		Con_Printf ("SCR_ScreenShot_f: Couldn't find an unused filename\n");
		return;
	}

	//get data
	buffer = (uint8_t*)malloc(glwidth*glheight*3);
	glReadPixels(glx,gly,glwidth,glheight,GL_RGB,GL_UNSIGNED_BYTE,buffer);

	// now write the file
	if(Image_WriteTGA(tganame,buffer,glwidth,glheight,24,false))
		Con_Printf("Wrote %s\n",tganame);
	else
		Con_Warning("Failed to write %s\n",tganame);

	free (buffer);
}
Example #10
0
/* 
================== 
SCR_RSShot_f
================== 
*/  
void SCR_RSShot_f (void) 
{ 
	int     	x, y;
	unsigned char	*src, *dest;
	char		pcxname[80];
#if 0
        int		i;
	char		checkname[MAX_OSPATH];
#endif
	unsigned char		*newbuf; //, *srcbuf;
//	int srcrowbytes;
	int w, h;
	int dx, dy, dex, dey, nx;
	int r, b, g;
	int count;
	float fracw, frach;
	char st[80];
	time_t now;

	if (CL_IsUploading())
		return; // already one pending

	if (cls.state < ca_onserver)
		return; // gotta be connected

	if (!scr_allowsnap.value) {
		MSG_WriteByte (&cls.netchan.message, clc_stringcmd);
		SZ_Print (&cls.netchan.message, "snap\n");
		Con_Printf("Refusing remote screen shot request.\n");
		return;
	}

	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'; 
#if defined (__APPLE__) || defined (MACOSX)
		snprintf (checkname, MAX_OSPATH, "%s/%s", com_gamedir, pcxname);
#else
		sprintf (checkname, "%s/%s", com_gamedir, pcxname);
#endif /* __APPLE__ || MACOSX */
		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
 
// 
// save the pcx file 
// 
	D_EnableBackBufferAccess ();	// enable direct drawing of console to back
									//  buffer

	w = (vid.width < RSSHOT_WIDTH) ? vid.width : RSSHOT_WIDTH;
	h = (vid.height < RSSHOT_HEIGHT) ? vid.height : RSSHOT_HEIGHT;

	fracw = (float)vid.width / (float)w;
	frach = (float)vid.height / (float)h;

	newbuf = malloc(w*h);

	for (y = 0; y < h; y++) {
		dest = newbuf + (w * y);

		for (x = 0; x < w; x++) {
			r = g = b = 0;

			dx = x * fracw;
			dex = (x + 1) * fracw;
			if (dex == dx) dex++; // at least one
			dy = y * frach;
			dey = (y + 1) * frach;
			if (dey == dy) dey++; // at least one

			count = 0;
			for (/* */; dy < dey; dy++) {
				src = vid.buffer + (vid.rowbytes * dy) + dx;
				for (nx = dx; nx < dex; nx++) {
					r += host_basepal[*src * 3];
					g += host_basepal[*src * 3+1];
					b += host_basepal[*src * 3+2];
					src++;
					count++;
				}
			}
			r /= count;
			g /= count;
			b /= count;
			*dest++ = MipColor(r, g, b);
		}
	}

	time(&now);
	strcpy(st, ctime(&now));
	st[strlen(st) - 1] = 0;
	SCR_DrawStringToSnap (st, newbuf, w - ((int) strlen(st))*8, 0, w);

	strncpy(st, cls.servername, sizeof(st));
	st[sizeof(st) - 1] = 0;
	SCR_DrawStringToSnap (st, newbuf, w - ((int) strlen(st))*8, 10, w);

	strncpy(st, name.string, sizeof(st));
	st[sizeof(st) - 1] = 0;
	SCR_DrawStringToSnap (st, newbuf, w - ((int) strlen(st))*8, 20, w);

	WritePCXfile (pcxname, newbuf, w, h, w, host_basepal, true);

	free(newbuf);

	D_DisableBackBufferAccess ();	// for adapters that can't stay mapped in
									//  for linear writes all the time

//	Con_Printf ("Wrote %s\n", pcxname);
	Con_Printf ("Sending shot to server...\n");
} 
Example #11
0
dir_t Sys_listdir (const char *path, const char *ext, int sort_type)
{
	static file_t	list[MAX_DIRFILES];
	dir_t	dir;
	HANDLE	h;
	WIN32_FIND_DATA fd;
	char	pathname[MAX_DEMO_NAME];
	qbool all;

	int	r;
	pcre	*preg;
	const char	*errbuf;

	memset(list, 0, sizeof(list));
	memset(&dir, 0, sizeof(dir));

	dir.files = list;
	all = !strncmp(ext, ".*", 3);
	if (!all)
		if (!(preg = pcre_compile(ext, PCRE_CASELESS, &errbuf, &r, NULL)))
		{
			Con_Printf("Sys_listdir: pcre_compile(%s) error: %s at offset %d\n",
			           ext, errbuf, r);
			Q_free(preg);
			return dir;
		}

	snprintf(pathname, sizeof(pathname), "%s/*.*", path);
	if ((h = FindFirstFile (pathname , &fd)) == INVALID_HANDLE_VALUE)
	{
		if (!all)
			Q_free(preg);
		return dir;
	}

	do
	{
		if (!strncmp(fd.cFileName, ".", 2) || !strncmp(fd.cFileName, "..", 3))
			continue;
		if (!all)
		{
			switch (r = pcre_exec(preg, NULL, fd.cFileName,
			                      strlen(fd.cFileName), 0, 0, NULL, 0))
			{
			case 0: break;
			case PCRE_ERROR_NOMATCH: continue;
			default:
				Con_Printf("Sys_listdir: pcre_exec(%s, %s) error code: %d\n",
				           ext, fd.cFileName, r);
				if (!all)
					Q_free(preg);
				return dir;
			}
		}

		if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) //bliP: list dir
		{
			dir.numdirs++;
			list[dir.numfiles].isdir = true;
			list[dir.numfiles].size = list[dir.numfiles].time = 0;
		}
		else
		{
			list[dir.numfiles].isdir = false;
			snprintf(pathname, sizeof(pathname), "%s/%s", path, fd.cFileName);
			list[dir.numfiles].time = Sys_FileTime(pathname);
			dir.size += (list[dir.numfiles].size = fd.nFileSizeLow);
		}
		strlcpy (list[dir.numfiles].name, fd.cFileName, sizeof(list[0].name));

		if (++dir.numfiles == MAX_DIRFILES - 1)
			break;

	}
	while (FindNextFile(h, &fd));

	FindClose (h);
	if (!all)
		Q_free(preg);

	switch (sort_type)
	{
	case SORT_NO: break;
	case SORT_BY_DATE:
		qsort((void *)list, dir.numfiles, sizeof(file_t), Sys_compare_by_date);
		break;
	case SORT_BY_NAME:
		qsort((void *)list, dir.numfiles, sizeof(file_t), Sys_compare_by_name);
		break;
	}
	return dir;
}
Example #12
0
/*
==================
SCR_ScreenShot_f -- johnfitz -- rewritten to use Image_WriteTGA
==================
*/
void SCR_ScreenShot_f (void)
{
	byte	*buffer;
	char	ext[4];
	char	imagename[16];  //johnfitz -- was [80]
	char	checkname[MAX_OSPATH];
	int	i, quality;
	qboolean	ok;

	Q_strncpy (ext, "png", sizeof(ext));

	if (Cmd_Argc () >= 2)
	{
		const char	*requested_ext = Cmd_Argv (1);

		if (!q_strcasecmp ("png", requested_ext)
		    || !q_strcasecmp ("tga", requested_ext)
		    || !q_strcasecmp ("jpg", requested_ext))
			Q_strncpy (ext, requested_ext, sizeof(ext));
		else
		{
			SCR_ScreenShot_Usage ();
			return;
		}
	}

// read quality as the 3rd param (only used for JPG)
	quality = 90;
	if (Cmd_Argc () >= 3)
		quality = Q_atoi (Cmd_Argv(2));
	if (quality < 1 || quality > 100)
	{
		SCR_ScreenShot_Usage ();
		return;
	}
	
// find a file name to save it to
	for (i=0; i<10000; i++)
	{
		q_snprintf (imagename, sizeof(imagename), "spasm%04i.%s", i, ext);	// "fitz%04i.tga"
		q_snprintf (checkname, sizeof(checkname), "%s/%s", com_gamedir, imagename);
		if (Sys_FileTime(checkname) == -1)
			break;	// file doesn't exist
	}
	if (i == 10000)
	{
		Con_Printf ("SCR_ScreenShot_f: Couldn't find an unused filename\n");
		return;
	}

//get data
	if (!(buffer = (byte *) malloc(glwidth*glheight*3)))
	{
		Con_Printf ("SCR_ScreenShot_f: Couldn't allocate memory\n");
		return;
	}

	glPixelStorei (GL_PACK_ALIGNMENT, 1);/* for widths that aren't a multiple of 4 */
	glReadPixels (glx, gly, glwidth, glheight, GL_RGB, GL_UNSIGNED_BYTE, buffer);

// now write the file
	if (!q_strncasecmp (ext, "png", sizeof(ext)))
		ok = Image_WritePNG (imagename, buffer, glwidth, glheight, 24, false);
	else if (!q_strncasecmp (ext, "tga", sizeof(ext)))
		ok = Image_WriteTGA (imagename, buffer, glwidth, glheight, 24, false);
	else if (!q_strncasecmp (ext, "jpg", sizeof(ext)))
		ok = Image_WriteJPG (imagename, buffer, glwidth, glheight, 24, quality, false);
	else
		ok = false;

	if (ok)
		Con_Printf ("Wrote %s\n", imagename);
	else
		Con_Printf ("SCR_ScreenShot_f: Couldn't create %s\n", imagename);

	free (buffer);
}