Skip to content

Commit

Permalink
ColorConverter was inaccurate when converting rgb555 (and bgr555) col…
Browse files Browse the repository at this point in the history
…orspace to rgb888. For details look at: https://stackoverflow.com/questions/71106056/what-is-the-correct-way-to-convert-rgb555-to-rgb888. I only tested rgb555 and not the bgr555 code path!
  • Loading branch information
qutefox committed Feb 17, 2025
1 parent bd572f8 commit ff8cec3
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions shared-module/displayio/ColorConverter.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,12 @@ uint32_t displayio_colorconverter_convert_pixel(displayio_colorspace_t colorspac
pixel = __builtin_bswap16(pixel);
MP_FALLTHROUGH;
case DISPLAYIO_COLORSPACE_RGB555: {
uint32_t r8 = (pixel >> 10) << 3;
uint32_t g8 = ((pixel >> 5) << 3) & 0xff;
uint32_t b8 = (pixel << 3) & 0xff;
uint32_t r8 = (pixel >> 10) & 0x1f;
uint32_t g8 = (pixel >> 5) & 0x1f;
uint32_t b8 = pixel & 0x1f;
r8 = (r8 << 3) | ((r8 >> 2) & 0b111);
g8 = (g8 << 3) | ((g8 >> 2) & 0b111);
b8 = (b8 << 3) | ((b8 >> 2) & 0b111);
pixel = (r8 << 16) | (g8 << 8) | b8;
}
break;
Expand All @@ -219,9 +222,12 @@ uint32_t displayio_colorconverter_convert_pixel(displayio_colorspace_t colorspac
pixel = __builtin_bswap16(pixel);
MP_FALLTHROUGH;
case DISPLAYIO_COLORSPACE_BGR555: {
uint32_t b8 = (pixel >> 10) << 3;
uint32_t g8 = ((pixel >> 5) << 3) & 0xff;
uint32_t r8 = (pixel << 3) & 0xff;
uint32_t b8 = (pixel >> 10) & 0x1f;
uint32_t g8 = (pixel >> 5) & 0x1f;
uint32_t r8 = pixel & 0x1f;
r8 = (r8 << 3) | ((r8 >> 2) & 0b111);
g8 = (g8 << 3) | ((g8 >> 2) & 0b111);
b8 = (b8 << 3) | ((b8 >> 2) & 0b111);
pixel = (r8 << 16) | (g8 << 8) | b8;
}
break;
Expand Down

0 comments on commit ff8cec3

Please sign in to comment.