-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};
-
-static XImage *
-parse_xpm_data (Display *dpy, Visual *visual, Colormap colormap, int depth,
- unsigned long transparent_color,
- unsigned const char * const * data,
- int *width_ret, int *height_ret,
- unsigned long **pixels_ret, int *npixels_ret,
- unsigned char **mask_ret)
-{
- int w, w8, h, ncolors, nbytes;
- char c;
- int i;
- struct {
- char byte;
- int cr; int cg; int cb;
- int mr; int mg; int mb;
- } cmap[256];
- unsigned char rmap[256];
-
- unsigned long *pixels;
- XImage *ximage = 0;
-
- if (4 != sscanf ((const char *) *data,
- "%d %d %d %d %c", &w, &h, &ncolors, &nbytes, &c))
- abort();
- if (ncolors < 1 || ncolors > 255)
- abort();
- if (nbytes != 1)
- abort();
- data++;
-
- w8 = (w + 8) / 8;
-
- if (mask_ret)
- {
- int s = (w8 * h) + 1;
- *mask_ret = (unsigned char *) malloc (s);
- if (!*mask_ret)
- mask_ret = 0;
- else
- memset (*mask_ret, 255, s);
- }
-
- for (i = 0; i < ncolors; i++)
- {
- const unsigned char *line = *data;
- cmap[i].byte = *line++;
- while (*line)
- {
- int r, g, b;
- char which;
- while (*line == ' ' || *line == '\t')
- line++;
- which = *line++;
- if (which != 'c' && which != 'm')
- abort();
- while (*line == ' ' || *line == '\t')
- line++;
- if (!strncasecmp(line, "None", 4))
- {
- r = g = b = -1;
- line += 4;
- }
- else
- {
- if (*line == '#')
- line++;
- r = (hex[(int) line[0]] << 4) | hex[(int) line[1]]; line += 2;
- g = (hex[(int) line[0]] << 4) | hex[(int) line[1]]; line += 2;
- b = (hex[(int) line[0]] << 4) | hex[(int) line[1]]; line += 2;
- }
-
- if (which == 'c')
- {
- cmap[i].cr = r;
- cmap[i].cg = g;
- cmap[i].cb = b;
- }
- else
- {
- cmap[i].mr = r;
- cmap[i].mg = g;
- cmap[i].mb = b;
- }
- }
-
- data++;
- }
-
- if (depth == 1) transparent_color = 1;
-
- pixels = (unsigned long *) calloc (ncolors+1, sizeof(*pixels));
- for (i = 0; i < ncolors; i++)
- {
- if (cmap[i].cr == -1) /* transparent */
- {
- rmap[(int) cmap[i].byte] = 255;
- }
- else
- {
- XColor color;
- color.flags = DoRed|DoGreen|DoBlue;
- color.red = (cmap[i].cr << 8) | cmap[i].cr;
- color.green = (cmap[i].cg << 8) | cmap[i].cg;
- color.blue = (cmap[i].cb << 8) | cmap[i].cb;
- if (depth == 1 ||
- !XAllocColor (dpy, colormap, &color))
- {
- color.pixel = (cmap[i].mr ? 1 : 0);
- }
- pixels[i] = color.pixel;
- rmap[(int) cmap[i].byte] = i;
- }
- }
-
- ximage = XCreateImage (dpy, visual, depth,
- (depth == 1 ? XYBitmap : ZPixmap),
- 0, 0, w, h, 8, 0);
- if (ximage)
- {
- int x, y;
- ximage->data = (char *)
- calloc ( ximage->height, ximage->bytes_per_line);
- for (y = 0; y < h; y++)
- {
- const unsigned char *line = *data++;
- for (x = 0; x < w; x++)
- {
- int p = rmap[*line++];
- XPutPixel (ximage, x, y,
- (p == 255 ? transparent_color : pixels[p]));
-
- if (p == 255 && mask_ret)
- (*mask_ret)[(y * w8) + (x >> 3)] &= (~(1 << (x % 8)));
- }
- }
- }
-
- *width_ret = w;
- *height_ret = h;
- *pixels_ret = pixels;
- *npixels_ret = ncolors;
- return ximage;
-}
-
-
-
-/* Draws the logo centered in the given Drawable (presumably a Pixmap.)
- next_frame_p means randomize the flame shape.