]> granicus.if.org Git - graphviz/commitdiff
trying for hsva set
authorellson <devnull@localhost>
Fri, 26 Sep 2008 14:58:17 +0000 (14:58 +0000)
committerellson <devnull@localhost>
Fri, 26 Sep 2008 14:58:17 +0000 (14:58 +0000)
lib/inkpot/inkpot.h
lib/inkpot/inkpot_scheme.c

index 3531e9e8b9f0d9ae625acddeebd06446eba17809..6076b3fb4c73f4d1271ae126555c65fb81a86ede 100644 (file)
@@ -56,6 +56,7 @@ extern inkpot_status_t inkpot_set           ( inkpot_t *inkpot, const char *color );
 extern inkpot_status_t inkpot_set_default     ( inkpot_t *inkpot );
 /* set inkpot color by value, which may or may not have a name in the current or any schemes */
 extern inkpot_status_t inkpot_set_rgba       ( inkpot_t *inkpot, double rgba[4] );
+extern inkpot_status_t inkpot_set_hsva       ( inkpot_t *inkpot, double hsva[4] );
 
 /* get inkpot color name in the translation scheme, or for colors without a name in the translated scheme,
  * set NULL and return INKPOT_COLOR_NONAME */
index 6f9ac465cd47267078c3fd44d388069b6cc595c4..6b79821726243e8c5fa47c3de45c0928580ebda1 100644 (file)
@@ -18,6 +18,7 @@
 #include <stdarg.h>
 #include <stdlib.h>
 #include <string.h>
+#include <ctype.h>
 #include <assert.h>
 
 #include "inkpot.h"
@@ -386,24 +387,78 @@ static inkpot_status_t inkpot_set_RGBA ( inkpot_t *inkpot, RGBA *rgba )
 #endif
 }
 
+inkpot_status_t inkpot_set_rgba ( inkpot_t *inkpot, double rgba[4] )
+{
+    unsigned int myrgba = 0, v;
+    int i;
+
+    for (i = 0; i < 4; i++) {
+       myrgba <<= SZB_RED;
+       v = rgba[i];
+       v = (v < 0.0) ? 0.0 : v;
+       v = (v > 1.0) ? 1.0 : v;
+       myrgba |= (int)(v * MAX_RED);
+    }
+
+    return inkpot_set_RGBA ( inkpot, &myrgba );
+}
+
+inkpot_status_t inkpot_set_hsva ( inkpot_t *inkpot, double hsva[4] )
+{
+    double rgba[4];
+
+    hsva2rgba( hsva, rgba );
+
+    return inkpot_set_rgba ( inkpot, rgba );
+}
+
 inkpot_status_t inkpot_set( inkpot_t *inkpot, const char *color )
 {
-    int index;
+    static char *canon;
+    static int allocated;
+    char *q, c;
+    const char *p;
+    int len, index;
     unsigned int rgba;
+    double hsva[4];
     inkpot_status_t rc = INKPOT_COLOR_UNKNOWN;
 
     if (!color)
         return ((inkpot->status = INKPOT_COLOR_UNKNOWN));
 
-    if (sscanf(color, "#%6x", &rgba)) {
-       rgba = (rgba << SZB_RED) | MAX_RED;
-       rc = inkpot_set_RGBA(inkpot, &rgba);
-    }
-
-    if (rc != INKPOT_SUCCESS)
+    if (*color == '#') {
         if (sscanf(color, "#%8x", &rgba))
            rc = inkpot_set_RGBA(inkpot, &rgba);
 
+        if (rc != INKPOT_SUCCESS) {
+            if (sscanf(color, "#%6x", &rgba)) {
+               rgba = (rgba << SZB_RED) | MAX_RED;
+               rc = inkpot_set_RGBA(inkpot, &rgba);
+            }
+       } 
+    }
+
+    if ((rc != INKPOT_SUCCESS) || ((c = *color) == '.') || isdigit(c)) {
+       len = strlen(color);
+       if (len >= allocated) {
+           allocated = len + 1 + 10;
+           canon = realloc(canon, allocated);
+           if (! canon)
+                return ((inkpot->status = INKPOT_MALLOC_FAIL));
+        }
+       p = color;
+        q = canon;
+        while ((c = *p++)) {
+           if (c == ',')
+               c = ' ';
+           *q++ = c;
+        }
+        *q = '\0';
+       hsva[3] = 1.0;
+        if (sscanf(canon, "%lf%lf%lf%lf", &hsva[0], &hsva[1], &hsva[2], &hsva[3]) >= 3)
+           rc = inkpot_set_hsva(inkpot, hsva);
+    }
+
     if (rc != INKPOT_SUCCESS)
         if (sscanf(color, "%d", &index) == 1)
             rc = inkpot_set_index(inkpot, index);
@@ -414,22 +469,6 @@ inkpot_status_t inkpot_set( inkpot_t *inkpot, const char *color )
     return rc;
 }
 
-inkpot_status_t inkpot_set_rgba ( inkpot_t *inkpot, double rgba[4] )
-{
-    unsigned int myrgba = 0, v;
-    int i;
-
-    for (i = 0; i < 4; i++) {
-       myrgba <<= SZB_RED;
-       v = rgba[i];
-       v = (v < 0.0) ? 0.0 : v;
-       v = (v > 1.0) ? 1.0 : v;
-       myrgba |= (int)(v * MAX_RED);
-    }
-
-    return inkpot_set_RGBA ( inkpot, &myrgba );
-}
-
 inkpot_status_t inkpot_get ( inkpot_t *inkpot, const char **color )
 {
     inkpot_name_t *out_name;