Take screenshots with savestates.

This commit is contained in:
Unknown W. Brackets
2014-12-20 23:14:46 -08:00
parent b1c9e7382f
commit 2dd9b10c8d
8 changed files with 181 additions and 80 deletions
+4 -76
View File
@@ -35,8 +35,6 @@
#include <memory>
#if defined(_WIN32)
#include <libpng17/png.h>
#include "ext/jpge/jpge.h"
#include "Windows/DSoundStream.h"
#include "Windows/WndMainWindow.h"
#include "Windows/D3D9Base.h"
@@ -50,9 +48,8 @@
#include "file/zip_read.h"
#include "thread/thread.h"
#include "net/http_client.h"
#include "gfx_es2/gl_state.h" // only for screenshot!
#include "gfx_es2/gl_state.h" // should've been only for screenshot - but actually not, cleanup?
#include "gfx_es2/draw_text.h"
#include "gfx_es2/draw_buffer.h"
#include "gfx/gl_lost_manager.h"
#include "gfx/texture.h"
#include "i18n/i18n.h"
@@ -76,13 +73,10 @@
#include "Core/Host.h"
#include "Core/PSPMixer.h"
#include "Core/SaveState.h"
#include "Core/Screenshot.h"
#include "Core/System.h"
#include "Core/HLE/sceCtrl.h"
#include "Core/Util/GameManager.h"
#include "GPU/GLES/GLES_GPU.h"
#ifdef _WIN32
#include "GPU/Directx9/GPU_DX9.h"
#endif
#include "ui_atlas.h"
#include "EmuScreen.h"
@@ -604,7 +598,7 @@ void NativeShutdownGraphics() {
void TakeScreenshot() {
g_TakeScreenshot = false;
#if defined(_WIN32) || (defined(USING_QT_UI) && !defined(MOBILE_DEVICE))
#if defined(_WIN32) || (defined(USING_QT_UI) && !defined(MOBILE_DEVICE))
mkDir(g_Config.memStickDirectory + "/PSP/SCREENSHOT");
// First, find a free filename.
@@ -627,73 +621,7 @@ void TakeScreenshot() {
i++;
}
GPUDebugBuffer buf;
bool success = true;
if (g_Config.iGPUBackend == GPU_BACKEND_OPENGL) {
success = GLES_GPU::GetDisplayFramebuffer(buf);
} else if (g_Config.iGPUBackend == GPU_BACKEND_DIRECT3D9) {
success = DX9::DIRECTX9_GPU::GetDisplayFramebuffer(buf);
} else {
success = false;
}
#ifdef USING_QT_UI
if (success) {
// TODO: Handle other formats (e.g. Direct3D.) Would only happen on Qt/Windows.
const u8 *buffer = buf.GetData();
QImage image(buffer, buf.GetStride(), buf.GetHeight(), QImage::Format_RGB888);
image = image.mirrored();
success = image.save(filename, g_Config.bScreenshotsAsPNG ? "PNG" : "JPG");
}
#else
if (success) {
const u8 *buffer = buf.GetData();
u8 *flipbuffer = nullptr;
if (buf.GetFlipped()) {
// Silly OpenGL reads upside down, we flip to another buffer for simplicity.
_assert_msg_(G3D, buf.GetFormat() == GPU_DBG_FORMAT_888_RGB, "Expecting RGB for flipped buffer (OpenGL.)");
flipbuffer = new u8[3 * buf.GetStride() * buf.GetHeight()];
for (u32 y = 0; y < buf.GetHeight(); y++) {
memcpy(flipbuffer + y * buf.GetStride() * 3, buffer + (buf.GetHeight() - y - 1) * buf.GetStride() * 3, buf.GetStride() * 3);
}
buffer = flipbuffer;
}
if (buf.GetFormat() == GPU_DBG_FORMAT_8888_BGRA) {
// Yay, we need to swap AND remove alpha.
flipbuffer = new u8[3 * buf.GetStride() * buf.GetHeight()];
for (u32 y = 0; y < buf.GetHeight(); y++) {
for (u32 x = 0; x < buf.GetStride(); x++) {
u8 *dst = &flipbuffer[y * buf.GetStride() * 3 + x * 3];
const u8 *src = &buffer[y * buf.GetStride() * 4 + x * 4];
dst[0] = src[2];
dst[1] = src[1];
dst[2] = src[0];
}
}
buffer = flipbuffer;
}
if (g_Config.bScreenshotsAsPNG) {
png_image png;
memset(&png, 0, sizeof(png));
png.version = PNG_IMAGE_VERSION;
png.format = PNG_FORMAT_RGB;
png.width = buf.GetStride();
png.height = buf.GetHeight();
png_image_write_to_file(&png, filename, 0, flipbuffer, buf.GetStride() * 3, NULL);
png_image_free(&png);
success = png.warning_or_error >= 2;
} else {
jpge::params params;
params.m_quality = 90;
success = compress_image_to_jpeg_file(filename, buf.GetStride(), buf.GetHeight(), 3, flipbuffer, params);
}
delete [] flipbuffer;
}
#endif
bool success = TakeGameScreenshot(filename, g_Config.bScreenshotsAsPNG ? SCREENSHOT_PNG : SCREENSHOT_JPG, SCREENSHOT_DISPLAY);
if (success) {
osm.Show(filename);
} else {