]> granicus.if.org Git - graphviz/commitdiff
Support alpha in HSVA format.
authorEmden Gansner <erg@research.att.com>
Tue, 7 Aug 2012 14:53:44 +0000 (10:53 -0400)
committerEmden Gansner <erg@research.att.com>
Tue, 7 Aug 2012 14:53:44 +0000 (10:53 -0400)
lib/gvpr/actions.c

index 87649253d30083db1fe156d0024b88a925421f78..16e9d65afc639a44efc0f7e71785e5d2c95ae093 100644 (file)
@@ -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;