mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-01 14:58:14 +00:00
Core: Refactor screenshot saving.
So we can reuse the actual saving.
This commit is contained in:
1 parent
fe45a059b5
commit
79dc857527
5 files changed
+48
-48
No files matched your search
+1
-1
@@ -689,7 +689,7 @@ namespace SaveState
|
||||
break;
|
||||
|
||||
case SAVESTATE_SAVE_SCREENSHOT:
|
||||
callbackResult = TakeGameScreenshot(op.filename.c_str(), SCREENSHOT_JPG, SCREENSHOT_DISPLAY);
|
||||
callbackResult = TakeGameScreenshot(op.filename.c_str(), ScreenshotFormat::JPG, SCREENSHOT_DISPLAY);
|
||||
if (!callbackResult) {
|
||||
ERROR_LOG(SAVESTATE, "Failed to take a screenshot for the savestate! %s", op.filename.c_str());
|
||||
}
|
||||
|
||||
+41
-42
@@ -240,54 +240,53 @@ bool TakeGameScreenshot(const char *filename, ScreenshotFormat fmt, ScreenshotTy
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef USING_QT_UI
|
||||
u8 *flipbuffer = nullptr;
|
||||
if (success) {
|
||||
u8 *flipbuffer = nullptr;
|
||||
const u8 *buffer = ConvertBufferTo888RGB(buf, flipbuffer, w, h);
|
||||
// TODO: Handle other formats (e.g. Direct3D, raw framebuffers.)
|
||||
QImage image(buffer, w, h, QImage::Format_RGB888);
|
||||
success = image.save(filename, fmt == SCREENSHOT_PNG ? "PNG" : "JPG");
|
||||
delete [] flipbuffer;
|
||||
}
|
||||
#else
|
||||
if (success) {
|
||||
u8 *flipbuffer = nullptr;
|
||||
const u8 *buffer = ConvertBufferTo888RGB(buf, flipbuffer, w, h);
|
||||
if (buffer == nullptr) {
|
||||
success = false;
|
||||
success = buffer != nullptr;
|
||||
if (success) {
|
||||
if (width)
|
||||
*width = w;
|
||||
if (height)
|
||||
*height = h;
|
||||
|
||||
success = Save888RGBScreenshot(filename, fmt, buffer, w, h);
|
||||
}
|
||||
|
||||
if (width)
|
||||
*width = w;
|
||||
if (height)
|
||||
*height = h;
|
||||
|
||||
if (success && fmt == SCREENSHOT_PNG) {
|
||||
png_image png;
|
||||
memset(&png, 0, sizeof(png));
|
||||
png.version = PNG_IMAGE_VERSION;
|
||||
png.format = PNG_FORMAT_RGB;
|
||||
png.width = w;
|
||||
png.height = h;
|
||||
success = WriteScreenshotToPNG(&png, filename, 0, buffer, w * 3, nullptr);
|
||||
png_image_free(&png);
|
||||
|
||||
if (png.warning_or_error >= 2) {
|
||||
ERROR_LOG(SYSTEM, "Saving screenshot to PNG produced errors.");
|
||||
success = false;
|
||||
}
|
||||
} else if (success && fmt == SCREENSHOT_JPG) {
|
||||
jpge::params params;
|
||||
params.m_quality = 90;
|
||||
success = WriteScreenshotToJPEG(filename, w, h, 3, buffer, params);
|
||||
} else {
|
||||
success = false;
|
||||
}
|
||||
delete [] flipbuffer;
|
||||
}
|
||||
#endif
|
||||
delete [] flipbuffer;
|
||||
|
||||
if (!success) {
|
||||
ERROR_LOG(SYSTEM, "Failed to write screenshot.");
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
bool Save888RGBScreenshot(const char *filename, ScreenshotFormat fmt, const u8 *bufferRGB888, int w, int h) {
|
||||
#ifdef USING_QT_UI
|
||||
QImage image(bufferRGB888, w, h, QImage::Format_RGB888);
|
||||
return image.save(filename, fmt == ScreenshotFormat::PNG ? "PNG" : "JPG");
|
||||
#else
|
||||
if (fmt == ScreenshotFormat::PNG) {
|
||||
png_image png;
|
||||
memset(&png, 0, sizeof(png));
|
||||
png.version = PNG_IMAGE_VERSION;
|
||||
png.format = PNG_FORMAT_RGB;
|
||||
png.width = w;
|
||||
png.height = h;
|
||||
bool success = WriteScreenshotToPNG(&png, filename, 0, bufferRGB888, w * 3, nullptr);
|
||||
png_image_free(&png);
|
||||
|
||||
if (png.warning_or_error >= 2) {
|
||||
ERROR_LOG(SYSTEM, "Saving screenshot to PNG produced errors.");
|
||||
success = false;
|
||||
}
|
||||
return success;
|
||||
} else if (fmt == ScreenshotFormat::JPG) {
|
||||
jpge::params params;
|
||||
params.m_quality = 90;
|
||||
return WriteScreenshotToJPEG(filename, w, h, 3, bufferRGB888, params);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
+4
-3
@@ -19,9 +19,9 @@
|
||||
|
||||
struct GPUDebugBuffer;
|
||||
|
||||
enum ScreenshotFormat {
|
||||
SCREENSHOT_PNG,
|
||||
SCREENSHOT_JPG,
|
||||
enum class ScreenshotFormat {
|
||||
PNG,
|
||||
JPG,
|
||||
};
|
||||
|
||||
enum ScreenshotType {
|
||||
@@ -37,3 +37,4 @@ const u8 *ConvertBufferTo888RGB(const GPUDebugBuffer &buf, u8 *&temp, u32 &w, u3
|
||||
|
||||
// Can only be used while in game.
|
||||
bool TakeGameScreenshot(const char *filename, ScreenshotFormat fmt, ScreenshotType type, int *width = nullptr, int *height = nullptr, int maxRes = -1);
|
||||
bool Save888RGBScreenshot(const char *filename, ScreenshotFormat fmt, const u8 *bufferRGB888, int w, int h);
|
||||
+1
-1
@@ -763,7 +763,7 @@ void TakeScreenshot() {
|
||||
i++;
|
||||
}
|
||||
|
||||
bool success = TakeGameScreenshot(filename, g_Config.bScreenshotsAsPNG ? SCREENSHOT_PNG : SCREENSHOT_JPG, SCREENSHOT_OUTPUT);
|
||||
bool success = TakeGameScreenshot(filename, g_Config.bScreenshotsAsPNG ? ScreenshotFormat::PNG : ScreenshotFormat::JPG, SCREENSHOT_OUTPUT);
|
||||
if (success) {
|
||||
osm.Show(filename);
|
||||
} else {
|
||||
|
||||
+1
-1
@@ -247,7 +247,7 @@ void ReportScreen::CreateViews() {
|
||||
}
|
||||
screenshotFilename_ = path + ".reporting.jpg";
|
||||
int shotWidth = 0, shotHeight = 0;
|
||||
if (TakeGameScreenshot(screenshotFilename_.c_str(), SCREENSHOT_JPG, SCREENSHOT_DISPLAY, &shotWidth, &shotHeight, 4)) {
|
||||
if (TakeGameScreenshot(screenshotFilename_.c_str(), ScreenshotFormat::JPG, SCREENSHOT_DISPLAY, &shotWidth, &shotHeight, 4)) {
|
||||
float scale = 340.0f * (1.0f / g_dpi_scale_y) * (1.0f / shotHeight);
|
||||
leftColumnItems->Add(new CheckBox(&includeScreenshot_, rp->T("FeedbackIncludeScreen", "Include a screenshot")))->SetEnabledPtr(&enableReporting_);
|
||||
screenshot_ = leftColumnItems->Add(new AsyncImageFileView(screenshotFilename_, IS_DEFAULT, nullptr, new LinearLayoutParams(shotWidth * scale, shotHeight * scale, Margins(12, 0))));
|
||||
|
||||
Reference in new issue
Block a user