russhughes / st7789py_mpy

Driver for 320x240, 240x240, 135x240 and 128x128 ST7789 displays written in MicroPython
MIT License
159 stars 59 forks source link

image converter does not do proper rgb_to_color565 conversion #17

Open Troyhy opened 2 months ago

Troyhy commented 2 months ago

Hi, I was using this image converter and noticed that with test picture like this test color palette does not have pure white 0xFFFF but it has 0xFFF8. Question is that is this somehow intentional or a bug? Here is the converter function and my proposed fix:

r=g=b=255
a = ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b & 0xF8)
#fixed
b = ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3)
print(f'{a:016b} != {b:016b}\n{a:2x} != {b:2x}')

# 1111111111111000 != 1111111111111111
# fff8 != ffff

https://github.com/russhughes/st7789py_mpy/blob/7265925bd0c092e8105200d18b2dba9dfbc12c27/utils/image_converter.py#L47-L60

Troyhy commented 2 months ago

Ah sorry, just realized that there is a pull request about it https://github.com/russhughes/st7789py_mpy/pull/14