Now outputs rounded down, unrounded, and rounded up variants
This commit is contained in:
parent
77435e69cf
commit
c1bdab1926
29
main.c
29
main.c
|
@ -18,26 +18,33 @@ int main (int argc, char *argv[])
|
|||
|
||||
uint32_t in_888 = strtol(argv[1], NULL, 16);
|
||||
|
||||
printf(" Input, 24 bit color, 6 char hex: #%06X\n\n", in_888);
|
||||
printf(" Input, 24 bit color, 6 char hex: #%06X\n\n", in_888);
|
||||
|
||||
rgb888 split;
|
||||
split.r = ((in_888 & 0x00FF0000) >> 16) & 0xF0;
|
||||
split.g = ((in_888 & 0x0000FF00) >> 8) & 0xF0;
|
||||
split.b = (in_888 & 0x000000FF) & 0xF0;
|
||||
split.r = ((in_888 & 0x00FF0000) >> 16) & 0xF8;
|
||||
split.g = ((in_888 & 0x0000FF00) >> 8) & 0xF8;
|
||||
split.b = (in_888 & 0x000000FF) & 0xF8;
|
||||
|
||||
rgb888 unrounded;
|
||||
unrounded.r = split.r & 0xF0;
|
||||
unrounded.g = split.g & 0xF0;
|
||||
unrounded.b = split.b & 0xF0;
|
||||
|
||||
// Basic rounding
|
||||
rgb888 rounded;
|
||||
rounded.r = split.r | 8;
|
||||
rounded.g = split.g | 8;
|
||||
rounded.b = split.b | 8;
|
||||
rounded.r = unrounded.r | 8;
|
||||
rounded.g = unrounded.g | 8;
|
||||
rounded.b = unrounded.b | 8;
|
||||
|
||||
int16_t rgb555 = ((split.b & 0xF8) << 7) | ((split.g & 0xF8) << 2) | (split.r >> 3);
|
||||
int16_t rgb555_unrounded = ((unrounded.b & 0xF8) << 7) | ((unrounded.g & 0xF8) << 2) | (unrounded.r >> 3);
|
||||
int16_t rgb555_rounded = ((rounded.b & 0xF8) << 7) | ((rounded.g & 0xF8) << 2) | (rounded.r >> 3);
|
||||
|
||||
printf("Output, 15 bit color, 6 char hex, rounded down: #%06X\n", (uint32_t) ((split.r & 0xF8) << 16) | ((split.g & 0xF8) << 8) | (split.b & 0xF8));
|
||||
printf("Output, 15 bit color, 6 char hex, rounded up: #%06X\n", (uint32_t) ((rounded.r & 0xF8) << 16) | ((rounded.g & 0xF8) << 8) | (rounded.b & 0xF8));
|
||||
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 up: #%06X\n", (uint32_t) ((rounded.r & 0xF8) << 16) | ((rounded.g & 0xF8) << 8) | (rounded.b & 0xF8));
|
||||
|
||||
printf("Output, 15 bit color, 4 char hex, rounded down: 0x%04X\n", rgb555);
|
||||
printf("Output, 15 bit color, 4 char hex, rounded up: 0x%04X\n", rgb555_rounded);
|
||||
printf("Output, 15 bit color, 4 char hex, rounded down: 0x%04X\n", rgb555_unrounded);
|
||||
printf(" Output, 15 bit color, 4 char hex, unrounded: 0x%04X\n", rgb555);
|
||||
printf(" Output, 15 bit color, 4 char hex, rounded up: 0x%04X\n", rgb555_rounded);
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue