HostDisplay: Fix framebuffer screenshot scaling

This commit is contained in:
Albert Liu 2020-12-20 17:38:59 -08:00
parent dfa36e0fa7
commit b824844043
1 changed files with 17 additions and 40 deletions

View File

@ -486,52 +486,29 @@ bool HostDisplay::WriteDisplayTextureToFile(std::string filename, bool full_reso
if (!m_display_texture_handle) if (!m_display_texture_handle)
return false; return false;
apply_aspect_ratio = (m_display_aspect_ratio > 0) ? apply_aspect_ratio : false;
s32 resize_width = 0; s32 resize_width = 0;
s32 resize_height = 0; s32 resize_height = std::abs(m_display_texture_view_height);
if (apply_aspect_ratio && full_resolution) if (apply_aspect_ratio)
{ {
if (m_display_aspect_ratio > 1.0f) const float ss_width_scale = static_cast<float>(m_display_active_width) / static_cast<float>(m_display_width);
{ const float ss_height_scale = static_cast<float>(m_display_active_height) / static_cast<float>(m_display_height);
resize_width = m_display_texture_view_width; const float ss_aspect_ratio = m_display_aspect_ratio * ss_width_scale / ss_height_scale;
resize_height = static_cast<s32>(static_cast<float>(resize_width) / m_display_aspect_ratio); resize_width = static_cast<s32>(static_cast<float>(resize_height) * ss_aspect_ratio);
}
else
{
resize_height = std::abs(m_display_texture_view_height);
resize_width = static_cast<s32>(static_cast<float>(resize_height) * m_display_aspect_ratio);
}
} }
else if (apply_aspect_ratio) else
{ {
const auto [left, top, right, bottom] = resize_width = m_display_texture_view_width;
CalculateDrawRect(GetWindowWidth(), GetWindowHeight(), m_display_top_margin);
resize_width = right - left;
resize_height = bottom - top;
}
else if (!full_resolution)
{
const auto [left, top, right, bottom] =
CalculateDrawRect(GetWindowWidth(), GetWindowHeight(), m_display_top_margin);
const float ratio =
static_cast<float>(m_display_texture_view_width) / static_cast<float>(std::abs(m_display_texture_view_height));
if (ratio > 1.0f)
{
resize_width = right - left;
resize_height = static_cast<s32>(static_cast<float>(resize_width) / ratio);
}
else
{
resize_height = bottom - top;
resize_width = static_cast<s32>(static_cast<float>(resize_height) * ratio);
}
} }
if (resize_width < 0) if (!full_resolution)
resize_width = 1; {
if (resize_height < 0) const s32 resolution_scale = std::abs(m_display_texture_view_height) / m_display_active_height;
resize_height = 1; resize_height /= resolution_scale;
resize_width /= resolution_scale;
}
if (resize_width <= 0 || resize_height <= 0)
return false;
const bool flip_y = (m_display_texture_view_height < 0); const bool flip_y = (m_display_texture_view_height < 0);
s32 read_height = m_display_texture_view_height; s32 read_height = m_display_texture_view_height;