feat: Extend high contrast mode to entire UI

- Add global high contrast mode flag in BitmapHelpers
- Modify quantization thresholds for high contrast rendering
- Update ditherer classes (Atkinson, Floyd-Steinberg) for contrast mode
- Add displayContrast setting with persistence
- Add "High Contrast" toggle in display settings
- Apply high contrast mode on startup from saved settings
This commit is contained in:
cottongin
2026-01-27 20:34:44 -05:00
parent 1496ce68a6
commit 158caacfe0
7 changed files with 80 additions and 27 deletions

View File

@@ -2,6 +2,17 @@
#include <cstdint>
// Global high contrast mode flag
static bool g_highContrastMode = false;
void setHighContrastMode(bool enabled) {
g_highContrastMode = enabled;
}
bool isHighContrastMode() {
return g_highContrastMode;
}
// Brightness/Contrast adjustments:
constexpr bool USE_BRIGHTNESS = false; // true: apply brightness/gamma adjustments
constexpr int BRIGHTNESS_BOOST = 10; // Brightness offset (0-50)
@@ -52,14 +63,28 @@ int adjustPixel(int gray) {
// Simple quantization without dithering - divide into 4 levels
// The thresholds are fine-tuned to the X4 display
uint8_t quantizeSimple(int gray) {
if (gray < 45) {
return 0;
} else if (gray < 70) {
return 1;
} else if (gray < 140) {
return 2;
if (g_highContrastMode) {
// High contrast: push mid-grays toward black/white
if (gray < 60) {
return 0;
} else if (gray < 100) {
return 1;
} else if (gray < 180) {
return 2;
} else {
return 3;
}
} else {
return 3;
// Normal thresholds
if (gray < 45) {
return 0;
} else if (gray < 70) {
return 1;
} else if (gray < 140) {
return 2;
} else {
return 3;
}
}
}

View File

@@ -2,6 +2,11 @@
#include <cstring>
// Global high contrast mode control
// When enabled, quantization thresholds are adjusted to push mid-grays toward black/white
void setHighContrastMode(bool enabled);
bool isHighContrastMode();
// Helper functions
uint8_t quantize(int gray, int x, int y);
uint8_t quantizeSimple(int gray);
@@ -122,21 +127,23 @@ class AtkinsonDitherer {
// Quantize to 4 levels
uint8_t quantized;
int quantizedValue;
if (false) { // original thresholds
if (adjusted < 43) {
if (isHighContrastMode()) {
// High contrast thresholds - push mid-grays toward extremes
if (adjusted < 50) {
quantized = 0;
quantizedValue = 0;
} else if (adjusted < 128) {
quantizedValue = 15;
} else if (adjusted < 90) {
quantized = 1;
quantizedValue = 85;
} else if (adjusted < 213) {
quantizedValue = 50;
} else if (adjusted < 170) {
quantized = 2;
quantizedValue = 170;
quantizedValue = 130;
} else {
quantized = 3;
quantizedValue = 255;
quantizedValue = 230;
}
} else { // fine-tuned to X4 eink display
} else {
// Normal thresholds - fine-tuned to X4 eink display
if (adjusted < 30) {
quantized = 0;
quantizedValue = 15;
@@ -223,24 +230,26 @@ class FloydSteinbergDitherer {
if (adjusted < 0) adjusted = 0;
if (adjusted > 255) adjusted = 255;
// Quantize to 4 levels (0, 85, 170, 255)
// Quantize to 4 levels
uint8_t quantized;
int quantizedValue;
if (false) { // original thresholds
if (adjusted < 43) {
if (isHighContrastMode()) {
// High contrast thresholds - push mid-grays toward extremes
if (adjusted < 50) {
quantized = 0;
quantizedValue = 0;
} else if (adjusted < 128) {
quantizedValue = 15;
} else if (adjusted < 90) {
quantized = 1;
quantizedValue = 85;
} else if (adjusted < 213) {
quantizedValue = 50;
} else if (adjusted < 170) {
quantized = 2;
quantizedValue = 170;
quantizedValue = 130;
} else {
quantized = 3;
quantizedValue = 255;
quantizedValue = 230;
}
} else { // fine-tuned to X4 eink display
} else {
// Normal thresholds - fine-tuned to X4 eink display
if (adjusted < 30) {
quantized = 0;
quantizedValue = 15;