This commit is contained in:
Miloslav Ciz 2025-05-26 19:29:00 +02:00
parent 23f4bd88fc
commit 8b619fe2cc
17 changed files with 2185 additions and 2130 deletions

View file

@ -30,4 +30,20 @@ void rgbFrom565(unsigned int colorIndex, unsigned char *red,
}
```
And also maybe a more practical variant:
```
uint16_t rgbTo565(uint32_t c)
{
return ((c >> 8) & 0xf800) | ((c >> 5) & 0x07e0) | ((c >> 3) & 0x001f);
}
uint32_t rgbFrom565(uint16_t c565)
{
uint32_t c =
((c565 & 0xf800) << 8) | ((c565 & 0x7e0) << 5) | ((c565 & 0x001f) << 3);
return c | ((c >> 5) & 0x070307);
}
```
There exist nice tricks you can do with colors represented this way, like quickly divide all three R, G and B components by a power of two just by doing one bit shift and logical [AND](and.md) to zero the highest bits of the components, or approximating addition of colors with logical [OR](or.md) and so on -- for details see the article on [RGB332](rgb332.md).