From 224aece0296b404e6e3108e981afe1f7c1874419 Mon Sep 17 00:00:00 2001 From: Pablo Santana Date: Mon, 3 Feb 2025 01:33:27 +0100 Subject: [PATCH] Removed background image caching --- src/qt_gui/game_grid_frame.cpp | 21 +-------------------- src/qt_gui/game_list_frame.cpp | 20 -------------------- src/qt_gui/game_list_utils.h | 13 ------------- 3 files changed, 1 insertion(+), 53 deletions(-) diff --git a/src/qt_gui/game_grid_frame.cpp b/src/qt_gui/game_grid_frame.cpp index 2d3f0b636..17dd77ef9 100644 --- a/src/qt_gui/game_grid_frame.cpp +++ b/src/qt_gui/game_grid_frame.cpp @@ -162,6 +162,7 @@ void GameGridFrame::SetGridBackgroundImage(int row, int column) { return; } + // If background images are hidden, clear the background image if (!Config::getShowBackgroundImage()) { backgroundImage = QImage(); RefreshGridBackgroundImage(); @@ -170,31 +171,11 @@ void GameGridFrame::SetGridBackgroundImage(int row, int column) { const auto& game = (*m_games_shared)[itemID]; const int opacity = Config::getBackgroundImageOpacity(); - const auto cache_path = Common::FS::GetUserPath(Common::FS::PathType::MetaDataDir) / - game.serial / fmt::format("pic1_{}.png", opacity); - // Fast path - try to load cached version first - if (std::filesystem::exists(cache_path)) { - backgroundImage = QImage(QString::fromStdString(cache_path.string())); - if (!backgroundImage.isNull()) { - RefreshGridBackgroundImage(); - return; - } - } - - // Cache miss - generate and store - m_game_list_utils.CleanupOldOpacityImages(cache_path.parent_path()); QImage original_image(QString::fromStdString(game.pic_path.string())); if (!original_image.isNull()) { - std::filesystem::create_directories(cache_path.parent_path()); backgroundImage = m_game_list_utils.ChangeImageOpacity( original_image, original_image.rect(), opacity / 100.0f); - if (!backgroundImage.isNull()) { - // Save the image to the cache asynchronously - QFuture future = QtConcurrent::run([this, cache_path]() { - backgroundImage.save(QString::fromStdString(cache_path.string()), "PNG"); - }); - } } RefreshGridBackgroundImage(); diff --git a/src/qt_gui/game_list_frame.cpp b/src/qt_gui/game_list_frame.cpp index 53957ea2b..e9b41c1c0 100644 --- a/src/qt_gui/game_list_frame.cpp +++ b/src/qt_gui/game_list_frame.cpp @@ -176,31 +176,11 @@ void GameListFrame::SetListBackgroundImage(QTableWidgetItem* item) { const auto& game = m_game_info->m_games[item->row()]; const int opacity = Config::getBackgroundImageOpacity(); - const auto cache_path = Common::FS::GetUserPath(Common::FS::PathType::MetaDataDir) / - game.serial / fmt::format("pic1_{}.png", opacity); - // Fast path - try to load cached version first - if (std::filesystem::exists(cache_path)) { - backgroundImage = QImage(QString::fromStdString(cache_path.string())); - if (!backgroundImage.isNull()) { - RefreshListBackgroundImage(); - return; - } - } - - // Cache miss - generate and store - m_game_list_utils.CleanupOldOpacityImages(cache_path.parent_path()); QImage original_image(QString::fromStdString(game.pic_path.string())); if (!original_image.isNull()) { - std::filesystem::create_directories(cache_path.parent_path()); backgroundImage = m_game_list_utils.ChangeImageOpacity( original_image, original_image.rect(), opacity / 100.0f); - if (!backgroundImage.isNull()) { - // Save the image to the cache asynchronously - QFuture future = QtConcurrent::run([this, cache_path]() { - backgroundImage.save(QString::fromStdString(cache_path.string()), "PNG"); - }); - } } RefreshListBackgroundImage(); diff --git a/src/qt_gui/game_list_utils.h b/src/qt_gui/game_list_utils.h index ac7702f70..c6b69e70e 100644 --- a/src/qt_gui/game_list_utils.h +++ b/src/qt_gui/game_list_utils.h @@ -227,17 +227,4 @@ public: return result; } - - void CleanupOldOpacityImages(const std::filesystem::path& dir) { - if (!std::filesystem::exists(dir)) { - return; - } - - for (const auto& entry : std::filesystem::directory_iterator(dir)) { - const auto& path = entry.path(); - if (path.filename().string().starts_with("pic1") && path.extension() == ".png") { - std::filesystem::remove(path); - } - } - } };