cellScreenshot: fix overlay scaling (#9867)

* cellScreenshot: fix overlay scaling
This commit is contained in:
Megamouse 2021-03-01 00:00:49 +01:00 committed by GitHub
parent 48cd56acc2
commit 0b5c6350ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 10 deletions

View File

@ -2,7 +2,7 @@
#include "GLGSRender.h" #include "GLGSRender.h"
#include "Emu/Cell/Modules/cellVideoOut.h" #include "Emu/Cell/Modules/cellVideoOut.h"
LOG_CHANNEL(screenshot); LOG_CHANNEL(screenshot_log, "SCREENSHOT");
gl::texture* GLGSRender::get_present_source(gl::present_surface_info* info, const rsx::avconf* avconfig) gl::texture* GLGSRender::get_present_source(gl::present_surface_info* info, const rsx::avconf* avconfig)
{ {
@ -227,7 +227,7 @@ void GLGSRender::flip(const rsx::display_flip_info_t& info)
glGetTextureImageEXT(image_to_flip, GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, sshot_frame.data()); glGetTextureImageEXT(image_to_flip, GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, sshot_frame.data());
if (GLenum err; (err = glGetError()) != GL_NO_ERROR) if (GLenum err; (err = glGetError()) != GL_NO_ERROR)
screenshot.error("Failed to capture image: 0x%x", err); screenshot_log.error("Failed to capture image: 0x%x", err);
else else
m_frame->take_screenshot(std::move(sshot_frame), buffer_width, buffer_height, false); m_frame->take_screenshot(std::move(sshot_frame), buffer_width, buffer_height, false);
} }

View File

@ -9,6 +9,7 @@
#include "Emu/system_config.h" #include "Emu/system_config.h"
#include "Emu/IdManager.h" #include "Emu/IdManager.h"
#include "Emu/Cell/Modules/cellScreenshot.h" #include "Emu/Cell/Modules/cellScreenshot.h"
#include "Emu/RSX/rsx_utils.h"
#include <QCoreApplication> #include <QCoreApplication>
#include <QDateTime> #include <QDateTime>
@ -442,6 +443,8 @@ void gs_frame::take_screenshot(const std::vector<u8> sshot_data, const u32 sshot
std::thread( std::thread(
[sshot_width, sshot_height, is_bgra](const std::vector<u8> sshot_data) [sshot_width, sshot_height, is_bgra](const std::vector<u8> sshot_data)
{ {
screenshot_log.notice("Taking screenshot (%dx%d)", sshot_width, sshot_height);
std::string screen_path = fs::get_config_dir() + "screenshots/"; std::string screen_path = fs::get_config_dir() + "screenshots/";
if (!fs::create_dir(screen_path) && fs::g_tls_error != fs::error::exist) 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
if (!overlay_img.load(qstr(cell_sshot_overlay_path))) if (!overlay_img.load(qstr(cell_sshot_overlay_path)))
{ {
screenshot_log.error("Failed to read cell screenshot overlay '%s' : %s", cell_sshot_overlay_path, fs::g_tls_error); screenshot_log.error("Failed to read cell screenshot overlay '%s' : %s", cell_sshot_overlay_path, fs::g_tls_error);
return;
} }
// TODO: the overlay and its offset need to be scaled based on image size, resolution scaling and video resolution
else if (manager.overlay_offset_x < static_cast<s64>(sshot_width) // Games choose the overlay file and the offset based on the current video resolution.
&& manager.overlay_offset_y < static_cast<s64>(sshot_height) // We need to scale the overlay if our resolution scaling causes the image to have a different size.
&& manager.overlay_offset_x + overlay_img.width() > 0 const auto avconf = g_fxo->get<rsx::avconf>();
&& manager.overlay_offset_y + overlay_img.height() > 0)
// TODO: handle wacky PS3 resolutions (without resolution scaling)
if (avconf->resolution_x != sshot_width || avconf->resolution_y != sshot_height)
{
const int scale = rsx::get_resolution_scale_percent();
const int x = (scale * manager.overlay_offset_x) / 100;
const int y = (scale * manager.overlay_offset_y) / 100;
const int width = (scale * overlay_img.width()) / 100;
const int height = (scale * overlay_img.height()) / 100;
screenshot_log.notice("Scaling overlay from %dx%d at offset (%d,%d) to %dx%d at offset (%d,%d)",
overlay_img.width(), overlay_img.height(), manager.overlay_offset_x, manager.overlay_offset_y, width, height, x, y);
manager.overlay_offset_x = x;
manager.overlay_offset_y = y;
overlay_img = overlay_img.scaled(QSize(width, height), Qt::AspectRatioMode::IgnoreAspectRatio, Qt::TransformationMode::SmoothTransformation);
}
if (manager.overlay_offset_x < static_cast<s64>(sshot_width) &&
manager.overlay_offset_y < static_cast<s64>(sshot_height) &&
manager.overlay_offset_x + overlay_img.width() > 0 &&
manager.overlay_offset_y + overlay_img.height() > 0)
{ {
QImage screenshot_img(rows[0], sshot_width, sshot_height, QImage::Format_RGBA8888); QImage screenshot_img(rows[0], sshot_width, sshot_height, QImage::Format_RGBA8888);
QPainter painter(&screenshot_img); QPainter painter(&screenshot_img);

View File

@ -248,9 +248,7 @@ std::unique_ptr<gs_frame> gui_application::get_gs_frame()
{ {
extern const std::unordered_map<video_resolution, std::pair<int, int>, value_hash<video_resolution>> g_video_out_resolution_map; extern const std::unordered_map<video_resolution, std::pair<int, int>, value_hash<video_resolution>> g_video_out_resolution_map;
const auto size = g_video_out_resolution_map.at(g_cfg.video.resolution); auto [w, h] = g_video_out_resolution_map.at(g_cfg.video.resolution);
int w = size.first;
int h = size.second;
if (m_gui_settings->GetValue(gui::gs_resize).toBool()) if (m_gui_settings->GetValue(gui::gs_resize).toBool())
{ {