Skip to content

Commit

Permalink
Added the possibility to provide ImageIO's output format in the TYPE …
Browse files Browse the repository at this point in the history
…string.

For instance:
TYPE=png image/png
TYPE=png image/png png256
TYPE=png image/png png24
TYPE=png image/png png

(closes openstreetmap#64)
  • Loading branch information
timautin committed Sep 25, 2018
1 parent e25bfdb commit f78436f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
1 change: 1 addition & 0 deletions includes/daemon.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ typedef struct {
char host[PATH_MAX];
char htcpip[PATH_MAX];
char tile_dir[PATH_MAX];
char output_format[INILINE_MAX];
char parameterization[PATH_MAX];
int tile_px_size;
double scale_factor;
Expand Down
18 changes: 17 additions & 1 deletion src/daemon.c
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,23 @@ int main(int argc, char **argv)
exit(7);
}
strcpy(maps[iconf].parameterization, ini_parameterize);



sprintf(buffer, "%s:type", name);
char *ini_type = iniparser_getstring(ini, buffer, "png image/png png256");

char* fileExtension[INILINE_MAX];
char* mimeType[INILINE_MAX];
char* outputFormat[INILINE_MAX];

strcpy(fileExtension, "png-default");
strcpy(mimeType, "image/png-default");
strcpy(outputFormat, "png256-default");

sscanf(ini_type, "%[^ ] %[^ ] %[^;#]", fileExtension, mimeType, outputFormat);

strcpy(maps[iconf].output_format, outputFormat);

/* Pass this information into the rendering threads,
* as it is needed to configure mapniks number of connections
*/
Expand Down
14 changes: 10 additions & 4 deletions src/gen_tile.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ struct projectionconfig {
struct xmlmapconfig {
char xmlname[XMLCONFIG_MAX];
char xmlfile[PATH_MAX];
char output_format[XMLCONFIG_MAX];
struct storage_backend * store;
Map map;
struct projectionconfig * prj;
Expand Down Expand Up @@ -274,13 +275,14 @@ static enum protoCmd render(struct xmlmapconfig * map, int x, int y, int z, char
#else
mapnik::image_view<mapnik::image_data_32> vw(xx * map->tilesize, yy * map->tilesize, map->tilesize, map->tilesize, buf.data());
#endif
tiles.set(xx, yy, save_to_string(vw, "png256"));
//tiles.set(xx, yy, save_to_string(vw, "png256"));
tiles.set(xx, yy, save_to_string(vw, map->output_format));
}
}
return cmdDone; // OK
}
#else //METATILE
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, projection &prj, int x, int y, int z, char* outputFormat)
{
char filename[PATH_MAX];
char tmp[PATH_MAX];
Expand Down Expand Up @@ -311,7 +313,10 @@ static enum protoCmd render(Map &m, const char *tile_dir, char *xmlname, project

mapnik::image_view<mapnik::image_data_32> vw(128, 128, 256, 256, buf.data());
//std::cout << "Render " << z << " " << x << " " << y << " " << filename << "\n";
mapnik::save_to_file(vw, tmp, "png256");

//mapnik::save_to_file(vw, tmp, "png256");
mapnik::save_to_file(vw, tmp, outputFormat);

if (rename(tmp, filename)) {
perror(tmp);
return cmdNotDone;
Expand Down Expand Up @@ -344,6 +349,7 @@ void *render_thread(void * arg)
if (parentxmlconfig[iMaxConfigs].xmlname[0] == 0 || parentxmlconfig[iMaxConfigs].xmlfile[0] == 0) break;
strcpy(maps[iMaxConfigs].xmlname, parentxmlconfig[iMaxConfigs].xmlname);
strcpy(maps[iMaxConfigs].xmlfile, parentxmlconfig[iMaxConfigs].xmlfile);
strcpy(maps[iMaxConfigs].output_format, parentxmlconfig[iMaxConfigs].output_format);
maps[iMaxConfigs].store = init_storage_backend(parentxmlconfig[iMaxConfigs].tile_dir);
maps[iMaxConfigs].tilesize = parentxmlconfig[iMaxConfigs].tile_px_size;
maps[iMaxConfigs].scale = parentxmlconfig[iMaxConfigs].scale_factor;
Expand Down Expand Up @@ -454,7 +460,7 @@ void *render_thread(void * arg)
}
}
#else //METATILE
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].prj, req->x, req->y, req->z, maps[i].output_format);
#ifdef HTCP_EXPIRE_CACHE
cache_expire(maps[i].htcpsock,maps[i].host, maps[i].xmluri, req->x,req->y,req->z);
#endif
Expand Down
4 changes: 3 additions & 1 deletion src/mod_tile.c
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -1762,6 +1762,7 @@ static const char *load_tile_config(cmd_parms *cmd, void *mconfig, const char *c
const char * result;
char fileExtension[INILINE_MAX];
char mimeType[INILINE_MAX];
char outputFormat[INILINE_MAX];
char * description = NULL;
char * attribution = NULL;
char * cors = NULL;
Expand Down Expand Up @@ -1823,6 +1824,7 @@ static const char *load_tile_config(cmd_parms *cmd, void *mconfig, const char *c
strcpy(url,"");
strcpy(fileExtension,"png");
strcpy(mimeType,"image/png");
strcpy(outputFormat,"png256");
description = NULL;
cors = NULL;
attribution = NULL;
Expand Down Expand Up @@ -1855,7 +1857,7 @@ static const char *load_tile_config(cmd_parms *cmd, void *mconfig, const char *c
fclose(hini);
return "TYPE too long";
}
if (sscanf(value, "%[^ ] %[^;#]", fileExtension, mimeType) != 2) {
if (sscanf(value, "%[^ ] %[^ ] %[^;#]", fileExtension, mimeType, outputFormat) < 2) {
if (description) {free(description); description = NULL;} if (attribution) {free(attribution); attribution = NULL;}
if (hostnames) {free(hostnames); hostnames = NULL;} if (cors) {free(cors); cors = NULL;}
if (tile_dir) {free(tile_dir); tile_dir = NULL; }
Expand Down

0 comments on commit f78436f

Please sign in to comment.