Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

image converter does not do proper rgb_to_color565 conversion #17

Open
Troyhy opened this issue Sep 3, 2024 · 1 comment
Open

image converter does not do proper rgb_to_color565 conversion #17

Troyhy opened this issue Sep 3, 2024 · 1 comment

Comments

@Troyhy
Copy link

Troyhy commented Sep 3, 2024

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

def rgb_to_color565(r, g, b):
"""
Convert RGB color to the 16-bit color format (565).
Args:
r (int): Red component of the RGB color (0-255).
g (int): Green component of the RGB color (0-255).
b (int): Blue component of the RGB color (0-255).
Returns:
int: Converted color value in the 16-bit color format (565).
"""
return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b & 0xF8)

@Troyhy
Copy link
Author

Troyhy commented Sep 3, 2024

Ah sorry, just realized that there is a pull request about it #14

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant