Allow colors in the form #RRGGBB (ie w/o alpha).

This commit is contained in:
Timothy M. Schaeffer 2014-10-30 21:58:19 -04:00
parent e9cdee9701
commit f87c249d21

14
bar.c
View File

@ -1,4 +1,5 @@
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -168,7 +169,11 @@ parse_color (const char *str, char **end, const uint32_t def)
unsigned int g = (tmp&0x0000ff00) >> 8;
unsigned int b = (tmp&0x000000ff);
if (a) {
ptrdiff_t len = *end - str;
if (len == 8) {
if (a == 0) {
r = g = b = 0;
} else {
r = (r * 255) / a;
g = (g * 255) / a;
b = (b * 255) / a;
@ -177,10 +182,11 @@ parse_color (const char *str, char **end, const uint32_t def)
if (r > 255) r = 255;
if (g > 255) g = 255;
if (b > 255) b = 255;
} else
r = g = b = 0;
}
}
return a << 24 | r << 16 | g << 8 | b;
uint32_t c = a << 24 | r << 16 | g << 8 | b;
return c;
}
/* Actual color name, resolve it */