Skip to content

Commit

Permalink
Merge pull request #149 from FoamyGuy/tuple_int_fix_pr
Browse files Browse the repository at this point in the history
convert tuple to hex color first
  • Loading branch information
FoamyGuy authored Jan 22, 2025
2 parents 3f945da + 74a2003 commit a42ece2
Showing 1 changed file with 7 additions and 0 deletions.
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

0 comments on commit a42ece2

Please sign in to comment.