Allow colors in the form #RRGGBB (ie w/o alpha).
This commit is contained in:
parent
e9cdee9701
commit
f87c249d21
28
bar.c
28
bar.c
|
@ -1,4 +1,5 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <stddef.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -168,19 +169,24 @@ parse_color (const char *str, char **end, const uint32_t def)
|
||||||
unsigned int g = (tmp&0x0000ff00) >> 8;
|
unsigned int g = (tmp&0x0000ff00) >> 8;
|
||||||
unsigned int b = (tmp&0x000000ff);
|
unsigned int b = (tmp&0x000000ff);
|
||||||
|
|
||||||
if (a) {
|
ptrdiff_t len = *end - str;
|
||||||
r = (r * 255) / a;
|
if (len == 8) {
|
||||||
g = (g * 255) / a;
|
if (a == 0) {
|
||||||
b = (b * 255) / a;
|
r = g = b = 0;
|
||||||
|
} else {
|
||||||
|
r = (r * 255) / a;
|
||||||
|
g = (g * 255) / a;
|
||||||
|
b = (b * 255) / a;
|
||||||
|
|
||||||
/* Clamp on overflow */
|
/* Clamp on overflow */
|
||||||
if (r > 255) r = 255;
|
if (r > 255) r = 255;
|
||||||
if (g > 255) g = 255;
|
if (g > 255) g = 255;
|
||||||
if (b > 255) b = 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 */
|
/* Actual color name, resolve it */
|
||||||
|
|
Loading…
Reference in New Issue
Block a user