+static NSColor *
+parse_color (const char *s)
+{
+ static const char hex[128] =
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0,
+ 0, 10,11,12,13,14,15,0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 10,11,12,13,14,15,0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+
+ unsigned char r=0, g=0, b=0;
+
+ if (!strcasecmp (s, "black")) ;
+ else if (!strcasecmp (s, "white")) r = g = b = 0xFF;
+ else if (!strcasecmp (s, "red")) r = 0xFF;
+ else if (!strcasecmp (s, "green")) g = 0xFF;
+ else if (!strcasecmp (s, "blue")) b = 0xFF;
+ else
+ {
+ if (*s != '#' || strlen(s) != 7)
+ {
+ fprintf (stderr, "%s: unparsable color: \"%s\"\n", progname, s);
+ exit (1);
+ }
+ s++;
+ r = (hex[(int) s[0]] << 4) | hex[(int) s[1]], s += 2;
+ g = (hex[(int) s[0]] << 4) | hex[(int) s[1]], s += 2;
+ b = (hex[(int) s[0]] << 4) | hex[(int) s[1]], s += 2;
+ }
+
+ return [NSColor colorWithRed: r / 255.0
+ green: g / 255.0
+ blue: b / 255.0
+ alpha: 1.0];
+}
+
+
+static void
+create (const char *color,
+ int w, int h,
+ const char *file)
+{
+ NSColor *c = parse_color (color);
+ NSImage *img = [[NSImage alloc] initWithSize:NSMakeSize(w, h)];
+ [img lockFocus];
+ [c drawSwatchInRect:NSMakeRect(0, 0, w, h)];
+ [img unlockFocus];
+ write_image (img, file);
+ [img release];
+}
+
+