feat: Sleep screen letterbox fill and image upscaling
Add configurable letterbox fill for sleep screen cover images that don't match the display aspect ratio. Four fill modes are available: Solid (single dominant edge shade), Blended (per-pixel edge colors), Gradient (edge colors interpolated toward white/black), and None. Enable upscaling of cover images smaller than the display in Fit mode by modifying drawBitmap/drawBitmap1Bit to support both up and downscaling via a unified block-fill approach. Edge sampling data is cached to .crosspoint alongside the cover BMP to avoid redundant bitmap scanning on subsequent sleeps. Cache is validated against screen dimensions and auto-regenerated when stale. New settings: Letterbox Fill (None/Solid/Blended/Gradient) and Gradient Direction (To White/To Black). Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -104,3 +104,20 @@ uint8_t quantize1bit(int gray, int x, int y) {
|
||||
const int adjustedThreshold = 128 + ((threshold - 128) / 2); // Range: 64-192
|
||||
return (gray >= adjustedThreshold) ? 1 : 0;
|
||||
}
|
||||
|
||||
// Noise dithering for gradient fills - always uses hash-based noise regardless of global dithering config.
|
||||
// Produces smooth-looking gradients on the 4-level e-ink display.
|
||||
uint8_t quantizeNoiseDither(int gray, int x, int y) {
|
||||
uint32_t hash = static_cast<uint32_t>(x) * 374761393u + static_cast<uint32_t>(y) * 668265263u;
|
||||
hash = (hash ^ (hash >> 13)) * 1274126177u;
|
||||
const int threshold = static_cast<int>(hash >> 24);
|
||||
|
||||
const int scaled = gray * 3;
|
||||
if (scaled < 255) {
|
||||
return (scaled + threshold >= 255) ? 1 : 0;
|
||||
} else if (scaled < 510) {
|
||||
return ((scaled - 255) + threshold >= 255) ? 2 : 1;
|
||||
} else {
|
||||
return ((scaled - 510) + threshold >= 255) ? 3 : 2;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user