Skip to content

Commit

Permalink
add a dominance threshold for colour handling
Browse files Browse the repository at this point in the history
  • Loading branch information
bdamokos committed Dec 25, 2024
1 parent 25566ff commit 48aed23
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions bus_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
11 changes: 11 additions & 0 deletions color_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down

0 comments on commit 48aed23

Please sign in to comment.