- if (gdk_pixmap_seek_string (infile, "XPM", FALSE) == TRUE)
- {
- if (gdk_pixmap_seek_char (infile,'{') == TRUE)
- {
- gdk_pixmap_seek_char (infile, '"');
- fseek (infile, -1, SEEK_CUR);
- gdk_pixmap_read_string (infile, &buffer, &buffer_size);
-
- sscanf (buffer,"%d %d %d %d", &width, &height, &num_cols, &cpp);
-
- colors = g_new(_GdkPixmapColor, num_cols);
-
- colormap = gdk_window_get_colormap (window);
- visual = gdk_window_get_visual (window);
-
- if (transparent_color == NULL)
- {
- gdk_color_white (colormap, &tmp_color);
- transparent_color = &tmp_color;
- }
-
- for (cnt = 0; cnt < num_cols; cnt++)
- {
- gdk_pixmap_seek_char (infile, '"');
- fseek (infile, -1, SEEK_CUR);
- gdk_pixmap_read_string (infile, &buffer, &buffer_size);
-
- colors[cnt].color_string = g_new(gchar, cpp + 1);
- for (n = 0; n < cpp; n++)
- colors[cnt].color_string[n] = buffer[n];
- colors[cnt].color_string[n] = 0;
- colors[cnt].transparent = FALSE;
-
- if (color_name != NULL)
- g_free (color_name);
-
- color_name = gdk_pixmap_extract_color (&buffer[cpp]);
-
- if (color_name != NULL)
- {
- if (gdk_color_parse (color_name, &colors[cnt].color) == FALSE)
- {
- colors[cnt].color = *transparent_color;
- colors[cnt].transparent = TRUE;
- }
- }
- else
- {
- colors[cnt].color = *transparent_color;
- colors[cnt].transparent = TRUE;
- }
-
- gdk_color_alloc (colormap, &colors[cnt].color);
- }
-
- index = 0;
- image = gdk_image_new (GDK_IMAGE_FASTEST, visual, width, height);
-
- gc = NULL;
- if (mask)
- {
- /* The pixmap mask is just a bits pattern.
- * Color 0 is used for background and 1 for foreground.
- * We don't care about the colormap, we just need 0 and 1.
- */
- GdkColor mask_pattern;
-
- *mask = gdk_pixmap_new (window, width, height, 1);
- gc = gdk_gc_new (*mask);
-
- mask_pattern.pixel = 0;
- gdk_gc_set_foreground (gc, &mask_pattern);
- gdk_draw_rectangle (*mask, gc, TRUE, 0, 0, -1, -1);
-
- mask_pattern.pixel = 1;
- gdk_gc_set_foreground (gc, &mask_pattern);
- }
-
- for (ycnt = 0; ycnt < height; ycnt++)
- {
- gdk_pixmap_read_string (infile, &buffer, &buffer_size);
-
- for (n = 0, cnt = 0, xcnt = 0; n < (width * cpp); n += cpp, xcnt++)
- {
- strncpy (pixel_str, &buffer[n], cpp);
- pixel_str[cpp] = 0;
- color = NULL;
- ns = 0;
-
- while (color == NULL)
- {
- if (strcmp (pixel_str, colors[ns].color_string) == 0)
- color = &colors[ns];
- else
- ns++;
- }
-
- gdk_image_put_pixel (image, xcnt, ycnt, color->color.pixel);
-
- if (mask && color->transparent)
- {
- if (cnt < xcnt)
- gdk_draw_line (*mask, gc, cnt, ycnt, xcnt - 1, ycnt);
- cnt = xcnt + 1;
- }
- }
-
- if (mask && (cnt < xcnt))
- gdk_draw_line (*mask, gc, cnt, ycnt, xcnt - 1, ycnt);
- }
-
- if (mask)
- gdk_gc_destroy (gc);
-
- pixmap = gdk_pixmap_new (window, width, height, visual->depth);
-
- gc = gdk_gc_new (pixmap);
- gdk_gc_set_foreground (gc, transparent_color);
- gdk_draw_image (pixmap, gc, image, 0, 0, 0, 0, image->width, image->height);
- gdk_gc_destroy (gc);
- gdk_image_destroy (image);
- }
- }
-
- fclose (infile);
- free (buffer);
-
- if (colors != NULL)
- {
- for (cnt = 0; cnt < num_cols; cnt++)
- g_free (colors[cnt].color_string);
- g_free (colors);
- }