robweber / omni-epd

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

EPDConfigurationError with example image in red mode #97

Closed fardage closed 7 months ago

fardage commented 7 months ago

Hello,

I've been using your fantastic library for my project and stumbled upon something puzzling.

I was trying to display an image (PIA03519_small.jpg) using the waveshare_epd.epd7in5b_V2 display in red mode and encountered the following error:

omni_epd.errors.EPDConfigurationError: '41 colors' for 'palette_filter' is not a valid configuration value for waveshare_epd.epd7in5b_V2

Here's the terminal command I used:

omni-epd-test -e waveshare_epd.epd7in5b_V2 -i ../PIA03519_small.jpg

I also tweaked the config file (omni-epd.ini) as follows:

[EPD]
type=waveshare_epd.epd7in5b_V2
mode=red

Interestingly, this problem seems to occur only in the red mode, and things work perfectly fine when I switch to black and white mode.

I was wondering if this is a normal issue or if there's a certain preprocessing step required for the image before it can be displayed in red mode. Any pointer that might help in resolving this issue would be highly appreciated.

Looking forward to hearing from you soon!

Best Regards.

robweber commented 7 months ago

What you're describing should work. You may have found a bug but not sure yet.

Reviewing the code where that error is thrown this happens when the number of filter colors in the palette_filter is more than the display can accommodate. Are those entries in your config file the only customizations in that file? The user can override the palette filter but it has to contain the same number of colors. Just confirming you don't have a palette filter customization somewhere before troubleshooting this further.

Also - can you confirm you're on the most recent version of the library? That way I can test 1:1.

fardage commented 7 months ago

After checking my environment with pip, it shows that I'm running the latest version of omni-epd which is version 0.4.1b1. As for the omni-epd.ini file, I have not made any additional customizations except for the type and mode, where mode was set to red as I mentioned earlier. Specifically, I have not defined a palette_filter.

I added print statements in virtualepd.py at line 174. The colors output is [[255, 255, 255], [0, 0, 0], [255, 0, 0]], and the palette is [255, 255, 255, 0, 0, 0, 255, 0, 0]. Since the palette has more than three elements, it causes an EPDConfigurationError. I'm unsure about the exact representation of the palette.

robweber commented 7 months ago

That's helpful - thanks. I'll run some tests. It's possible either the comparison or format of the palette is wrong; however I'd have expected this to show up long before now. I have some different devices I can test on. The palette mapping is the same for all devices so I should be able to find some common problems.

robweber commented 7 months ago

Did some checking and I think that if statement needs adjusting. There was a time when the colors array was expected to be an array of RGB colors (each an array as well). It's been modified a few times to accept other things (like the names of colors) so the result is no longer an array. The same goes for the palette itself. It's a single array of RGB values all in a row as opposed to an array of arrays.

Try modifying line 176 to the following:

if (len(palette) > self.max_colors * 3):

The check should pass now as it's expecting 3 values for every color. If this works I'll have some other updating to do on the log messages, as well as making sure this type of check isn't happening elsewhere.

fardage commented 7 months ago

Sure, I've tested your proposed change, and it indeed resolves the issue on my setup. Now, I can use the red mode without any problems. Let me know if you need any further assistance or if there's anything else I can help with.

robweber commented 7 months ago

I started updating an actual fix for this and realized it affected other things as well - like the dithering options. Everything seems to trace back to when changes were made to how the color values are parsed. Will have the fix done later today but was more systemic than expected. Thanks for pointing this out!