/*<html><pre>*/
#include <../source/TAL/objbase.h>
#include <../source/PAL/dataman.h>

/*
 *	Utility function to produce screenshots.
 */
vboolean	V_GLOBAL
vglSaveFramebuffer(char *file_name,u32_t mmWidth,u32_t mmHeight)
{
	u8_t *pixels;
	u32_t rw, rh;
	char ext[_MAX_EXT];
	vboolean res;
	if(!file_name || !file_name[0])
	{
#ifdef	CHECKED_BUILD
		conlPrintf(LOG_ERROR,"vglSaveFramebuffer(%s,%u,%u): "
			"incorrect parameter.\n",
			strSafe(file_name),mmWidth,mmHeight);
#endif	/* CHECKED_BUILD */
		return false;
	}
	pixels=vglReadPixels(&rw,&rh);
	if(!pixels)
	{
#ifdef	CHECKED_BUILD
		conlPrintf(LOG_ERROR,"vglSaveFramebuffer(%s,%u,%u): "
			"vglReadPixels() failed.\n",
			strSafe(file_name),mmWidth,mmHeight);
#endif	/* CHECKED_BUILD */
		return false;
	}
	/* determine file format */
	if(!strcasecmp(file_name,"//./clipboard"))
		res=bmpSaveEx(file_name,rw,rh,pixels,mmWidth,mmHeight);
	else
	{
		fsSplitPath(file_name,NULL,NULL,ext);
		if(!strcasecmp(ext,"bmp"))
			res=bmpSaveEx(file_name,rw,rh,pixels,mmWidth,mmHeight);
		else if(!strcasecmp(ext,"tga"))
		{
#ifdef	CHECKED_BUILD
			if(mmWidth || mmHeight)
				conlPrintf(LOG_WARNING,"vglSaveFramebuffer(%s,%u,%u): "
					"Targa format specified, ignoring image size "
					"%u by %u millimeters.\n",
					strSafe(file_name),mmWidth,mmHeight,mmWidth,mmHeight);
#endif	/* CHECKED_BUILD */
			res=tgaSave(file_name,rw,rh,pixels);
		}
		else
		{
#ifdef	CHECKED_BUILD
			conlPrintf(LOG_ERROR,"vglSaveFramebuffer(%s,%u,%u): "
				"unknown file format '%s'.\n",
				strSafe(file_name),mmWidth,mmHeight,ext);
#endif	/* CHECKED_BUILD */
			res=false;
		}
	}
	return res;
}

/*</pre></html>*/
/*EOF*/
