[mapserver-dev] MapCache: improvements/changes

Daniele Debernardi daniele at geosar.ch
Fri Feb 1 08:58:22 PST 2013

after using the apache module mapCache, I had to do some changes to the 
code to fit best my needs.
I would like to share my considerations on some behavior:

1) when you request a tile outside the extension of the tileset, you get 
the error.
with the configuration of the errors as empty_img it returns an empty 
image but the http response code was annoying, so I changed it
to a response code of 200 and the browser will not log all the errors.
file lib/core.c around line ~600
   } else if(ctx->config && ctx->config->reporting == 
     response->data = ctx->config->empty_image;
     response->code = 200;    //set response code
     apr_table_set(response->headers, "Content-Type", 
     apr_table_set(response->headers, "X-Mapcache-Error", msg);
   } else if(ctx->config && ctx->config->reporting == 

2) configuring the mapcache with a jpeg output format, when I request a 
tile that is half-in and half-out the extension of
the tileset, the half-out image had a black background, as I use maps 
with a white background, I changed it using the alpha channel
to determine which part to change to white.
file lib/imageio_jpeg.c around line ~195
   rowdata = 
   for(row=0; row<img->h; row++) {
     JSAMPLE *pixptr = rowdata;
     int col;
     unsigned char *r,*g,*b,*alpha;
     alpha= &(img->data[3])+row*img->stride;
     for(col=0; col<img->w; col++) {
       if (*alpha == 255) {
         *(pixptr++) = *r;
         *(pixptr++) = *g;
         *(pixptr++) = *b;
       } else {
         *(pixptr++) = 255;
         *(pixptr++) = 255;
         *(pixptr++) = 255;
     (void) jpeg_write_scanlines(&cinfo, &rowdata, 1);


3) requesting images as png to maintain transparency, I had some trouble 
with the default image format which was JPEG,
this because in the code, the default format is get by dont know what 
and by default was jpeg.
I suggest to change it to take the default format specified in the 
mapcache xml configuration.
file lib/core.c around line ~400
   if(basemap->raw_image) {
     //remove this line and get image format from configuration xml
     //format = req_map->getmap_format; /* always defined, defaults to 

     format = ctx->config->default_image_format;

     response->data = format->write(ctx,basemap->raw_image,format);
     if(GC_HAS_ERROR(ctx)) {
       return NULL;
   } else {

I would like to know what you guys think of my changes.

Best regards,

More information about the mapserver-dev mailing list