+/* Parse color information specified by KEY into {RED,GREEN,BLUE}.
+ Currently, the input string must be of the form "#RRRRGGGGBBBB"
+ Future implementations might allow things like "yellow" and
+ "sky-blue-ultra-brown"
+*/
+static void
+parse_color (struct output_driver *d, struct string_map *options,
+ const char *key, const char *default_value,
+ double *dred, double *dgreen, double *dblue)
+{
+ int red, green, blue;
+ char *string = parse_string (opt (d, options, key, default_value));
+
+ if (3 != sscanf (string, "#%04x%04x%04x", &red, &green, &blue))
+ {
+ /* If the parsed option string fails, then try the default value */
+ if ( 3 != sscanf (default_value, "#%04x%04x%04x", &red, &green, &blue))
+ {
+ /* ... and if that fails set everything to zero */
+ red = green = blue = 0;
+ }
+ }
+
+ /* Convert 16 bit ints to float */
+ *dred = red / (double) 0xFFFF;
+ *dgreen = green / (double) 0xFFFF;
+ *dblue = blue / (double) 0xFFFF;
+}
+