40 lines
2.2 KiB
Markdown
40 lines
2.2 KiB
Markdown
|
|
# Prerender Book Covers/Thumbnails on First Open
|
||
|
|
|
||
|
|
**Date:** 2026-02-12
|
||
|
|
**Branch:** `mod/prerender-book-covers`
|
||
|
|
|
||
|
|
## Task
|
||
|
|
|
||
|
|
Implement todo item: "Process/render all covers/thumbs when opening book for first time" with a progress indicator so the reader doesn't appear frozen.
|
||
|
|
|
||
|
|
## Changes Made
|
||
|
|
|
||
|
|
### `src/components/UITheme.h`
|
||
|
|
- Added `PRERENDER_THUMB_HEIGHTS[]` and `PRERENDER_THUMB_HEIGHTS_COUNT` constants (226, 400) representing all known theme `homeCoverHeight` values (Lyra and Base). This ensures thumbnails are pre-generated for all themes.
|
||
|
|
|
||
|
|
### `src/activities/reader/EpubReaderActivity.cpp`
|
||
|
|
- Added prerender block in `onEnter()` after `setupCacheDir()` and before `addBook()`.
|
||
|
|
- Checks whether `cover.bmp`, `cover_crop.bmp`, `thumb_226.bmp`, and `thumb_400.bmp` exist.
|
||
|
|
- If any are missing, shows "Preparing book..." popup with a progress bar that updates after each generation step.
|
||
|
|
- On subsequent opens, all files already exist and the popup is skipped entirely.
|
||
|
|
|
||
|
|
### `src/activities/reader/XtcReaderActivity.cpp`
|
||
|
|
- Added same prerender pattern in `onEnter()`.
|
||
|
|
- Generates `cover.bmp`, `thumb_226.bmp`, and `thumb_400.bmp` (XTC has no cropped cover variant).
|
||
|
|
|
||
|
|
### `src/activities/reader/TxtReaderActivity.cpp`
|
||
|
|
- Added prerender for `cover.bmp` only (TXT has no thumbnail support).
|
||
|
|
- Shows "Preparing book..." popup if the cover needs generating.
|
||
|
|
|
||
|
|
## Design Decisions
|
||
|
|
|
||
|
|
- **Letterbox edge data not prerendered:** The sleep screen's letterbox gradient fill (`cover_edges.bin`) depends on runtime settings (crop mode, screen dimensions) and is already efficiently cached after first sleep. The expensive part (JPEG-to-BMP conversion) is what this change addresses.
|
||
|
|
- **TXT `addBook()` cover path unchanged:** The `coverBmpPath` field in `RecentBook` is used for home screen thumbnails, not sleep covers. Since TXT has no thumbnail support, passing `""` remains correct.
|
||
|
|
- **HomeActivity::loadRecentCovers() kept as fallback:** Books opened before this change will still have thumbnails generated lazily on the Home screen. No code removal needed.
|
||
|
|
|
||
|
|
## Follow-up Items
|
||
|
|
|
||
|
|
- Mark todo item as complete in `mod/docs/todo.md`
|
||
|
|
- Test on device with each book format (EPUB, XTC/XTCH, TXT)
|
||
|
|
- If a new theme is added with a different `homeCoverHeight`, update `PRERENDER_THUMB_HEIGHTS`
|