- data->map = map;
- data->tile = tile;
- data->path = grits_wms_fetch(map->wms, tile, GRITS_ONCE, NULL, NULL);
+ data->map = map;
+ data->tile = tile;
+ data->pixels = gdk_pixbuf_get_pixels(pixbuf);
+ data->alpha = gdk_pixbuf_get_has_alpha(pixbuf);
+ data->width = gdk_pixbuf_get_width(pixbuf);
+ data->height = gdk_pixbuf_get_height(pixbuf);
+ data->pixels = g_memdup(data->pixels,
+ data->width * data->height * (data->alpha ? 4 : 3));
+ g_object_unref(pixbuf);
+
+ /* Map texture colors, if needed */
+ for (int i = 0; i < data->width * data->height; i++) {
+ for (int j = 0; j < G_N_ELEMENTS(colormap); j++) {
+ if (data->pixels[i*4+0] == colormap[j][0][0] &&
+ data->pixels[i*4+1] == colormap[j][0][1] &&
+ data->pixels[i*4+2] == colormap[j][0][2]) {
+ data->pixels[i*4+0] = colormap[j][1][0];
+ data->pixels[i*4+1] = colormap[j][1][1];
+ data->pixels[i*4+2] = colormap[j][1][2];
+ data->pixels[i*4+3] = colormap[j][1][3];
+ break;
+ }
+ }
+ }
+
+ /* Load the GL texture from the main thread */