Update
This commit is contained in:
parent
23f4bd88fc
commit
8b619fe2cc
17 changed files with 2185 additions and 2130 deletions
16
rgb565.md
16
rgb565.md
|
@ -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).
|
Loading…
Add table
Add a link
Reference in a new issue