# 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 ` 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 ` 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_/`). 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