From 4040f58af6d2d8ce8c25b19e47602d1ca1853796 Mon Sep 17 00:00:00 2001 From: Pablo Santana Date: Sun, 2 Feb 2025 02:27:49 +0100 Subject: [PATCH] Added opacity change instead of blur for background image --- src/qt_gui/game_grid_frame.cpp | 2 +- src/qt_gui/game_list_frame.cpp | 2 +- src/qt_gui/game_list_utils.h | 25 +++++++++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/qt_gui/game_grid_frame.cpp b/src/qt_gui/game_grid_frame.cpp index d719ac878..859a4867e 100644 --- a/src/qt_gui/game_grid_frame.cpp +++ b/src/qt_gui/game_grid_frame.cpp @@ -150,7 +150,7 @@ void GameGridFrame::SetGridBackgroundImage(int row, int column) { backgroundImage = QImage(blurredPic1PathQt); if (backgroundImage.isNull()) { QImage image(pic1Path); - backgroundImage = m_game_list_utils.BlurImage(image, image.rect(), 16); + backgroundImage = m_game_list_utils.ChangeImageOpacity(image, image.rect(), 0.5); std::filesystem::path img_path = Common::FS::GetUserPath(Common::FS::PathType::MetaDataDir) / diff --git a/src/qt_gui/game_list_frame.cpp b/src/qt_gui/game_list_frame.cpp index f2d08f578..b871f47b5 100644 --- a/src/qt_gui/game_list_frame.cpp +++ b/src/qt_gui/game_list_frame.cpp @@ -177,7 +177,7 @@ void GameListFrame::SetListBackgroundImage(QTableWidgetItem* item) { backgroundImage = QImage(blurredPic1PathQt); if (backgroundImage.isNull()) { QImage image(pic1Path); - backgroundImage = m_game_list_utils.BlurImage(image, image.rect(), 16); + backgroundImage = m_game_list_utils.ChangeImageOpacity(image, image.rect(), 0.5); std::filesystem::path img_path = Common::FS::GetUserPath(Common::FS::PathType::MetaDataDir) / diff --git a/src/qt_gui/game_list_utils.h b/src/qt_gui/game_list_utils.h index 581a8a55f..1a8860c1e 100644 --- a/src/qt_gui/game_list_utils.h +++ b/src/qt_gui/game_list_utils.h @@ -201,4 +201,29 @@ public: return result; } + + QImage ChangeImageOpacity(const QImage& image, const QRect& rect, float opacity) { + // Convert to ARGB32 format to ensure alpha channel support + QImage result = image.convertToFormat(QImage::Format_ARGB32); + + // Ensure opacity is between 0 and 1 + opacity = std::clamp(opacity, 0.0f, 1.0f); + + // Convert opacity to integer alpha value (0-255) + int alpha = static_cast(opacity * 255); + + // Process only the specified rectangle area + for (int y = rect.top(); y <= rect.bottom(); ++y) { + QRgb* line = reinterpret_cast(result.scanLine(y)); + for (int x = rect.left(); x <= rect.right(); ++x) { + // Get current pixel + QRgb pixel = line[x]; + // Keep RGB values, but modify alpha while preserving relative transparency + int newAlpha = (qAlpha(pixel) * alpha) / 255; + line[x] = qRgba(qRed(pixel), qGreen(pixel), qBlue(pixel), newAlpha); + } + } + + return result; + } };