Removed background image caching

This commit is contained in:
Pablo Santana 2025-02-03 01:33:27 +01:00
parent be979a535d
commit 224aece029
3 changed files with 1 additions and 53 deletions

View File

@ -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<void> future = QtConcurrent::run([this, cache_path]() {
backgroundImage.save(QString::fromStdString(cache_path.string()), "PNG");
});
}
}
RefreshGridBackgroundImage();

View File

@ -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<void> future = QtConcurrent::run([this, cache_path]() {
backgroundImage.save(QString::fromStdString(cache_path.string()), "PNG");
});
}
}
RefreshListBackgroundImage();

View File

@ -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);
}
}
}
};