Exemplo n.º 1
0
void TakeScreenshot() {
	g_TakeScreenshot = false;
	mkDir(g_Config.memCardDirectory + "/PSP/SCREENSHOT");

	// First, find a free filename.
	int i = 0;

	char temp[256];
	while (i < 10000){
		if(g_Config.bScreenshotsAsPNG)
			sprintf(temp, "%s/PSP/SCREENSHOT/screen%05d.png", g_Config.memCardDirectory.c_str(), i);
		else
			sprintf(temp, "%s/PSP/SCREENSHOT/screen%05d.jpg", g_Config.memCardDirectory.c_str(), i);
		FileInfo info;
		if (!getFileInfo(temp, &info))
			break;
		i++;
	}

	// Okay, allocate a buffer.
	u8 *buffer = new u8[3 * pixel_xres * pixel_yres];
	// Silly openGL reads upside down, we flip to another buffer for simplicity.
	u8 *flipbuffer = new u8[3 * pixel_xres * pixel_yres];

	glReadPixels(0, 0, pixel_xres, pixel_yres, GL_RGB, GL_UNSIGNED_BYTE, buffer);

	for (int y = 0; y < pixel_yres; y++) {
		memcpy(flipbuffer + y * pixel_xres * 3, buffer + (pixel_yres - y - 1) * pixel_xres * 3, pixel_xres * 3);
	}

	if (g_Config.bScreenshotsAsPNG) {
		png_image png;
		memset(&png, 0, sizeof(png));
		png.version = PNG_IMAGE_VERSION;
		png.format = PNG_FORMAT_RGB;
		png.width = pixel_xres;
		png.height = pixel_yres;
		png_image_write_to_file(&png, temp, 0, flipbuffer, pixel_xres * 3, NULL);
		png_image_free(&png);
	} else {
		jpge::params params;
		params.m_quality = 90;
		compress_image_to_jpeg_file(temp, pixel_xres, pixel_yres, 3, flipbuffer, params);
	}

	delete [] buffer;
	delete [] flipbuffer;

	osm.Show(temp);
}
Exemplo n.º 2
0
void TakeScreenshot() {
#ifdef _WIN32
	g_TakeScreenshot = false;
	mkDir(g_Config.memCardDirectory + "/PSP/SCREENSHOT");

	// First, find a free filename.
	int i = 0;

	char temp[256];
	while (i < 10000){
		if(g_Config.bScreenshotsAsPNG)
			sprintf(temp, "%s/PSP/SCREENSHOT/screen%05d.png", g_Config.memCardDirectory.c_str(), i);
		else
			sprintf(temp, "%s/PSP/SCREENSHOT/screen%05d.jpg", g_Config.memCardDirectory.c_str(), i);
		FileInfo info;
		if (!getFileInfo(temp, &info))
			break;
		i++;
	}

	// Okay, allocate a buffer.
	u8 *buffer = new u8[4 * pixel_xres * pixel_yres];
	// Silly openGL reads upside down, we flip to another buffer for simplicity.
	u8 *flipbuffer = new u8[4 * pixel_xres * pixel_yres];

	glReadPixels(0, 0, pixel_xres, pixel_yres, GL_RGBA, GL_UNSIGNED_BYTE, buffer);

	for (int y = 0; y < pixel_yres; y++) {
		memcpy(flipbuffer + y * pixel_xres * 4, buffer + (pixel_yres - y - 1) * pixel_xres * 4, pixel_xres * 4);
	}

	if(g_Config.bScreenshotsAsPNG)
		stbi_write_png(temp, pixel_xres, pixel_yres, 4, flipbuffer, pixel_xres * 4);
	else
	{
		jpge::params params;
		params.m_quality = 90;
		compress_image_to_jpeg_file(temp, pixel_xres, pixel_yres, 4, flipbuffer, params);
	}

	delete [] buffer;
	delete [] flipbuffer;

	osm.Show(temp);
#endif
}