]> Pileus Git - grits/commitdiff
Add color mapping to map plugin
authorAndy Spencer <andy753421@gmail.com>
Thu, 28 Jan 2010 09:43:28 +0000 (09:43 +0000)
committerAndy Spencer <andy753421@gmail.com>
Thu, 28 Jan 2010 09:55:22 +0000 (09:55 +0000)
TODO
src/plugins/map.c

diff --git a/TODO b/TODO
index aa098cae9176191fedef1c7a674083fcaa35a3c1..ad9a31fa08861d45fca338029800841112ba9327 100644 (file)
--- a/TODO
+++ b/TODO
@@ -33,7 +33,6 @@ sat:
 map:
        - Config panel
   - Use local rendering instead of pixmaps
-  - Color mapping for alpha/color values
 
 gps:
   - Create/test it
index 44bc9fc40ba6f9c63ca7f593ed401f239746bbcc..e30975f0df673348a89dba977324fcad7a0d18fb 100644 (file)
 #define TILE_WIDTH     1024
 #define TILE_HEIGHT    512
 
+const guchar colormap[][2][4] = {
+       {{0x73, 0x91, 0xad}, {0x73, 0x91, 0xad, 0x20}}, // Oceans
+       {{0xf6, 0xee, 0xee}, {0xf6, 0xee, 0xee, 0x00}}, // Ground
+       {{0xff, 0xff, 0xff}, {0xff, 0xff, 0xff, 0xff}}, // Borders
+       {{0x73, 0x93, 0xad}, {0x73, 0x93, 0xad, 0x40}}, // Lakes
+};
+
 struct _LoadTileData {
        GisPluginMap *self;
-       GisTile       *tile;
-       GdkPixbuf     *pixbuf;
+       GisTile      *tile;
+       GdkPixbuf    *pixbuf;
 };
+#include <stdlib.h>
 static gboolean _load_tile_cb(gpointer _data)
 {
        struct _LoadTileData *data = _data;
        GisPluginMap *self   = data->self;
-       GisTile       *tile   = data->tile;
-       GdkPixbuf     *pixbuf = data->pixbuf;
+       GisTile      *tile   = data->tile;
+       GdkPixbuf    *pixbuf = data->pixbuf;
        g_free(data);
 
        /* Create Texture */
@@ -47,6 +55,20 @@ static gboolean _load_tile_cb(gpointer _data)
        gint      width  = gdk_pixbuf_get_width(pixbuf);
        gint      height = gdk_pixbuf_get_height(pixbuf);
 
+       for (int i = 0; i < width*height; i++) {
+               for (int j = 0; j < G_N_ELEMENTS(colormap); j++) {
+                       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;
+                       }
+               }
+       }
+
        guint *tex = g_new0(guint, 1);
        gis_viewer_begin(self->viewer);
        glGenTextures(1, tex);
@@ -155,7 +177,7 @@ GisPluginMap *gis_plugin_map_new(GisViewer *viewer)
 
        /* Add renderers */
        GisCallback *callback = gis_callback_new(_expose, self);
-       gis_viewer_add(viewer, GIS_OBJECT(callback), GIS_LEVEL_WORLD, 0);
+       gis_viewer_add(viewer, GIS_OBJECT(callback), GIS_LEVEL_OVERLAY, 0);
 
        return self;
 }