Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion src/display/waveshare_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,30 @@ def split_image_for_bi_color_epd(image):
return black_layer, red_layer


def quantize_for_color_epd(image):
"""
Quantize image with correct palette for E6 (Spectra 6) full-color e-paper displays.

E6 displays support 6 colors: black, white, red, yellow, green, blue (no orange).
Using the exact hardware color palette reduces dithering artifacts and blotchy text.
"""
black = (0, 0, 0)
white = (255, 255, 255)
red = (255, 0, 0)
yellow = (255, 255, 0)
green = (0, 255, 0)
blue = (0, 0, 255)

# E6/Spectra 6 palette: 6 colors (black, white, red, yellow, green, blue)
palette_data = [*black, *white, *red, *yellow, *green, *blue]
palette_img = Image.new('P', (1, 1))
palette_img.putpalette(palette_data)

# Quantize to hardware-supported colors - reduces dithering
return image.quantize(palette=palette_img, dither=Image.Dither.FLOYDSTEINBERG).convert('RGB')



class WaveshareDisplay(AbstractDisplay):
"""
Handles Waveshare e-paper display dynamically based on device type.
Expand Down Expand Up @@ -129,7 +153,9 @@ def display_image(self, image, image_settings=[]):

# Display the image on the WS display.
if not self.bi_color_display:
self.epd_display.display(self.epd_display.getbuffer(image))
# Apply extended palette quantization for full-color displays
quantized_image = quantize_for_color_epd(image)
self.epd_display.display(self.epd_display.getbuffer(quantized_image))
else:
black_layer, red_layer = split_image_for_bi_color_epd(image)

Expand Down