Files
crosspoint-reader-mod/chat-summaries/2026-02-09_16-29-summary.md

26 lines
1.9 KiB
Markdown
Raw Normal View History

# Edge Data Caching for Sleep Screen Letterbox Fill
## Task
Cache the letterbox edge-sampling calculations so they are only computed once per cover image (on first sleep) and reused from a binary cache file on subsequent sleeps.
## Changes Made
### `src/activities/boot_sleep/SleepActivity.h`
- Added `#include <string>` and updated `renderBitmapSleepScreen` signature to accept an optional `edgeCachePath` parameter (defaults to empty string for no caching).
### `src/activities/boot_sleep/SleepActivity.cpp`
- Added `#include <Serialization.h>` for binary read/write helpers.
- Added `loadEdgeCache()` function in the anonymous namespace: loads edge data from a binary cache file, validates the cache version and screen dimensions against current values to detect stale data.
- Added `saveEdgeCache()` function: writes edge data (edgeA, edgeB arrays + metadata) to a compact binary file (~10 bytes header + 2 * edgeCount bytes data, typically under 1KB).
- Updated `renderBitmapSleepScreen()`: tries loading from cache before sampling. On cache miss, samples edges from bitmap and saves to cache. On cache hit, skips the bitmap sampling pass entirely.
- Updated `renderCoverSleepScreen()`: derives the edge cache path from the cover BMP path (e.g. `cover.bmp` -> `cover_edges.bin`) and passes it to `renderBitmapSleepScreen`. The cache is stored alongside the cover BMP in the book's `.crosspoint` directory.
- Custom sleep images (`renderCustomSleepScreen`) do not use caching since the image may change randomly each sleep.
### Cache Design
- **Format**: Binary file with version byte, screen dimensions, horizontal flag, edge count, letterbox sizes, and two edge color arrays.
- **Invalidation**: Validated by cache version and screen dimensions. Naturally scoped per-book (lives in `/.crosspoint/epub_<hash>/`). Different cover modes (FIT vs CROP) produce different BMP files and thus different cache paths.
- **Size**: ~970 bytes for a 480-wide image.
## Follow-up Items
- None