diff --git a/src/display/waveshare_display.py b/src/display/waveshare_display.py index 6e88bb580..0bb3b40aa 100644 --- a/src/display/waveshare_display.py +++ b/src/display/waveshare_display.py @@ -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. @@ -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)