35static void hsv2rgb(
double h,
double s,
double v,
36 double *r,
double *g,
double *b)
53 t = v * (1 -
s * (1 - f));
91static void rgb2hsv(
double r,
double g,
double b,
92 double *h,
double *
s,
double *v)
95 double rgbmin, rgbmax;
97 double ht = 0.0, st = 0.0;
99 rgbmin = fmin(r, fmin(g, b));
100 rgbmax = fmax(r, fmax(g, b));
103 st = (rgbmax - rgbmin) / rgbmax;
106 rc = (rgbmax - r) / (rgbmax - rgbmin);
107 gc = (rgbmax - g) / (rgbmax - rgbmin);
108 bc = (rgbmax - b) / (rgbmax - rgbmin);
181#define DFLT_SCHEME "X11/"
182#define DFLT_SCHEME_LEN ((sizeof(DFLT_SCHEME)-1)/sizeof(char))
183#define ISNONDFLT(s) ((s) && *(s) && strncasecmp(DFLT_SCHEME, s, DFLT_SCHEME_LEN-1))
191 if (!strcmp(
str,
"black"))
return strdup(
str);
192 if (!strcmp(
str,
"white"))
return strdup(
str);
193 if (!strcmp(
str,
"lightgrey"))
return strdup(
str);
197 if ((ss = strchr(c2,
'/'))) {
222 double H,
S,
V,
A, R,
G,
B;
223 unsigned int r, g, b, a;
226 color->type = target_type;
229 for (; *
str ==
' ';
str++);
235 bool is_rgb = *p ==
'#' && sscanf(p,
"#%2x%2x%2x%2x", &r, &g, &b, &a) >= 3;
237 is_rgb = *p ==
'#' && strlen(p) == 4 && sscanf(p,
"#%1x%1x%1x", &r, &g, &b) == 3;
245 switch (target_type) {
247 R = (double) r / 255.0;
248 G = (double) g / 255.0;
249 B = (double) b / 255.0;
250 A = (double) a / 255.0;
252 color->u.HSVA[0] = H;
258 color->u.rgba[0] = (
unsigned char)r;
259 color->u.rgba[1] = (
unsigned char)g;
260 color->u.rgba[2] = (
unsigned char)b;
261 color->u.rgba[3] = (
unsigned char)a;
264 color->u.rrggbbaa[0] = (int)(r * 65535 / 255);
265 color->u.rrggbbaa[1] = (int)(g * 65535 / 255);
266 color->u.rrggbbaa[2] = (int)(b * 65535 / 255);
267 color->u.rrggbbaa[3] = (int)(a * 65535 / 255);
270 color->u.RGBA[0] = (double) r / 255.0;
271 color->u.RGBA[1] = (double) g / 255.0;
272 color->u.RGBA[2] = (double) b / 255.0;
273 color->u.RGBA[3] = (double) a / 255.0;
295 H = fmax(fmin(H, 1.0), 0.0);
296 S = fmax(fmin(
S, 1.0), 0.0);
297 V = fmax(fmin(
V, 1.0), 0.0);
298 A = fmax(fmin(
A, 1.0), 0.0);
299 switch (target_type) {
301 color->u.HSVA[0] = H;
308 color->u.rgba[0] = (
unsigned char)(R * 255);
309 color->u.rgba[1] = (
unsigned char)(
G * 255);
310 color->u.rgba[2] = (
unsigned char)(
B * 255);
311 color->u.rgba[3] = (
unsigned char)(
A * 255);
315 color->u.rrggbbaa[0] = (int) (R * 65535);
316 color->u.rrggbbaa[1] = (int) (
G * 65535);
317 color->u.rrggbbaa[2] = (int) (
B * 65535);
318 color->u.rrggbbaa[3] = (int) (
A * 65535);
322 color->u.RGBA[0] = R;
350 switch (target_type) {
352 color->u.HSVA[0] = ((double)
last->h) / 255.0;
353 color->u.HSVA[1] = ((double)
last->
s) / 255.0;
354 color->u.HSVA[2] = ((double)
last->v) / 255.0;
355 color->u.HSVA[3] = ((double)
last->a) / 255.0;
387 switch (target_type) {
390 color->u.HSVA[3] = 1.0;
394 color->u.rgba[3] = 255;
397 color->u.rrggbbaa[0] =
color->u.rrggbbaa[1] =
color->u.rrggbbaa[2] = 0;
398 color->u.rrggbbaa[3] = 65535;
402 color->u.RGBA[3] = 1.0;
static agxbuf last
last message
static void agxbfree(agxbuf *xb)
free any malloced resources
static int agxbprint(agxbuf *xb, const char *fmt,...)
Printf-style output to an agxbuf.
static int agxbputc(agxbuf *xb, char c)
add character to buffer
static char * agxbuse(agxbuf *xb)
static char * agxbdisown(agxbuf *xb)
Memory allocation wrappers that exit on failure.
static char * gv_strdup(const char *original)
#define COLOR_MALLOC_FAIL
require define api prefix
replacements for ctype.h functions
static char gv_tolower(int c)
static bool gv_isdigit(int c)
Arithmetic helper functions.
static bool is_exactly_equal(double a, double b)
are two values precisely the same?
static void color(Agraph_t *g)
static char * fullColor(agxbuf *xb, const char *prefix, const char *str)
static void hsv2rgb(double h, double s, double v, double *r, double *g, double *b)
char * canontoken(char *str)
char * setColorScheme(const char *s)
static void rgb2hsv(double r, double g, double b, double *h, double *s, double *v)
static char * resolveColor(char *str)
static char * colorscheme
static bool on_heap(const subtree_t *tree)
is this subtree stored in an STheap?
static char * canon(graph_t *g, char *s)
platform abstraction for case-insensitive string functions
struct agxbuf::@59::@60 s