From: Emden Gansner Date: Tue, 7 Aug 2012 14:53:44 +0000 (-0400) Subject: Support alpha in HSVA format. X-Git-Tag: LAST_LIBGRAPH~32^2~358^2~6 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c4205c6e132efe64f23211fe885ff37209bc6ac0;p=graphviz Support alpha in HSVA format. --- diff --git a/lib/gvpr/actions.c b/lib/gvpr/actions.c index 87649253d..16e9d65af 100644 --- a/lib/gvpr/actions.c +++ b/lib/gvpr/actions.c @@ -1120,6 +1120,7 @@ int colorxlate(char *str, gvcolor_t * color, color_type_t target_type) /* test for hsv value such as: ".6,.5,.3" */ if (((c = *p) == '.') || isdigit(c)) { + int cnt; len = strlen((char*)p); if (len >= allocated) { allocated = len + 1 + 10; @@ -1137,24 +1138,28 @@ int colorxlate(char *str, gvcolor_t * color, color_type_t target_type) } *q = '\0'; - if (sscanf((char *) canon, "%lf%lf%lf", &H, &S, &V) == 3) { + if ((cnt = sscanf((char *) canon, "%lf%lf%lf%lf", &H, &S, &V, &A)) >= 3) { /* clip to reasonable values */ H = MAX(MIN(H, 1.0), 0.0); S = MAX(MIN(S, 1.0), 0.0); V = MAX(MIN(V, 1.0), 0.0); + if (cnt == 4) + A = MAX(MIN(A, 1.0), 0.0); + else + A = 1.0; switch (target_type) { case HSVA_DOUBLE: color->u.HSVA[0] = H; color->u.HSVA[1] = S; color->u.HSVA[2] = V; - color->u.HSVA[3] = 1.0; /* opaque */ + color->u.HSVA[3] = A; break; case RGBA_BYTE: hsv2rgb(H, S, V, &R, &G, &B); color->u.rgba[0] = (int) (R * 255); color->u.rgba[1] = (int) (G * 255); color->u.rgba[2] = (int) (B * 255); - color->u.rgba[3] = 255; /* opaque */ + color->u.rgba[3] = (int) (A * 255); break; case CMYK_BYTE: hsv2rgb(H, S, V, &R, &G, &B); @@ -1169,14 +1174,14 @@ int colorxlate(char *str, gvcolor_t * color, color_type_t target_type) color->u.rrggbbaa[0] = (int) (R * 65535); color->u.rrggbbaa[1] = (int) (G * 65535); color->u.rrggbbaa[2] = (int) (B * 65535); - color->u.rrggbbaa[3] = 65535; /* opaque */ + color->u.rrggbbaa[3] = (int) (A * 65535); break; case RGBA_DOUBLE: hsv2rgb(H, S, V, &R, &G, &B); color->u.RGBA[0] = R; color->u.RGBA[1] = G; color->u.RGBA[2] = B; - color->u.RGBA[3] = 1.0; /* opaque */ + color->u.RGBA[3] = A; break; case COLOR_STRING: break;