Beispiel #1
0
/* 
================== 
RB_TakeScreenshot
================== 
*/  
void RB_TakeScreenshot(int x, int y, int width, int height, char *fileName)
{
	byte *allbuf, *buffer;
	byte *srcptr, *destptr;
	byte *endline, *endmem;
	byte temp;
	
	int linelen, padlen;
	size_t offset = 18, memcount;
		
	allbuf = RB_ReadPixels(x, y, width, height, &offset, &padlen);
	buffer = allbuf + offset - 18;
	
	Com_Memset (buffer, 0, 18);
	buffer[2] = 2;		// uncompressed type
	buffer[12] = width & 255;
	buffer[13] = width >> 8;
	buffer[14] = height & 255;
	buffer[15] = height >> 8;
	buffer[16] = 24;	// pixel size

	// swap rgb to bgr and remove padding from line endings
	linelen = width * 3;
	
	srcptr = destptr = allbuf + offset;
	endmem = srcptr + (linelen + padlen) * height;
	
	while(srcptr < endmem)
	{
		endline = srcptr + linelen;

		while(srcptr < endline)
		{
			temp = srcptr[0];
			*destptr++ = srcptr[2];
			*destptr++ = srcptr[1];
			*destptr++ = temp;
			
			srcptr += 3;
		}
		
		// Skip the pad
		srcptr += padlen;
	}

	memcount = linelen * height;

	// gamma correct
	if(glConfig.deviceSupportsGamma
//openarena: altbright
		&& !r_alternateBrightness->integer
//-openarena
	) {
		R_GammaCorrect(allbuf + offset, memcount);
}

	ri.FS_WriteFile(fileName, buffer, memcount + 18);

	ri.Hunk_FreeTempMemory(allbuf);
}
Beispiel #2
0
/*
 * R_LevelShot
 *
 * levelshots are specialized 128*128 thumbnails for
 * the menu system, sampled down from full screen distorted images
 */
void
R_LevelShot(void)
{
	char checkname[MAX_OSPATH];
	byte	*buffer;
	byte	*source, *allsource;
	byte	*src, *dst;
	size_t	offset = 0;
	int	padlen;
	int	x, y;
	int	r, g, b;
	float	xScale, yScale;
	int	xx, yy;

	Q_sprintf(checkname, sizeof(checkname), "levelshots/%s.tga", tr.world->baseName);

	allsource = RB_ReadPixels(0, 0, glConfig.vidWidth, glConfig.vidHeight, &offset, &padlen);
	source = allsource + offset;

	buffer = ri.hunkalloctemp(128 * 128*3 + 18);
	Q_Memset (buffer, 0, 18);
	buffer[2]	= 2;	/* uncompressed type */
	buffer[12]	= 128;
	buffer[14]	= 128;
	buffer[16]	= 24;	/* pixel size */

	/* resample from source */
	xScale	= glConfig.vidWidth / 512.0f;
	yScale	= glConfig.vidHeight / 384.0f;
	for(y = 0; y < 128; y++)
		for(x = 0; x < 128; x++){
			r = g = b = 0;
			for(yy = 0; yy < 3; yy++)
				for(xx = 0; xx < 4; xx++){
					src = source +
					      (3 * glConfig.vidWidth + padlen) * (int)((y*3 + yy) * yScale) +
					      3 * (int)((x*4 + xx) * xScale);
					r	+= src[0];
					g	+= src[1];
					b	+= src[2];
				}
			dst = buffer + 18 + 3 * (y * 128 + x);
			dst[0]	= b / 12;
			dst[1]	= g / 12;
			dst[2]	= r / 12;
		}

	/* gamma correct */
	if(glConfig.deviceSupportsGamma){
		R_GammaCorrect(buffer + 18, 128 * 128 * 3);
	}

	ri.fswritefile(checkname, buffer, 128 * 128*3 + 18);

	ri.hunkfreetemp(buffer);
	ri.hunkfreetemp(allsource);

	ri.Printf(PRINT_ALL, "Wrote %s\n", checkname);
}
Beispiel #3
0
static void R_LevelShot( void ) {
	char		checkname[MAX_OSPATH];
	byte		*buffer;
	byte		*source, *allsource;
	byte		*src, *dst;
	size_t		offset = 0;
	int			padlen;
	int			x, y;
	int			r, g, b;
	float		xScale, yScale;
	int			xx, yy;

	Com_sprintf( checkname, sizeof(checkname), "levelshots/%s.tga", tr.world->baseName );

	allsource = RB_ReadPixels(0, 0, glConfig.vidWidth, glConfig.vidHeight, &offset, &padlen);
	source = allsource + offset;

	buffer = (byte *)Hunk_AllocateTempMemory(LEVELSHOTSIZE * LEVELSHOTSIZE*3 + 18);
	Com_Memset (buffer, 0, 18);
	buffer[2] = 2;		// uncompressed type
	buffer[12] = LEVELSHOTSIZE & 255;
	buffer[13] = LEVELSHOTSIZE >> 8;
	buffer[14] = LEVELSHOTSIZE & 255;
	buffer[15] = LEVELSHOTSIZE >> 8;
	buffer[16] = 24;	// pixel size

	// resample from source
	xScale = glConfig.vidWidth / (4.0*LEVELSHOTSIZE);
	yScale = glConfig.vidHeight / (3.0*LEVELSHOTSIZE);
	for ( y = 0 ; y < LEVELSHOTSIZE ; y++ ) {
		for ( x = 0 ; x < LEVELSHOTSIZE ; x++ ) {
			r = g = b = 0;
			for ( yy = 0 ; yy < 3 ; yy++ ) {
				for ( xx = 0 ; xx < 4 ; xx++ ) {
					src = source + 3 * ( glConfig.vidWidth * (int)( (y*3+yy)*yScale ) + (int)( (x*4+xx)*xScale ) );
					r += src[0];
					g += src[1];
					b += src[2];
				}
			}
			dst = buffer + 18 + 3 * ( y * LEVELSHOTSIZE + x );
			dst[0] = b / 12;
			dst[1] = g / 12;
			dst[2] = r / 12;
		}
	}

	// gamma correct
	if ( ( tr.overbrightBits > 0 ) && glConfig.deviceSupportsGamma ) {
		R_GammaCorrect( buffer + 18, LEVELSHOTSIZE * LEVELSHOTSIZE * 3 );
	}

	FS_WriteFile( checkname, buffer, LEVELSHOTSIZE * LEVELSHOTSIZE*3 + 18 );

	Hunk_FreeTempMemory( buffer );
	Hunk_FreeTempMemory( allsource );

	Com_Printf ("Wrote %s\n", checkname );
}
Beispiel #4
0
/*
 * RB_TakeScreenshot
 */
void
RB_TakeScreenshot(int x, int y, int width, int height, char *fileName)
{
	byte	*allbuf, *buffer;
	byte	*srcptr, *destptr;
	byte	*endline, *endmem;
	byte	temp;

	int	linelen, padlen;
	size_t offset = 18, memcount;

	allbuf	= RB_ReadPixels(x, y, width, height, &offset, &padlen);
	buffer	= allbuf + offset - 18;

	Q_Memset (buffer, 0, 18);
	buffer[2]	= 2;	/* uncompressed type */
	buffer[12]	= width & 255;
	buffer[13]	= width >> 8;
	buffer[14]	= height & 255;
	buffer[15]	= height >> 8;
	buffer[16]	= 24;	/* pixel size */

	/* swap rgb to bgr and remove padding from line endings */
	linelen = width * 3;

	srcptr	= destptr = allbuf + offset;
	endmem	= srcptr + (linelen + padlen) * height;

	while(srcptr < endmem){
		endline = srcptr + linelen;

		while(srcptr < endline){
			temp = srcptr[0];
			*destptr++	= srcptr[2];
			*destptr++	= srcptr[1];
			*destptr++	= temp;

			srcptr += 3;
		}

		/* Skip the pad */
		srcptr += padlen;
	}

	memcount = linelen * height;

	/* gamma correct */
	if(glConfig.deviceSupportsGamma)
		R_GammaCorrect(allbuf + offset, memcount);

	ri.fswritefile(fileName, buffer, memcount + 18);

	ri.hunkfreetemp(allbuf);
}
Beispiel #5
0
/*
==================
R_TakeScreenshotPNG
==================
*/
static void R_TakeScreenshotPNG( int x, int y, int width, int height, char *fileName )
{
	byte *buffer = RB_ReadPixels( x, y, width, height, 0 );

	if ( tr.overbrightBits > 0 && glConfig.deviceSupportsGamma )
	{
		R_GammaCorrect( buffer, 3 * width * height );
	}

	SavePNG( fileName, buffer, width, height, 3, qfalse );
	ri.Hunk_FreeTempMemory( buffer );
}
Beispiel #6
0
/*
==================
R_TakeScreenshot
==================
*/
void R_TakeScreenshotJPEG( int x, int y, int width, int height, char *fileName ) {
	byte *buffer;
	size_t offset = 0, memcount;
	int padlen;

	buffer = RB_ReadPixels(x, y, width, height, &offset, &padlen);
	memcount = (width * 3 + padlen) * height;

	// gamma correct
	if(glConfig.deviceSupportsGamma)
		R_GammaCorrect(buffer + offset, memcount);

	RE_SaveJPG(fileName, r_screenshotJpegQuality->integer, width, height, buffer + offset, padlen);
	Hunk_FreeTempMemory(buffer);
}
Beispiel #7
0
void R_TakeScreenshotJPEG(int x, int y, int width, int height, char *fileName) {
	byte *buffer;
	size_t offset = 0, memcount;
	int padlen;

	buffer = RB_ReadPixels(x, y, width, height, &offset, &padlen);
	memcount = (width * 3 + padlen) * height;

	// gamma correct
	if (r_gammamethod->integer == GAMMA_HARDWARE)
		R_GammaCorrect(buffer + offset, (int)memcount);

	SaveJPG(fileName, r_screenshotJpegQuality->integer, width, height, buffer + offset, padlen);
	ri.Hunk_FreeTempMemory(buffer);
}
Beispiel #8
0
/*
==================
RB_TakeScreenshotPNG
==================
*/
static void RB_TakeScreenshotPNG(int x, int y, int width, int height, char *fileName)
{
	byte *buffer;
	size_t offset = 0, memcount;
	int padlen;

	buffer = RB_ReadPixels(x, y, width, height, &offset, &padlen);
	memcount = (width * 3 + padlen) * height;

	// gamma correct
	if(glConfig.deviceSupportsGamma)
		R_GammaCorrect(buffer + offset, memcount);

	RE_SavePNG(fileName, width, height, buffer+offset, 3, padlen, qfalse);
	ri.Hunk_FreeTempMemory(buffer);
}
Beispiel #9
0
/*
==================
R_TakeScreenshot
==================
*/
static void R_TakeScreenshot( int x, int y, int width, int height, char *fileName )
{
	byte *buffer;
	int  dataSize;
	byte *end, *p;

	// with 18 bytes for the TGA file header
	buffer = RB_ReadPixels( x, y, width, height, 18 );
	Com_Memset( buffer, 0, 18 );

	buffer[ 2 ] = 2; // uncompressed type
	buffer[ 12 ] = width & 255;
	buffer[ 13 ] = width >> 8;
	buffer[ 14 ] = height & 255;
	buffer[ 15 ] = height >> 8;
	buffer[ 16 ] = 24; // pixel size

	dataSize = 3 * width * height;

	// RGB to BGR
	end = buffer + 18 + dataSize;

	for ( p = buffer + 18; p < end; p += 3 )
	{
		byte temp = p[ 0 ];
		p[ 0 ] = p[ 2 ];
		p[ 2 ] = temp;
	}

	if ( tr.overbrightBits > 0 && glConfig.deviceSupportsGamma )
	{
		R_GammaCorrect( buffer + 18, dataSize );
	}

	ri.FS_WriteFile( fileName, buffer, 18 + dataSize );

	ri.Hunk_FreeTempMemory( buffer );
}
Beispiel #10
0
/*
====================
R_LevelShot

levelshots are specialized 128*128 thumbnails for
the menu system, sampled down from full screen distorted images
====================
*/
void R_LevelShot(void)
{
	char   checkname[MAX_OSPATH];
	byte   *buffer;
	byte   *source, *allsource;
	byte   *src, *dst;
	size_t offset = 0;
	int    padlen;
	int    x, y;
	int    r, g, b;
	float  xScale, yScale;
	int    xx, yy;

	Com_sprintf(checkname, sizeof(checkname), "levelshots/%s.tga", tr.world->baseName);

	allsource = RB_ReadPixels(0, 0, glConfig.vidWidth, glConfig.vidHeight, &offset, &padlen);
	source    = allsource + offset;

	buffer = ri.Hunk_AllocateTempMemory(128 * 128 * 3 + 18);
	Com_Memset(buffer, 0, 18);
	buffer[2]  = 2;         // uncompressed type
	buffer[12] = 128;
	buffer[14] = 128;
	buffer[16] = 24;        // pixel size

	// resample from source
	xScale = glConfig.vidWidth / 512.0f;
	yScale = glConfig.vidHeight / 384.0f;
	for (y = 0 ; y < 128 ; y++)
	{
		for (x = 0 ; x < 128 ; x++)
		{
			r = g = b = 0;
			for (yy = 0 ; yy < 3 ; yy++)
			{
				for (xx = 0 ; xx < 4 ; xx++)
				{
					src = source + (3 * glConfig.vidWidth + padlen) * ( int ) ((y * 3 + yy) * yScale) +
					      3 * ( int ) ((x * 4 + xx) * xScale);
					r += src[0];
					g += src[1];
					b += src[2];
				}
			}
			dst    = buffer + 18 + 3 * (y * 128 + x);
			dst[0] = b / 12;
			dst[1] = g / 12;
			dst[2] = r / 12;
		}
	}

	// gamma correct
	if (glConfig.deviceSupportsGamma)
	{
		R_GammaCorrect(buffer + 18, 128 * 128 * 3);
	}

	ri.FS_WriteFile(checkname, buffer, 128 * 128 * 3 + 18);

	ri.Hunk_FreeTempMemory(buffer);
	ri.Hunk_FreeTempMemory(allsource);

	Ren_Print("Wrote %s\n", checkname);
}
Beispiel #11
0
/*
====================
R_LevelShot

levelshots are specialized 128*128 thumbnails for
the menu system, sampled down from full screen distorted images
====================
*/
void R_LevelShot( screenshotType_e type, const char *ext ) {
	char		fileName[MAX_OSPATH];
	byte		*source;
	byte		*resample, *resamplestart;
	size_t		offset = 0, memcount;
	int			spadlen, rpadlen;
	int			padwidth, linelen;
	GLint		packAlign;
	byte		*src, *dst;
	int			x, y;
	int			r, g, b;
	float		xScale, yScale;
	int			xx, yy;
	int			width, height;
	int			arg;

	// Allow custom resample width/height
	arg = atoi(ri.Cmd_Argv(2));
	if (arg > 0)
		width = height = arg;
	else
		width = height = 128;

	if (width > glConfig.vidWidth)
		width = glConfig.vidWidth;
	if (height > glConfig.vidHeight)
		height = glConfig.vidHeight;

	Com_sprintf(fileName, sizeof(fileName), "levelshots/%s_small%s", tr.world->baseName, ext);

	source = RB_ReadPixels(0, 0, glConfig.vidWidth, glConfig.vidHeight, &offset, &spadlen);

	//
	// Based on RB_ReadPixels
	qglGetIntegerv(GL_PACK_ALIGNMENT, &packAlign);

	linelen = width * 3;
	padwidth = PAD(linelen, packAlign);

	// Allocate a few more bytes so that we can choose an alignment we like
	resample = ri.Hunk_AllocateTempMemory(padwidth * height + offset + packAlign - 1);

	resamplestart = PADP((intptr_t) resample + offset, packAlign);

	offset = resamplestart - resample;
	rpadlen = padwidth - linelen;
	//

	// resample from source
	xScale = glConfig.vidWidth / (float)(width * 4.0f);
	yScale = glConfig.vidHeight / (float)(height * 3.0f);
	for ( y = 0 ; y < height ; y++ ) {
		for ( x = 0 ; x < width ; x++ ) {
			r = g = b = 0;
			for ( yy = 0 ; yy < 3 ; yy++ ) {
				for ( xx = 0 ; xx < 4 ; xx++ ) {
					src = source + (3 * glConfig.vidWidth + spadlen) * (int)((y*3 + yy) * yScale) +
						3 * (int) ((x*4 + xx) * xScale);
					r += src[0];
					g += src[1];
					b += src[2];
				}
			}
			dst = resample + 3 * ( y * width + x );
			dst[0] = r / 12;
			dst[1] = g / 12;
			dst[2] = b / 12;
		}
	}

	memcount = (width * 3 + rpadlen) * height;

	// gamma correct
	if(glConfig.deviceSupportsGamma)
		R_GammaCorrect(resample + offset, memcount);

	if ( type == ST_TGA )
		RE_SaveTGA(fileName, width, height, resample + offset, rpadlen);
	else if ( type == ST_JPEG )
		RE_SaveJPG(fileName, r_screenshotJpegQuality->integer, width, height, resample + offset, rpadlen);
	else if ( type == ST_PNG )
		RE_SavePNG(fileName, width, height, resample + offset, rpadlen);

	ri.Hunk_FreeTempMemory(resample);
	ri.Hunk_FreeTempMemory(source);

	ri.Printf( PRINT_ALL, "Wrote %s\n", fileName );
}