- /* Load the image to a pixbuf */
- GError *error = NULL;
- conus->pixbuf = gdk_pixbuf_new_from_file(path, &error);
- g_free(path);
- if (!gdk_pixbuf_get_has_alpha(conus->pixbuf)) {
- GdkPixbuf *tmp = gdk_pixbuf_add_alpha(conus->pixbuf, TRUE, 0xff, 0xff, 0xff);
- g_object_unref(conus->pixbuf);
- conus->pixbuf = tmp;
- }
-
- /* Map the pixbuf's alpha values */
- const guchar colormap[][2][4] = {
- {{0x04, 0xe9, 0xe7}, {0x04, 0xe9, 0xe7, 0x30}},
- {{0x01, 0x9f, 0xf4}, {0x01, 0x9f, 0xf4, 0x60}},
- {{0x03, 0x00, 0xf4}, {0x03, 0x00, 0xf4, 0x90}},
- };
- guchar *pixels = gdk_pixbuf_get_pixels(conus->pixbuf);
- gint height = gdk_pixbuf_get_height(conus->pixbuf);
- gint width = gdk_pixbuf_get_width(conus->pixbuf);
- for (int i = 0; i < width*height; i++) {
- for (int j = 0; j < G_N_ELEMENTS(colormap); j++) {
- if (pixels[i*4+0] > 0xe0 &&
- pixels[i*4+1] > 0xe0 &&
- pixels[i*4+2] > 0xe0) {
- pixels[i*4+3] = 0x00;
- break;
- }
- if (pixels[i*4+0] == colormap[j][0][0] &&
- pixels[i*4+1] == colormap[j][0][1] &&
- pixels[i*4+2] == colormap[j][0][2]) {
- pixels[i*4+0] = colormap[j][1][0];
- pixels[i*4+1] = colormap[j][1][1];
- pixels[i*4+2] = colormap[j][1][2];
- pixels[i*4+3] = colormap[j][1][3];
- break;
- }
- }
- }
-