Some fixes for cover generation

This commit is contained in:
jpirnay
2026-05-08 18:04:41 +02:00
parent 13e87ff470
commit 79ef2eea91
5 changed files with 29 additions and 15 deletions
+7 -2
View File
@@ -217,6 +217,11 @@ void HomeActivity::loadRecentCovers(int coverHeight) {
RECENT_BOOKS.updateBook(book.path, book.title, book.author, book.series, "");
book.coverBmpPath = "";
} else {
// Free the carousel frame cache before converting — PNG/JPEG decode needs ~42 KB
// contiguous heap, which won't be available while the 48 KB frame buffer is held.
// The cache will be rebuilt on the next render.
UITheme::getInstance().getMutableTheme().invalidateFrameCache();
const std::string cacheBase = "/.crosspoint/sidecar_" + std::to_string(std::hash<std::string>{}(book.path));
const std::string placeholder = cacheBase + "/[HEIGHT].bmp";
bool success = true;
@@ -239,8 +244,8 @@ void HomeActivity::loadRecentCovers(int coverHeight) {
book.coverBmpPath = placeholder;
} else {
LOG_ERR("HOME", "Failed to convert sidecar cover for %s", book.path.c_str());
RECENT_BOOKS.updateBook(book.path, book.title, book.author, book.series, "");
book.coverBmpPath = "";
// Don't permanently clear the path on failure — keep the raw sidecar path
// so the next home visit can retry (e.g. after more memory becomes available).
}
coverRendered = false;
nextRecentCoverIndex++;
-2
View File
@@ -62,13 +62,11 @@ std::string ReaderActivity::sidecarCoverPath(const std::string& bookPath) {
const std::string base = bookPath.substr(0, dot);
for (const char* ext : {".jpg", ".jpeg", ".png", ".bmp"}) {
const std::string candidate = base + ext;
LOG_DBG("SIDECAR", "Checking: %s", candidate.c_str());
if (Storage.exists(candidate.c_str())) {
LOG_DBG("SIDECAR", "Found sidecar cover: %s", candidate.c_str());
return candidate;
}
}
LOG_DBG("SIDECAR", "No sidecar found for: %s", bookPath.c_str());
return "";
}
@@ -52,7 +52,7 @@ void Lyra3CoversTheme::drawRecentBookCover(GfxRenderer& renderer, Rect rect, con
const float ratio = bitmapWidth / bitmapHeight;
const float tileRatio =
static_cast<float>(tileWidth - 2 * hPaddingInSelection) / static_cast<float>(coverHeight);
const float cropX = 1.0f - (tileRatio / ratio);
const float cropX = std::max(0.0f, 1.0f - (tileRatio / ratio));
renderer.drawBitmap(bitmap, tileX + hPaddingInSelection, tileY + hPaddingInSelection,
tileWidth - 2 * hPaddingInSelection, coverHeight, cropX);