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

[stm32f4-ltdc] this fixes ltdc_get_rgb888_from_rgb565 return value type #682

Closed
wants to merge 1 commit into from
Closed
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
31 changes: 26 additions & 5 deletions include/libopencm3/stm32/f4/ltdc.h
Original file line number Diff line number Diff line change
Expand Up @@ -487,15 +487,36 @@ static inline bool LTDC_SRCR_IS_RELOADING(void)
}

/**
* color conversion helper function
* RGB565-to-RGB888 color conversion helper function
* (simulate the ltdc color conversion)
* NOTE: always use this function to calculate rgb888 for color key
* from rgb565 color!
*/
static inline uint32_t ltdc_get_rgb888_from_rgb565(uint16_t rgb565)
{
uint32_t r,g,b;

r = ((((rgb565) & 0xF800) >> (11-8))/31);
g = ((((rgb565) & 0x07E0) << (8-5))/63);
b = ((((rgb565) & 0x001F) << (8-0))/31);

if (r==256) r = 255;
if (g==256) g = 255;
if (b==256) b = 255;

return (r<<16) | (g<<8) | b;
}

static inline uint16_t ltdc_get_rgb888_from_rgb565(uint16_t rgb888)
/**
* RGB888-to-RGB565 color conversion helper function
*/
static inline uint16_t ltdc_get_rgb565_from_rgb888(uint32_t rgb888)
{
return ((((rgb888) & 0xF800) >> (11-8))/31)<<16
| ((((rgb888) & 0x07E0) << (8-5))/63)<<8
| ((((rgb888) & 0x001F) << (8-0))/31)<<0;
return (uint16_t)(
((rgb888 & 0xf80000) >> (16-11 + 8-5)) /* grab upper 5 bits of red */
| ((rgb888 & 0x00fc00) >> (8-5 + 8-6)) /* grab upper 6 bits of green */
| ((rgb888 & 0x0000f8) >> (0-0 + 8-5)) /* grab upper 5 bits of blue */
);
}


Expand Down