Added opacity change instead of blur for background image

This commit is contained in:
Pablo Santana 2025-02-02 02:27:49 +01:00
parent 1d8c607c15
commit 4040f58af6
3 changed files with 27 additions and 2 deletions

View File

@ -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) /

View File

@ -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) /

View File

@ -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<int>(opacity * 255);
// Process only the specified rectangle area
for (int y = rect.top(); y <= rect.bottom(); ++y) {
QRgb* line = reinterpret_cast<QRgb*>(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;
}
};