now displays both rounded and unrounded variants

This commit is contained in:
Alex Gentilucci 2020-05-28 17:30:37 -06:00
parent 1d847c96cb
commit 939a9019aa
Signed by: nytpu
GPG Key ID: 144ADD49F173F5CE
2 changed files with 17 additions and 5 deletions

View File

@ -6,6 +6,9 @@ instead of RGB for use on the Game Boy Color and Game Boy Advance. It also
outputs a 24 bit representation of the 15 bit color (still in `0xRRGGBB`) for
use in things like your sprite software.
If it outputs a rounded and unrounded variant, it's up to you to look at it and
decide which you like, because they may differ significantly.
## compiling:
```

19
main.c
View File

@ -26,14 +26,23 @@ int main (int argc, char *argv[])
split.b = in_888 & 0x000000FF;
// Basic rounding
if (split.r & 4) split.r |= 8;
if (split.g & 4) split.g |= 8;
if (split.b & 4) split.b |= 8;
rgb888 rounded = split;
if (split.r & 4) rounded.r |= 8;
if (split.g & 4) rounded.g |= 8;
if (split.b & 4) rounded.b |= 8;
int16_t rgb555 = ((split.b & 0xF8) << 7) | ((split.g & 0xF8) << 2) | (split.r >> 3);
int16_t rgb555_rounded = ((rounded.b & 0xF8) << 7) | ((rounded.g & 0xF8) << 2) | (rounded.r >> 3);
printf("Output, 15 bit color, 4 char hex: 0x%04X\n", rgb555);
printf("Output, 15 bit color, 6 char hex: #%06X\n", (uint32_t) ((split.r & 0xF8) << 16) | ((split.g & 0xF8) << 8) | (split.b & 0xF8));
if (rgb555 != rgb555_rounded) {
printf("Output, 15 bit color, 6 char hex, unrounded: #%06X\n", (uint32_t) ((split.r & 0xF8) << 16) | ((split.g & 0xF8) << 8) | (split.b & 0xF8));
printf("Output, 15 bit color, 6 char hex, rounded: #%06X\n", (uint32_t) ((rounded.r & 0xF8) << 16) | ((rounded.g & 0xF8) << 8) | (rounded.b & 0xF8));
printf("Output, 15 bit color, 4 char hex, unrounded: 0x%04X\n", rgb555);
printf("Output, 15 bit color, 4 char hex, rounded: 0x%04X\n", rgb555_rounded);
} else {
printf("Output, 15 bit color, 6 char hex: #%06X\n", (uint32_t) ((split.r & 0xF8) << 16) | ((split.g & 0xF8) << 8) | (split.b & 0xF8));
printf("Output, 15 bit color, 4 char hex: 0x%04X\n", rgb555);
}
return 0;
}