robweber / omni-epd

An EPD (electronic paper display) class abstraction to simplify communications across multiple display types.
GNU General Public License v3.0
75 stars 16 forks source link

Mock Display Palette with Dithering #69

Closed robweber closed 2 years ago

robweber commented 2 years ago

This doesn't impact usability in a meaningful way but it is a shortcoming. When using the omni_epd.mock display in color mode the value of the palette_filter attribute returns the colors for black and white but no other colors.

The main effect this has is if you also try and apply a dither effect to the image when using the mock display. The dithering process expects this attribute to exist and have correct values. When testing this on a color image, applying a dither always results in a black and white image as that is the returned palette.

Since the mock display is really more of a testing tool it isn't a meaningful usability issue but will not yield correct results in it's current form.

Issues with a fix

A simple fix for this wasn't evident at first glance. The dithering code is triggered when display() is called within the parent VirtualEPD class prior to the display implementation method _display() being called. As a result the effect is already applied before the specific device class has access to the Image. Because this is a parent class function it's not easy to code around this by simply importing the palette of the Image object. There are other displays that use color as their mode that do set a proper palette correctly from the device driver.

Workarounds

Not really a workaround but if no fix can be found I think it would be ok to simply document this as a shortcoming and leave it as is. It's not really a show stopper as it doesn't effect actual devices.

missionfloyd commented 2 years ago

Just installed 736f0e7fa3d50926f48b2fea19996208178b6cea to check this. Seems to work here. mock_output

[EPD]
type=omni_epd.mock
mode=color
# DESATURATED_PALETTE from inky impression lib
palette_filter=[[0, 0, 0], [255, 255, 255], [0, 255, 0], [0, 0, 255], [255, 0, 0], [255, 255, 0], [255, 140, 0], [255, 255, 255]]
width=800
height=480

[Display]
dither=floyd-steinberg

Edit: Okay I see now, doesn't work without palette_filter in the ini. Perhaps set a default palette for color mode?

robweber commented 2 years ago

Added a hardcoded palette based on the list of standard web safe colors. These are an accepted 216 color list that should yield a decent looking image. I think this is reasonable for a virtual testing class and will allow functions, like dithering, to work in a test environment without resulting a black and white image.