qt: For Qt 6.9.0 and above, use QImage::flipped over QImage::mirrored

The latter has been deprecated, and is causing build failures where deprecations warnings are treated as errors.
This commit is contained in:
OpenSauce04 2025-04-07 22:54:14 +01:00 committed by OpenSauce
parent 8d769ed9cb
commit e341dcf238
4 changed files with 31 additions and 5 deletions

View File

@ -10,6 +10,7 @@
#include <QWindow> #include <QWindow>
#include "citra_qt/bootmanager.h" #include "citra_qt/bootmanager.h"
#include "citra_qt/citra_qt.h" #include "citra_qt/citra_qt.h"
#include "citra_qt/util/util.h"
#include "common/color.h" #include "common/color.h"
#include "common/microprofile.h" #include "common/microprofile.h"
#include "common/scm_rev.h" #include "common/scm_rev.h"
@ -714,7 +715,7 @@ void GRenderWindow::CaptureScreenshot(u32 res_scale, const QString& screenshot_p
screenshot_image.bits(), screenshot_image.bits(),
[this, screenshot_path](bool invert_y) { [this, screenshot_path](bool invert_y) {
const std::string std_screenshot_path = screenshot_path.toStdString(); const std::string std_screenshot_path = screenshot_path.toStdString();
if (screenshot_image.mirrored(false, invert_y).save(screenshot_path)) { if (GetMirroredImage(screenshot_image, false, invert_y).save(screenshot_path)) {
LOG_INFO(Frontend, "Screenshot saved to \"{}\"", std_screenshot_path); LOG_INFO(Frontend, "Screenshot saved to \"{}\"", std_screenshot_path);
} else { } else {
LOG_ERROR(Frontend, "Failed to save screenshot to \"{}\"", std_screenshot_path); LOG_ERROR(Frontend, "Failed to save screenshot to \"{}\"", std_screenshot_path);

View File

@ -7,6 +7,7 @@
#include <cstring> #include <cstring>
#include <QImage> #include <QImage>
#include "citra_qt/camera/camera_util.h" #include "citra_qt/camera/camera_util.h"
#include "citra_qt/util/util.h"
namespace CameraUtil { namespace CameraUtil {
@ -213,9 +214,9 @@ std::vector<u16> ProcessImage(const QImage& image, int width, int height, bool o
} }
QImage scaled = QImage scaled =
image.scaled(width, height, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation); image.scaled(width, height, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
QImage transformed = QImage transformed = GetMirroredImage(
scaled.copy((scaled.width() - width) / 2, (scaled.height() - height) / 2, width, height) scaled.copy((scaled.width() - width) / 2, (scaled.height() - height) / 2, width, height),
.mirrored(flip_horizontal, flip_vertical); flip_horizontal, flip_vertical);
if (output_rgb) { if (output_rgb) {
QImage converted = transformed.convertToFormat(QImage::Format_RGB16); QImage converted = transformed.convertToFormat(QImage::Format_RGB16);
std::memcpy(buffer.data(), converted.bits(), width * height * sizeof(u16)); std::memcpy(buffer.data(), converted.bits(), width * height * sizeof(u16));

View File

@ -175,3 +175,19 @@ const std::string GetApplicationsDirectory() {
return QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation).toStdString(); return QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation).toStdString();
#endif #endif
} }
QImage GetMirroredImage(QImage source_image, bool flip_horizontal, bool flip_vertical) {
#if QT_VERSION < QT_VERSION_CHECK(6, 9, 0) // Fallback, uses deprecated method
return source_image.mirrored(flip_horizontal, flip_vertical);
#else // New method
auto orientation_horizontal = static_cast<Qt::Orientations>(0x0);
auto orientation_vertical = static_cast<Qt::Orientations>(0x0);
if (flip_horizontal)
orientation_horizontal = Qt::Horizontal;
if (flip_vertical)
orientation_vertical = Qt::Vertical;
return source_image.flipped(orientation_horizontal | orientation_vertical);
#endif
}

View File

@ -41,3 +41,11 @@ QPixmap GetQPixmapFromSMDH(const std::vector<u8>& smdh_data);
* @return The users applications directory * @return The users applications directory
*/ */
[[nodiscard]] const std::string GetApplicationsDirectory(); [[nodiscard]] const std::string GetApplicationsDirectory();
/**
* Imitates the deprecated `QImage::mirrored` function in a forwards-compatible manner
* @param flip_horizontal Whether the image should be flipped horizontally
* @param flip_vertical Whether the image should be flipped vertically
* @return QImage The mirrored image
*/
QImage GetMirroredImage(QImage source_image, bool flip_horizontal, bool flip_vertical);