|
|
@ -6,6 +6,7 @@ |
|
|
|
//
|
|
|
|
|
|
|
|
#include "color.h" |
|
|
|
#include <stdlib.h> |
|
|
|
|
|
|
|
/*
|
|
|
|
* Consume whitespace. |
|
|
@ -234,6 +235,28 @@ rgba_create(uint32_t rgba) { |
|
|
|
return color; |
|
|
|
} |
|
|
|
|
|
|
|
/*
|
|
|
|
* Return a string representation of the color. |
|
|
|
*/ |
|
|
|
|
|
|
|
char * |
|
|
|
rgba_to_string(rgba_t rgba) { |
|
|
|
char *buf = (char *) malloc(64); |
|
|
|
if (1 == rgba.a) { |
|
|
|
sprintf(buf, "#%.2X%.2X%.2X" |
|
|
|
, (int) (rgba.r * 255) |
|
|
|
, (int) (rgba.g * 255) |
|
|
|
, (int) (rgba.b * 255)); |
|
|
|
} else { |
|
|
|
sprintf(buf, "rgba(%d, %d, %d, %.2f)" |
|
|
|
, (int) (rgba.r * 255) |
|
|
|
, (int) (rgba.g * 255) |
|
|
|
, (int) (rgba.b * 255) |
|
|
|
, rgba.a); |
|
|
|
} |
|
|
|
return buf; |
|
|
|
} |
|
|
|
|
|
|
|
/*
|
|
|
|
* Return rgba from (r,g,b,a). |
|
|
|
*/ |
|
|
|