Index: daemon.c
===================================================================
--- daemon.c	(revision 18719)
+++ daemon.c	(working copy)
@@ -942,10 +942,22 @@
                 fprintf(stderr, "HTCP host name too long: %s\n", ini_htcpip);
                 exit(7);
             }
+
+            sprintf(buffer, "%s:format", name);
+            char *ini_format = iniparser_getstring(ini, buffer, (char *) "");
+	    int len = strlen(ini_format);
+            if (len >= 7) {
+                fprintf(stderr, "Format too long: %s\n", ini_format);
+                exit(7);
+            } else if (len == 0) {
+	    	ini_format = "png";
+	    }
+            
             strcpy(maps[iconf].xmlfile, ini_xmlpath);
             strcpy(maps[iconf].tile_dir, config.tile_dir);
             strcpy(maps[iconf].host, ini_hostname);
             strcpy(maps[iconf].htcpip, ini_htcpip);
+            strcpy(maps[iconf].format, ini_format);
         } else if (strncmp(name, "renderd", 7) == 0) {
             int render_sec = 0;
             if (sscanf(name, "renderd%i", &render_sec) != 1) {
Index: daemon.h
===================================================================
--- daemon.h	(revision 18719)
+++ daemon.h	(working copy)
@@ -27,6 +27,7 @@
     char host[PATH_MAX];
     char htcpip[PATH_MAX];
     char tile_dir[PATH_MAX];
+    char format[7];
 } xmlconfigitem;
 
 typedef struct {
Index: render_config.h
===================================================================
--- render_config.h	(revision 18719)
+++ render_config.h	(working copy)
@@ -1,14 +1,14 @@
 #ifndef RENDER_CONFIG_H
 #define RENDER_CONFIG_H
 
-#define MAX_ZOOM 18
+#define MAX_ZOOM 19
 
 // MAX_SIZE is the biggest file which we will return to the user
 #define MAX_SIZE (1 * 1024 * 1024)
 
 // With directory hashing enabled we rewrite the path so that tiles are really stored here instead
 #define DIRECTORY_HASH
-#define HASH_PATH "/var/lib/mod_tile"
+#define HASH_PATH "/tmp/var/tiles/metatiles"
 
 // TILE_PATH is where Openlayers with try to fetch the "z/x/y.png" tiles from
 // this is now only used if DIRECTORY_HASH is undefined
@@ -24,17 +24,17 @@
 #define MAX_LOAD_ANY 100
 
 // Location of osm.xml file
-#define RENDERD_CONFIG "/etc/renderd.conf"
+#define RENDERD_CONFIG "/home/skinkie/mod_tile/renderd.conf"
 // The XML configuration used if one is not provided
 #define XMLCONFIG_DEFAULT "default"
 // Maximum number of configurations that mod tile will allow
-#define XMLCONFIGS_MAX 10
+#define XMLCONFIGS_MAX 30
 
 // Mapnik input plugins (will need to adjust for 32 bit libs)
-#define MAPNIK_PLUGINS "/usr/local/lib64/mapnik/input"
+#define MAPNIK_PLUGINS "/usr/lib/mapnik/input"
 
 // Default directory to search for fonts. Recursion can be enabled if desired.
-#define FONT_DIR "/usr/local/lib64/mapnik/fonts"
+#define FONT_DIR "/usr/lib/mapnik/fonts"
 #define FONT_RECURSE 0
 
 // Typical interval between planet imports, used as basis for tile expiry times
@@ -55,7 +55,7 @@
 #define MAX_CONNECTIONS (2048)
 
 // default for number of rendering threads
-#define NUM_THREADS (4)
+#define NUM_THREADS (10)
 
 // Use this to enable meta-tiles which will render NxN tiles at once
 // Note: This should be a power of 2 (2, 4, 8, 16 ...)
Index: gen_tile.cpp
===================================================================
--- gen_tile.cpp	(revision 18719)
+++ gen_tile.cpp	(working copy)
@@ -41,12 +41,13 @@
 #endif
 
 static const int minZoom = 0;
-static const int maxZoom = 18;
+static const int maxZoom = 19;
 
 typedef struct {
     char xmlname[XMLCONFIG_MAX];
     char xmlfile[PATH_MAX];
     char tile_dir[PATH_MAX];
+    char format[7];
     Map map;
     projection prj;
     char xmluri[PATH_MAX];
@@ -61,7 +62,7 @@
     double *Ac, *Bc, *Cc, *zc;
 
     public:
-        SphericalProjection(int levels=18) {
+        SphericalProjection(int levels=19) {
             Ac = new double[levels];
             Bc = new double[levels];
             Cc = new double[levels];
@@ -314,6 +315,32 @@
             return (x & mask) * METATILE + (y & mask);
         }
 
+#define SAVE_IN_PIECES 1
+#ifdef SAVE_IN_PIECES
+	void save(const char *tile_dir)
+	{
+	    int ox, oy, limit;
+	    limit = (1 << z_);
+	    limit = MIN(limit, METATILE);
+
+	    // Write tiles
+            
+	    for (ox=0; ox < limit; ox++) {
+                for (oy=0; oy < limit; oy++) {
+		    std::stringstream ss;
+		    ss << std::string(tile_dir) << "/" << xmlconfig_.c_str() << "/" << z_ << "/" << (x_ + ox) << "/" << (y_ + oy) << ".png";
+		    std::string tmp(ss.str());
+
+		    syslog(LOG_DEBUG, "%s\n", tmp.c_str());
+		    mkdirp(tmp.c_str());
+
+		    std::ofstream file(tmp.c_str(), std::ios::out | std::ios::binary | std::ios::trunc);
+                    file.write((const char *)tile[ox][oy].data(), tile[ox][oy].size());
+		    file.close();
+                }
+            }
+	}
+#else
         void save(const char *tile_dir)
         {
             int ox, oy, limit;
@@ -369,6 +396,7 @@
             rename(tmp.c_str(), meta_path);
             //printf("Produced .meta: %s\n", meta_path);
         }
+#endif
 
 #ifdef HTCP_EXPIRE_CACHE
         void expire_tiles(int sock, char * host, char * uri) {
@@ -395,7 +423,7 @@
 };
 
 
-static enum protoCmd render(Map &m, char *xmlname, projection &prj, int x, int y, int z, unsigned int size, metaTile &tiles)
+static enum protoCmd render(Map &m, char *xmlname, char *format, projection &prj, int x, int y, int z, unsigned int size, metaTile &tiles)
 {
     int render_size = 256 * size;
     double p0x = x * 256;
@@ -426,7 +454,7 @@
     for (yy = 0; yy < size; yy++) {
         for (xx = 0; xx < size; xx++) {
             image_view<ImageData32> vw(xx * 256, yy * 256, 256, 256, buf.data());
-            tiles.set(xx, yy, save_to_string(vw, "png256"));
+            tiles.set(xx, yy, save_to_string(vw, format));
         }
     }
 //    std::cout << "DONE TILE " << xmlname << " " << z << " " << x << "-" << x+size-1 << " " << y << "-" << y+size-1 << "\n";
@@ -434,7 +462,7 @@
     return cmdDone; // OK
 }
 #else
-static enum protoCmd render(Map &m, const char *tile_dir, char *xmlname, projection &prj, int x, int y, int z)
+static enum protoCmd render(Map &m, const char *tile_dir, char *xmlname, char *format, projection &prj, int x, int y, int z)
 {
     char filename[PATH_MAX];
     char tmp[PATH_MAX];
@@ -465,7 +493,7 @@
 
     image_view<ImageData32> vw(128, 128, 256, 256, buf.data());
     //std::cout << "Render " << z << " " << x << " " << y << " " << filename << "\n";
-    save_to_file(vw, tmp, "png256");
+    save_to_file(vw, tmp, format);
     if (rename(tmp, filename)) {
         perror(tmp);
         return cmdNotDone;
@@ -493,6 +521,7 @@
         strcpy(maps[iMaxConfigs].xmlname, parentxmlconfig[iMaxConfigs].xmlname);
         strcpy(maps[iMaxConfigs].xmlfile, parentxmlconfig[iMaxConfigs].xmlfile);
         strcpy(maps[iMaxConfigs].tile_dir, parentxmlconfig[iMaxConfigs].tile_dir);
+        strcpy(maps[iMaxConfigs].format, parentxmlconfig[iMaxConfigs].format);
         maps[iMaxConfigs].map = Map(RENDER_SIZE, RENDER_SIZE);
         load_map(maps[iMaxConfigs].map, maps[iMaxConfigs].xmlfile);
         maps[iMaxConfigs].prj = projection(maps[iMaxConfigs].map.srs());
@@ -526,7 +555,7 @@
                 if (!strcmp(maps[i].xmlname, req->xmlname)) {
                     metaTile tiles(req->xmlname, item->mx, item->my, req->z);
 
-                    ret = render(maps[i].map, req->xmlname, maps[i].prj, item->mx, item->my, req->z, size, tiles);
+                    ret = render(maps[i].map, req->xmlname, maps[i].format, maps[i].prj, item->mx, item->my, req->z, size, tiles);
                     if (ret == cmdDone) {
                         tiles.save(maps[i].tile_dir);
 #ifdef HTCP_EXPIRE_CACHE
@@ -534,7 +563,7 @@
 #endif
                     }
 #else
-                    ret = render(maps[i].map, maps[i].tile_dir, req->xmlname, maps[i].prj, req->x, req->y, req->z);
+                    ret = render(maps[i].map, maps[i].tile_dir, req->xmlname, maps[i].format, maps[i].prj, req->x, req->y, req->z);
 #ifdef HTCP_EXPIRE_CACHE
                     cache_expire(maps[i].htcpsock,maps[i].host, maps[i].xmluri, req->x,req->y,req->z);
 #endif
