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

convert tuple to hex color first #149

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions displayio/_colorconverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,15 @@ def _convert(
self._cached_input_pixel = input_pixel.pixel
self._cached_output_color = output_color.pixel

@staticmethod
def _rgbtuple_to_hex(color_tuple):
"""Convert rgb tuple with 0-255 values to hex color value"""
return color_tuple[0] << 16 | color_tuple[1] << 8 | color_tuple[2]

@staticmethod
def _convert_pixel(colorspace: Colorspace, pixel: int) -> int:
if isinstance(pixel, tuple):
pixel = ColorConverter._rgbtuple_to_hex(pixel)
pixel = clamp(pixel, 0, 0xFFFFFFFF)
if colorspace in (
Colorspace.RGB565_SWAPPED,
Expand Down
Loading