Skip to content

Commit

Permalink
Fix color issues
Browse files Browse the repository at this point in the history
The issue with the color was that a little bug regarding to the bit shifting operations in the native color converter. This fixes the issue by shifting the additional required 8 bits to become the right color by conversion.
  • Loading branch information
RossAdrian committed Aug 4, 2024
1 parent 4991758 commit f683156
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions native/color.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ void pyfb_initcolor_u32(struct pyfb_color* cptr, uint32_t value) {

// initialize the 16 bit color
#if __BYTE_ORDER == __LITTLE_ENDIAN
unsigned int r = (value & 0xFF000000) >> 16;
unsigned int g = (value & 0x00FF0000) >> 8;
unsigned int b = (value & 0x0000FF00);
unsigned int r = (value & 0xFF000000) >> 24;
unsigned int g = (value & 0x00FF0000) >> 16;
unsigned int b = (value & 0x0000FF00) >> 8;
u16_color = (uint16_t)((r >> 3 << 11) + (g >> 2 << 5) + (b >> 3));
#else
unsigned int r = (value & 0x000000FF) << 16;
unsigned int g = (value & 0x0000FF00) << 8;
unsigned int b = (value & 0x00FF0000);
unsigned int r = (value & 0x000000FF) << 24;
unsigned int g = (value & 0x0000FF00) << 16;
unsigned int b = (value & 0x00FF0000) << 8;
u16_color = (uint16_t)((r << 3 >> 11) + (g << 2 >> 5) + (b << 3));
#endif

Expand All @@ -35,8 +35,7 @@ void pyfb_initcolor_u16(struct pyfb_color* cptr, uint16_t value) {
g = g * 255 / 63;
b = b * 255 / 31;

u32_color = (uint32_t)((r << 16) | (g << 8) | b);
u32_color = u32_color << 8;
u32_color = (uint32_t)((r << 24) | (g << 16) | (b << 8));

// now set the alpha
u32_color &= 0xFFFFFF00;// clear alpha channel if something is in there
Expand All @@ -49,8 +48,7 @@ void pyfb_initcolor_u16(struct pyfb_color* cptr, uint16_t value) {
g = g * 255 / 63;
b = b * 255 / 31;

u32_color = (uint32_t)((r >> 16) | (g >> 8) | b);
u32_color = u32_color >> 8;
u32_color = (uint32_t)((r >> 24) | (g >> 16) | (b >> 8));

// now set the alpha
u32_color &= 0x00FFFFFF;// clear the alpha channel if something is in there
Expand Down

0 comments on commit f683156

Please sign in to comment.