@@ -666,18 +666,18 @@ def _full_writeEPD_hd(self, image):
666666 def _full_writeEPD_non_hd (self , image ):
667667 '''wipe screen and write an image'''
668668 if self .screen_type == ScreenType .FOUR_GRAYS :
669- image_buffer = self .epd .getbuffer_4Gray (image )
669+ image_buffer = self .epd .getbuffer_4Gray (Screen . image_to_4_grays ( image ) )
670670 else :
671671 image_buffer = self .epd .getbuffer (image )
672672
673673 try :
674674 if self .screen_type == ScreenType .FOUR_GRAYS :
675- logging .debug ('one-bit display' )
675+ logging .debug ('4 grayscale display' )
676676 self .epd .display_4Gray (image_buffer )
677677 elif self .screen_type == ScreenType .THREE_COLORS : # displays that require multiple images
678678 logging .debug ('bi-color display' )
679679 self .epd .display (image_buffer , self .buffer_no_image )
680- else : # 7 color displays
680+ else : # 7 color or monochrome displays
681681 logging .debug ('seven-color or monochrome display' )
682682 self .epd .display (image_buffer )
683683
@@ -771,6 +771,25 @@ def module_exit(self):
771771 logging .warning (f'failed to sleep module: { e } ' )
772772 raise ScreenError (e )
773773
774+ @staticmethod
775+ def image_to_4_grays (image ):
776+ logging .debug ('converting image to 4 grays' )
777+
778+ '''
779+ Waveshare displays do not render colors accurately.
780+ For example, an input color of "#808080" looks more like "#a9aca3" on the ePaper.
781+ Therefore, we convert our images to grayscale in 2 steps:
782+ 1. Convert colors to their actual displayed output
783+ 2. Update palette to reverse the error
784+ '''
785+ palette = Screen .colors2palette (constants .COLORS_4GRAY_NATURAL .values ())
786+ image_gs = Screen .reduce_palette (image , palette , True )
787+
788+ ws_palette = Screen .colors2palette (constants .COLORS_4GRAY_WS .values ())
789+ image_gs .putpalette (ws_palette )
790+ return image_gs
791+
792+
774793
775794# + code_folding=[]
776795def list_compatible_modules (print_modules = True , reasons = False ):
0 commit comments