Skip to content

Commit 0b5c635

Browse files
authored
cellScreenshot: fix overlay scaling (#9867)
* cellScreenshot: fix overlay scaling
1 parent 48cd56a commit 0b5c635

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

rpcs3/Emu/RSX/GL/GLPresent.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include "GLGSRender.h"
33
#include "Emu/Cell/Modules/cellVideoOut.h"
44

5-
LOG_CHANNEL(screenshot);
5+
LOG_CHANNEL(screenshot_log, "SCREENSHOT");
66

77
gl::texture* GLGSRender::get_present_source(gl::present_surface_info* info, const rsx::avconf* avconfig)
88
{
@@ -227,7 +227,7 @@ void GLGSRender::flip(const rsx::display_flip_info_t& info)
227227
glGetTextureImageEXT(image_to_flip, GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, sshot_frame.data());
228228

229229
if (GLenum err; (err = glGetError()) != GL_NO_ERROR)
230-
screenshot.error("Failed to capture image: 0x%x", err);
230+
screenshot_log.error("Failed to capture image: 0x%x", err);
231231
else
232232
m_frame->take_screenshot(std::move(sshot_frame), buffer_width, buffer_height, false);
233233
}

rpcs3/rpcs3qt/gs_frame.cpp

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "Emu/system_config.h"
1010
#include "Emu/IdManager.h"
1111
#include "Emu/Cell/Modules/cellScreenshot.h"
12+
#include "Emu/RSX/rsx_utils.h"
1213

1314
#include <QCoreApplication>
1415
#include <QDateTime>
@@ -442,6 +443,8 @@ void gs_frame::take_screenshot(const std::vector<u8> sshot_data, const u32 sshot
442443
std::thread(
443444
[sshot_width, sshot_height, is_bgra](const std::vector<u8> sshot_data)
444445
{
446+
screenshot_log.notice("Taking screenshot (%dx%d)", sshot_width, sshot_height);
447+
445448
std::string screen_path = fs::get_config_dir() + "screenshots/";
446449

447450
if (!fs::create_dir(screen_path) && fs::g_tls_error != fs::error::exist)
@@ -571,12 +574,34 @@ void gs_frame::take_screenshot(const std::vector<u8> sshot_data, const u32 sshot
571574
if (!overlay_img.load(qstr(cell_sshot_overlay_path)))
572575
{
573576
screenshot_log.error("Failed to read cell screenshot overlay '%s' : %s", cell_sshot_overlay_path, fs::g_tls_error);
577+
return;
578+
}
579+
580+
// Games choose the overlay file and the offset based on the current video resolution.
581+
// We need to scale the overlay if our resolution scaling causes the image to have a different size.
582+
const auto avconf = g_fxo->get<rsx::avconf>();
583+
584+
// TODO: handle wacky PS3 resolutions (without resolution scaling)
585+
if (avconf->resolution_x != sshot_width || avconf->resolution_y != sshot_height)
586+
{
587+
const int scale = rsx::get_resolution_scale_percent();
588+
const int x = (scale * manager.overlay_offset_x) / 100;
589+
const int y = (scale * manager.overlay_offset_y) / 100;
590+
const int width = (scale * overlay_img.width()) / 100;
591+
const int height = (scale * overlay_img.height()) / 100;
592+
593+
screenshot_log.notice("Scaling overlay from %dx%d at offset (%d,%d) to %dx%d at offset (%d,%d)",
594+
overlay_img.width(), overlay_img.height(), manager.overlay_offset_x, manager.overlay_offset_y, width, height, x, y);
595+
596+
manager.overlay_offset_x = x;
597+
manager.overlay_offset_y = y;
598+
overlay_img = overlay_img.scaled(QSize(width, height), Qt::AspectRatioMode::IgnoreAspectRatio, Qt::TransformationMode::SmoothTransformation);
574599
}
575-
// TODO: the overlay and its offset need to be scaled based on image size, resolution scaling and video resolution
576-
else if (manager.overlay_offset_x < static_cast<s64>(sshot_width)
577-
&& manager.overlay_offset_y < static_cast<s64>(sshot_height)
578-
&& manager.overlay_offset_x + overlay_img.width() > 0
579-
&& manager.overlay_offset_y + overlay_img.height() > 0)
600+
601+
if (manager.overlay_offset_x < static_cast<s64>(sshot_width) &&
602+
manager.overlay_offset_y < static_cast<s64>(sshot_height) &&
603+
manager.overlay_offset_x + overlay_img.width() > 0 &&
604+
manager.overlay_offset_y + overlay_img.height() > 0)
580605
{
581606
QImage screenshot_img(rows[0], sshot_width, sshot_height, QImage::Format_RGBA8888);
582607
QPainter painter(&screenshot_img);

rpcs3/rpcs3qt/gui_application.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,7 @@ std::unique_ptr<gs_frame> gui_application::get_gs_frame()
248248
{
249249
extern const std::unordered_map<video_resolution, std::pair<int, int>, value_hash<video_resolution>> g_video_out_resolution_map;
250250

251-
const auto size = g_video_out_resolution_map.at(g_cfg.video.resolution);
252-
int w = size.first;
253-
int h = size.second;
251+
auto [w, h] = g_video_out_resolution_map.at(g_cfg.video.resolution);
254252

255253
if (m_gui_settings->GetValue(gui::gs_resize).toBool())
256254
{

0 commit comments

Comments
 (0)