From 48aed23a17a5cbd2ed8b995f6153f9d82d767c08 Mon Sep 17 00:00:00 2001 From: bdamokos <163609735+bdamokos@users.noreply.github.com> Date: Wed, 25 Dec 2024 22:08:54 +0100 Subject: [PATCH] add a dominance threshold for colour handling --- bus_service.py | 5 +++++ color_utils.py | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/bus_service.py b/bus_service.py index 7f5b5a2..7c1e219 100644 --- a/bus_service.py +++ b/bus_service.py @@ -199,6 +199,11 @@ def _get_dithering_colors(self, target_rgb: Tuple[int, int, int]) -> Tuple[str, # Ensure ratio is between 0.0 and 1.0 ratio = max(0.0, min(1.0, ratio)) + # If the primary color is very dominant (>80%), use it exclusively + DOMINANCE_THRESHOLD = 0.8 + if ratio >= DOMINANCE_THRESHOLD: + return color1, color2, 1.0 + return color1, color2, ratio def set_epd(self, epd): diff --git a/color_utils.py b/color_utils.py index fadc407..aa8d716 100644 --- a/color_utils.py +++ b/color_utils.py @@ -17,6 +17,17 @@ def find_optimal_colors(pixel_rgb, epd): yellow_ratio = min(r, g) / 255.0 # Yellow needs both red and green orange_factor = min(r, g) / max(1, r) if r > 0 else 0 # How "yellow" is the orange + # Check for dominant colors first + DOMINANCE_THRESHOLD = 0.8 + if has_yellow and r > 200 and g > 200 and b < 100: # Strong yellow + yellow_strength = min(r, g) / 255.0 + if yellow_strength >= DOMINANCE_THRESHOLD: + return [('yellow', 1.0)] + if has_red and r > 200 and g < 100 and b < 100: # Strong red + red_strength = r / 255.0 + if red_strength >= DOMINANCE_THRESHOLD: + return [('red', 1.0)] + # Handle pure white specially if r > 250 and g > 250 and b > 250: return [('white', 1.0)]