[mapserver-commits] r12697 - in trunk/mapserver/mapcache: include
src
svn at osgeo.org
svn at osgeo.org
Tue Oct 25 11:28:33 EDT 2011
Author: tbonfort
Date: 2011-10-25 08:28:33 -0700 (Tue, 25 Oct 2011)
New Revision: 12697
Modified:
trunk/mapserver/mapcache/include/mapcache.h
trunk/mapserver/mapcache/src/cache_disk.c
trunk/mapserver/mapcache/src/cache_memcache.c
trunk/mapserver/mapcache/src/cache_sqlite.c
trunk/mapserver/mapcache/src/cache_tiff.c
trunk/mapserver/mapcache/src/core.c
trunk/mapserver/mapcache/src/image.c
trunk/mapserver/mapcache/src/source_mapserver.c
trunk/mapserver/mapcache/src/source_wms.c
trunk/mapserver/mapcache/src/tileset.c
Log:
avoid some superfluous image compression/decompression steps in some cases
Modified: trunk/mapserver/mapcache/include/mapcache.h
===================================================================
--- trunk/mapserver/mapcache/include/mapcache.h 2011-10-25 15:26:54 UTC (rev 12696)
+++ trunk/mapserver/mapcache/include/mapcache.h 2011-10-25 15:28:33 UTC (rev 12697)
@@ -499,8 +499,8 @@
mapcache_tileset *tileset;
mapcache_grid_link *grid_link;
apr_table_t *dimensions;
- mapcache_buffer *data;
- mapcache_image *image;
+ mapcache_buffer *encoded_data;
+ mapcache_image *raw_image;
int width, height;
double extent[4];
apr_time_t mtime; /**< last modification time */
@@ -511,6 +511,7 @@
mapcache_map map;
int i,j;
char *format;
+ mapcache_buffer *data;
};
struct mapcache_request_get_feature_info {
@@ -1004,7 +1005,8 @@
* \sa mapcache_source::render_map()
* \sa mapcache_image_format
*/
- mapcache_buffer *data;
+ mapcache_buffer *encoded_data;
+ mapcache_image *raw_image;
apr_time_t mtime; /**< last modification time */
int expires; /**< time in seconds after which the tile should be rechecked for validity */
Modified: trunk/mapserver/mapcache/src/cache_disk.c
===================================================================
--- trunk/mapserver/mapcache/src/cache_disk.c 2011-10-25 15:26:54 UTC (rev 12696)
+++ trunk/mapserver/mapcache/src/cache_disk.c 2011-10-25 15:28:33 UTC (rev 12697)
@@ -232,7 +232,7 @@
* i.e. normally only once.
*/
tile->mtime = finfo.mtime;
- tile->data = mapcache_buffer_create(size,ctx->pool);
+ tile->encoded_data = mapcache_buffer_create(size,ctx->pool);
#ifndef NOMMAP
apr_mmap_t *tilemmap;
@@ -242,16 +242,16 @@
ctx->set_error(ctx, 500, "mmap error: %s",apr_strerror(rv,errmsg,120));
return MAPCACHE_FAILURE;
}
- tile->data->buf = tilemmap->mm;
- tile->data->size = tile->data->avail = finfo.size;
+ tile->encoded_data->buf = tilemmap->mm;
+ tile->encoded_data->size = tile->encoded_data->avail = finfo.size;
#else
//manually add the data to our buffer
- apr_file_read(f,(void*)tile->data->buf,&size);
- tile->data->size = size;
- tile->data->avail = size;
+ apr_file_read(f,(void*)tile->encoded_data->buf,&size);
+ tile->encoded_data->size = size;
+ tile->encoded_data->avail = size;
#endif
apr_file_close(f);
- if(tile->data->size != finfo.size) {
+ if(tile->encoded_data->size != finfo.size) {
ctx->set_error(ctx, 500, "failed to copy image data, got %d of %d bytes",(int)size, (int)finfo.size);
return MAPCACHE_FAILURE;
}
@@ -285,11 +285,16 @@
char *filename, *hackptr1, *hackptr2=NULL;
#ifdef DEBUG
/* all this should be checked at a higher level */
- if(!tile->data || !tile->data->size) {
+ if(!tile->encoded_data && !tile->raw_image) {
ctx->set_error(ctx,500,"attempting to write empty tile to disk");
return;
}
+ if(!tile->encoded_data && !tile->tileset->format) {
+ ctx->set_error(ctx,500,"received a raw tile image for a tileset with no format");
+ return;
+ }
#endif
+
_mapcache_cache_disk_tile_key(ctx, tile, &filename);
GC_CHECK_ERROR(ctx);
@@ -327,12 +332,18 @@
#ifdef HAVE_SYMLINK
if(((mapcache_cache_disk*)tile->tileset->cache)->symlink_blank) {
- mapcache_image *image = mapcache_imageio_decode(ctx, tile->data);
- GC_CHECK_ERROR(ctx);
- if(mapcache_image_blank_color(image) != MAPCACHE_FALSE) {
+ if(!tile->raw_image) {
+ tile->raw_image = mapcache_imageio_decode(ctx, tile->encoded_data);
+ GC_CHECK_ERROR(ctx);
+ }
+ if(mapcache_image_blank_color(tile->raw_image) != MAPCACHE_FALSE) {
char *blankname;
- _mapcache_cache_disk_blank_tile_key(ctx,tile,image->data,&blankname);
+ _mapcache_cache_disk_blank_tile_key(ctx,tile,tile->raw_image->data,&blankname);
if(apr_file_open(&f, blankname, APR_FOPEN_READ, APR_OS_DEFAULT, ctx->pool) != APR_SUCCESS) {
+ if(!tile->encoded_data) {
+ tile->encoded_data = tile->tileset->format->write(ctx, tile->raw_image, tile->tileset->format);
+ GC_CHECK_ERROR(ctx);
+ }
/* create the blank file */
char *blankdirname = apr_psprintf(ctx->pool, "%s/%s/%s/blanks",
((mapcache_cache_disk*)tile->tileset->cache)->base_directory,
@@ -359,16 +370,16 @@
return; /* we could not create the file */
}
- bytes = (apr_size_t)tile->data->size;
- ret = apr_file_write(f,(void*)tile->data->buf,&bytes);
+ bytes = (apr_size_t)tile->encoded_data->size;
+ ret = apr_file_write(f,(void*)tile->encoded_data->buf,&bytes);
if(ret != APR_SUCCESS) {
- ctx->set_error(ctx, 500, "failed to write data to file %s (wrote %d of %d bytes): %s",blankname, (int)bytes, (int)tile->data->size, apr_strerror(ret,errmsg,120));
+ ctx->set_error(ctx, 500, "failed to write data to file %s (wrote %d of %d bytes): %s",blankname, (int)bytes, (int)tile->encoded_data->size, apr_strerror(ret,errmsg,120));
mapcache_unlock_resource(ctx,blankname);
return; /* we could not create the file */
}
- if(bytes != tile->data->size) {
- ctx->set_error(ctx, 500, "failed to write image data to %s, wrote %d of %d bytes", blankname, (int)bytes, (int)tile->data->size);
+ if(bytes != tile->encoded_data->size) {
+ ctx->set_error(ctx, 500, "failed to write image data to %s, wrote %d of %d bytes", blankname, (int)bytes, (int)tile->encoded_data->size);
mapcache_unlock_resource(ctx,blankname);
return;
}
@@ -395,6 +406,12 @@
#endif /*HAVE_SYMLINK*/
/* go the normal way: either we haven't configured blank tile detection, or the tile was not blank */
+
+ if(!tile->encoded_data) {
+ tile->encoded_data = tile->tileset->format->write(ctx, tile->raw_image, tile->tileset->format);
+ GC_CHECK_ERROR(ctx);
+ }
+
if((ret = apr_file_open(&f, filename,
APR_FOPEN_CREATE|APR_FOPEN_WRITE|APR_FOPEN_BUFFERED|APR_FOPEN_BINARY,
APR_OS_DEFAULT, ctx->pool)) != APR_SUCCESS) {
@@ -402,15 +419,15 @@
return; /* we could not create the file */
}
- bytes = (apr_size_t)tile->data->size;
- ret = apr_file_write(f,(void*)tile->data->buf,&bytes);
+ bytes = (apr_size_t)tile->encoded_data->size;
+ ret = apr_file_write(f,(void*)tile->encoded_data->buf,&bytes);
if(ret != APR_SUCCESS) {
- ctx->set_error(ctx, 500, "failed to write data to file %s (wrote %d of %d bytes): %s",filename, (int)bytes, (int)tile->data->size, apr_strerror(ret,errmsg,120));
+ ctx->set_error(ctx, 500, "failed to write data to file %s (wrote %d of %d bytes): %s",filename, (int)bytes, (int)tile->encoded_data->size, apr_strerror(ret,errmsg,120));
return; /* we could not create the file */
}
- if(bytes != tile->data->size) {
- ctx->set_error(ctx, 500, "failed to write image data to %s, wrote %d of %d bytes", filename, (int)bytes, (int)tile->data->size);
+ if(bytes != tile->encoded_data->size) {
+ ctx->set_error(ctx, 500, "failed to write image data to %s, wrote %d of %d bytes", filename, (int)bytes, (int)tile->encoded_data->size);
}
ret = apr_file_close(f);
if(ret != APR_SUCCESS) {
Modified: trunk/mapserver/mapcache/src/cache_memcache.c
===================================================================
--- trunk/mapserver/mapcache/src/cache_memcache.c 2011-10-25 15:26:54 UTC (rev 12696)
+++ trunk/mapserver/mapcache/src/cache_memcache.c 2011-10-25 15:28:33 UTC (rev 12697)
@@ -123,23 +123,23 @@
if(GC_HAS_ERROR(ctx)) {
return MAPCACHE_FAILURE;
}
- tile->data = mapcache_buffer_create(0,ctx->pool);
- rv = apr_memcache_getp(cache->memcache,ctx->pool,key,(char**)&tile->data->buf,&tile->data->size,NULL);
+ tile->encoded_data = mapcache_buffer_create(0,ctx->pool);
+ rv = apr_memcache_getp(cache->memcache,ctx->pool,key,(char**)&tile->encoded_data->buf,&tile->encoded_data->size,NULL);
if(rv != APR_SUCCESS) {
return MAPCACHE_CACHE_MISS;
}
- if(tile->data->size == 0) {
+ if(tile->encoded_data->size == 0) {
ctx->set_error(ctx,500,"memcache cache returned 0-length data for tile %d %d %d\n",tile->x,tile->y,tile->z);
return MAPCACHE_FAILURE;
}
/* extract the tile modification time from the end of the data returned */
memcpy(
&tile->mtime,
- &(((char*)tile->data->buf)[tile->data->size-sizeof(apr_time_t)]),
+ &(((char*)tile->encoded_data->buf)[tile->encoded_data->size-sizeof(apr_time_t)]),
sizeof(apr_time_t));
- ((char*)tile->data->buf)[tile->data->size+sizeof(apr_time_t)]='\0';
- tile->data->avail = tile->data->size;
- tile->data->size -= sizeof(apr_time_t);
+ ((char*)tile->encoded_data->buf)[tile->encoded_data->size+sizeof(apr_time_t)]='\0';
+ tile->encoded_data->avail = tile->encoded_data->size;
+ tile->encoded_data->size -= sizeof(apr_time_t);
return MAPCACHE_SUCCESS;
}
@@ -162,16 +162,21 @@
mapcache_cache_memcache *cache = (mapcache_cache_memcache*)tile->tileset->cache;
_mapcache_cache_memcache_tile_key(ctx, tile, &key);
GC_CHECK_ERROR(ctx);
+
+ if(!tile->encoded_data) {
+ tile->encoded_data = tile->tileset->format->write(ctx, tile->raw_image, tile->tileset->format);
+ GC_CHECK_ERROR(ctx);
+ }
/* concatenate the current time to the end of the memcache data so we can extract it out
* when we re-get the tile */
- char *data = calloc(1,tile->data->size+sizeof(apr_time_t));
+ char *data = calloc(1,tile->encoded_data->size+sizeof(apr_time_t));
apr_time_t now = apr_time_now();
apr_pool_cleanup_register(ctx->pool, data, (void*)free, apr_pool_cleanup_null);
- memcpy(data,tile->data->buf,tile->data->size);
- memcpy(&(data[tile->data->size]),&now,sizeof(apr_time_t));
+ memcpy(data,tile->encoded_data->buf,tile->encoded_data->size);
+ memcpy(&(data[tile->encoded_data->size]),&now,sizeof(apr_time_t));
- rv = apr_memcache_set(cache->memcache,key,data,tile->data->size+sizeof(apr_time_t),expires,0);
+ rv = apr_memcache_set(cache->memcache,key,data,tile->encoded_data->size+sizeof(apr_time_t),expires,0);
if(rv != APR_SUCCESS) {
ctx->set_error(ctx,500,"failed to store tile %d %d %d to memcache cache %s",
tile->x,tile->y,tile->z,cache->cache.name);
Modified: trunk/mapserver/mapcache/src/cache_sqlite.c
===================================================================
--- trunk/mapserver/mapcache/src/cache_sqlite.c 2011-10-25 15:26:54 UTC (rev 12696)
+++ trunk/mapserver/mapcache/src/cache_sqlite.c 2011-10-25 15:28:33 UTC (rev 12697)
@@ -129,8 +129,12 @@
/* tile blob data */
paramidx = sqlite3_bind_parameter_index(stmt, ":data");
if(paramidx) {
- if(tile->data && tile->data->size) {
- sqlite3_bind_blob(stmt,paramidx,tile->data->buf, tile->data->size,SQLITE_STATIC);
+ if(!tile->encoded_data) {
+ tile->encoded_data = tile->tileset->format->write(ctx, tile->raw_image, tile->tileset->format);
+ GC_CHECK_ERROR(ctx);
+ }
+ if(tile->encoded_data && tile->encoded_data->size) {
+ sqlite3_bind_blob(stmt,paramidx,tile->encoded_data->buf, tile->encoded_data->size,SQLITE_STATIC);
} else {
sqlite3_bind_text(stmt,paramidx,"",-1,SQLITE_STATIC);
}
@@ -210,9 +214,9 @@
} else {
const void *blob = sqlite3_column_blob(stmt,0);
int size = sqlite3_column_bytes(stmt, 0);
- tile->data = mapcache_buffer_create(size,ctx->pool);
- memcpy(tile->data->buf, blob,size);
- tile->data->size = size;
+ tile->encoded_data = mapcache_buffer_create(size,ctx->pool);
+ memcpy(tile->encoded_data->buf, blob,size);
+ tile->encoded_data->size = size;
if(sqlite3_column_count(stmt) > 1) {
time_t mtime = sqlite3_column_int64(stmt, 1);
apr_time_ansi_put(&(tile->mtime),mtime);
Modified: trunk/mapserver/mapcache/src/cache_tiff.c
===================================================================
--- trunk/mapserver/mapcache/src/cache_tiff.c 2011-10-25 15:26:54 UTC (rev 12696)
+++ trunk/mapserver/mapcache/src/cache_tiff.c 2011-10-25 15:28:33 UTC (rev 12697)
@@ -406,16 +406,16 @@
void *bufptr;
/* create a memory buffer to contain the jpeg data */
- tile->data = mapcache_buffer_create((jpegtable_size+sizes[tiff_off]-4),ctx->pool);
+ tile->encoded_data = mapcache_buffer_create((jpegtable_size+sizes[tiff_off]-4),ctx->pool);
/*
* copy the jpeg header to the beginning of the memory buffer,
* omitting the last 2 bytes
*/
- memcpy(tile->data->buf,jpegtable_ptr,(jpegtable_size-2));
+ memcpy(tile->encoded_data->buf,jpegtable_ptr,(jpegtable_size-2));
/* advance the data pointer to after the header data */
- bufptr = tile->data->buf + (jpegtable_size-2);
+ bufptr = tile->encoded_data->buf + (jpegtable_size-2);
/* go to the specified offset in the tiff file, plus 2 bytes */
@@ -437,7 +437,7 @@
return MAPCACHE_FAILURE;
}
- tile->data->size = (jpegtable_size+sizes[tiff_off]-4);
+ tile->encoded_data->size = (jpegtable_size+sizes[tiff_off]-4);
/* finalize and cleanup */
apr_file_close(f);
@@ -529,15 +529,18 @@
int tilew = tile->grid_link->grid->tile_sx;
int tileh = tile->grid_link->grid->tile_sy;
- mapcache_image *tileimg = mapcache_imageio_decode(ctx, tile->data);
+ if(!tile->raw_image) {
+ tile->raw_image = mapcache_imageio_decode(ctx, tile->encoded_data);
+ GC_CHECK_ERROR(ctx);
+ }
/* remap xrgb to rgb */
unsigned char *rgb = (unsigned char*)malloc(tilew*tileh*3);
int r,c;
- for(r=0;r<tileimg->h;r++) {
- unsigned char *imptr = tileimg->data + r * tileimg->stride;
+ for(r=0;r<tile->raw_image->h;r++) {
+ unsigned char *imptr = tile->raw_image->data + r * tile->raw_image->stride;
unsigned char *rgbptr = rgb + r * tilew * 3;
- for(c=0;c<tileimg->w;c++) {
+ for(c=0;c<tile->raw_image->w;c++) {
rgbptr[0] = imptr[2];
rgbptr[1] = imptr[1];
rgbptr[2] = imptr[0];
Modified: trunk/mapserver/mapcache/src/core.c
===================================================================
--- trunk/mapserver/mapcache/src/core.c 2011-10-25 15:26:54 UTC (rev 12696)
+++ trunk/mapserver/mapcache/src/core.c 2011-10-25 15:28:33 UTC (rev 12697)
@@ -66,8 +66,11 @@
expires = tile->expires;
/* if we have multiple tiles to merge, decode the image data */
if(req_tile->ntiles>1) {
- base = mapcache_imageio_decode(ctx, tile->data);
- if(!base) return NULL;
+ if(!tile->raw_image) {
+ tile->raw_image = mapcache_imageio_decode(ctx, tile->encoded_data);
+ if(!tile->raw_image) return NULL;
+ }
+ base = tile->raw_image;
}
} else {
if(response->mtime < tile->mtime)
@@ -75,8 +78,11 @@
if(tile->expires < expires) {
expires = tile->expires;
}
- overlay = mapcache_imageio_decode(ctx, tile->data);
- if(!overlay) return NULL;
+ if(!tile->raw_image) {
+ tile->raw_image = mapcache_imageio_decode(ctx, tile->encoded_data);
+ if(!tile->raw_image) return NULL;
+ }
+ overlay = tile->raw_image;
mapcache_image_merge(ctx, base, overlay);
if(GC_HAS_ERROR(ctx)) {
return NULL;
@@ -101,7 +107,7 @@
return NULL;
}
} else {
- response->data = req_tile->tiles[0]->data;
+ response->data = req_tile->tiles[0]->encoded_data;
format = req_tile->tiles[0]->tileset->format;
}
@@ -132,7 +138,7 @@
-mapcache_image* _core_get_single_map(mapcache_context *ctx, mapcache_map *map, mapcache_resample_mode mode) {
+void _core_get_single_map(mapcache_context *ctx, mapcache_map *map, mapcache_resample_mode mode) {
mapcache_tile **maptiles;
int i,nmaptiles;
@@ -143,8 +149,7 @@
mapcache_tile *tile = maptiles[i];
tile->dimensions = map->dimensions;
mapcache_tileset_tile_get(ctx, tile);
- if(GC_HAS_ERROR(ctx))
- return NULL;
+ GC_CHECK_ERROR(ctx);
/* update the map modification time if it is older than the tile mtime */
if(tile->mtime>map->mtime) map->mtime = tile->mtime;
@@ -155,11 +160,10 @@
*/
if(!map->expires || tile->expires<map->expires) map->expires = tile->expires;
}
- mapcache_image *getmapim = mapcache_tileset_assemble_map_tiles(ctx,map->tileset,map->grid_link,
+ map->raw_image = mapcache_tileset_assemble_map_tiles(ctx,map->tileset,map->grid_link,
map->extent, map->width, map->height,
nmaptiles, maptiles,
mode);
- return getmapim;
}
mapcache_http_response *mapcache_core_get_map(mapcache_context *ctx, mapcache_request_get_map *req_map) {
@@ -180,19 +184,16 @@
mapcache_http_response *response = mapcache_http_response_create(ctx->pool);
mapcache_map *basemap = req_map->maps[0];
- /* raw image data. if left NULL, there is no need to reencode the image */
- mapcache_image *baseim = NULL;
-
int i;
char *timestr;
if(req_map->getmap_strategy == MAPCACHE_GETMAP_ASSEMBLE) {
- baseim = _core_get_single_map(ctx,basemap,req_map->resample_mode);
+ _core_get_single_map(ctx,basemap,req_map->resample_mode);
if(GC_HAS_ERROR(ctx)) return NULL;
for(i=1;i<req_map->nmaps;i++) {
mapcache_map *overlaymap = req_map->maps[i];
- mapcache_image *overlayim = _core_get_single_map(ctx,overlaymap,req_map->resample_mode);
+ _core_get_single_map(ctx,overlaymap,req_map->resample_mode);
if(GC_HAS_ERROR(ctx)) return NULL;
- mapcache_image_merge(ctx,baseim,overlayim);
+ mapcache_image_merge(ctx,basemap->raw_image,overlaymap->raw_image);
if(GC_HAS_ERROR(ctx)) return NULL;
if(overlaymap->mtime > basemap->mtime) basemap->mtime = overlaymap->mtime;
if(!basemap->expires || overlaymap->expires<basemap->expires) basemap->expires = overlaymap->expires;
@@ -209,30 +210,41 @@
basemap->tileset->source->render_map(ctx, basemap);
if(GC_HAS_ERROR(ctx)) return NULL;
if(req_map->nmaps>1) {
- baseim = mapcache_imageio_decode(ctx,basemap->data);
- if(GC_HAS_ERROR(ctx)) return NULL;
+ if(!basemap->raw_image) {
+ basemap->raw_image = mapcache_imageio_decode(ctx,basemap->encoded_data);
+ if(GC_HAS_ERROR(ctx)) return NULL;
+ }
for(i=1;i<req_map->nmaps;i++) {
mapcache_map *overlaymap = req_map->maps[i];
overlaymap->tileset->source->render_map(ctx, overlaymap);
if(GC_HAS_ERROR(ctx)) return NULL;
- mapcache_image *overlayim = mapcache_imageio_decode(ctx,overlaymap->data);
+ if(!overlaymap->raw_image) {
+ overlaymap->raw_image = mapcache_imageio_decode(ctx,overlaymap->encoded_data);
+ if(GC_HAS_ERROR(ctx)) return NULL;
+ }
if(GC_HAS_ERROR(ctx)) return NULL;
- mapcache_image_merge(ctx,baseim,overlayim);
+ mapcache_image_merge(ctx,basemap->raw_image,overlaymap->raw_image);
if(GC_HAS_ERROR(ctx)) return NULL;
if(!basemap->expires || overlaymap->expires<basemap->expires) basemap->expires = overlaymap->expires;
}
}
}
- if(baseim) {
+ if(basemap->raw_image) {
format = req_map->getmap_format; /* always defined, defaults to JPEG */
- response->data = format->write(ctx,baseim,format);
+ response->data = format->write(ctx,basemap->raw_image,format);
if(GC_HAS_ERROR(ctx)) {
return NULL;
}
} else {
/* this case happens when we have a forward strategy for a single tileset */
- response->data = basemap->data;
+#ifdef DEBUG
+ if(!basemap->encoded_data) {
+ ctx->set_error(ctx,500,"###BUG### core_get_map failed with null encoded_data");
+ return;
+ }
+#endif
+ response->data = basemap->encoded_data;
}
/* compute the content-type */
@@ -304,7 +316,7 @@
tileset->source->query_info(ctx,fi);
if(GC_HAS_ERROR(ctx)) return NULL;
mapcache_http_response *response = mapcache_http_response_create(ctx->pool);
- response->data = fi->map.data;
+ response->data = fi->data;
apr_table_set(response->headers,"Content-Type",fi->format);
return response;
} else {
Modified: trunk/mapserver/mapcache/src/image.c
===================================================================
--- trunk/mapserver/mapcache/src/image.c 2011-10-25 15:26:54 UTC (rev 12696)
+++ trunk/mapserver/mapcache/src/image.c 2011-10-25 15:28:33 UTC (rev 12697)
@@ -228,33 +228,33 @@
void mapcache_image_metatile_split(mapcache_context *ctx, mapcache_metatile *mt) {
if(mt->map.tileset->format) {
/* the tileset has a format defined, we will use it to encode the data */
- mapcache_image tileimg;
+ mapcache_image *tileimg;
mapcache_image *metatile;
int i,j;
int sx,sy;
- tileimg.w = mt->map.grid_link->grid->tile_sx;
- tileimg.h = mt->map.grid_link->grid->tile_sy;
- if(mt->map.image) {
- metatile = mt->map.image;
+ if(mt->map.raw_image) {
+ metatile = mt->map.raw_image;
} else {
- metatile = mapcache_imageio_decode(ctx, mt->map.data);
+ metatile = mapcache_imageio_decode(ctx, mt->map.encoded_data);
}
if(!metatile) {
ctx->set_error(ctx, 500, "failed to load image data from metatile");
return;
}
- tileimg.stride = metatile->stride;
for(i=0;i<mt->metasize_x;i++) {
for(j=0;j<mt->metasize_y;j++) {
- sx = mt->map.tileset->metabuffer + i * tileimg.w;
- sy = mt->map.height - (mt->map.tileset->metabuffer + (j+1) * tileimg.w);
- tileimg.data = &(metatile->data[sy*metatile->stride + 4 * sx]);
+ tileimg = (mapcache_image*)apr_pcalloc(ctx->pool,sizeof(mapcache_image));
+ tileimg->w = mt->map.grid_link->grid->tile_sx;
+ tileimg->h = mt->map.grid_link->grid->tile_sy;
+ tileimg->stride = metatile->stride;
+ sx = mt->map.tileset->metabuffer + i * tileimg->w;
+ sy = mt->map.height - (mt->map.tileset->metabuffer + (j+1) * tileimg->w);
+ tileimg->data = &(metatile->data[sy*metatile->stride + 4 * sx]);
if(mt->map.tileset->watermark) {
- mapcache_image_merge(ctx,&tileimg,mt->map.tileset->watermark);
+ mapcache_image_merge(ctx,tileimg,mt->map.tileset->watermark);
GC_CHECK_ERROR(ctx);
}
- mt->tiles[i*mt->metasize_y+j].data =
- mt->map.tileset->format->write(ctx, &tileimg, mt->map.tileset->format);
+ mt->tiles[i*mt->metasize_y+j].raw_image = tileimg;
GC_CHECK_ERROR(ctx);
}
}
@@ -263,12 +263,12 @@
if(mt->map.tileset->metasize_x != 1 ||
mt->map.tileset->metasize_y != 1 ||
mt->map.tileset->metabuffer != 0 ||
- !mt->map.data) {
+ !mt->map.encoded_data) {
ctx->set_error(ctx, 500, "##### BUG ##### using a metatile with no format");
return;
}
#endif
- mt->tiles[0].data = mt->map.data;
+ mt->tiles[0].encoded_data = mt->map.encoded_data;
}
}
Modified: trunk/mapserver/mapcache/src/source_mapserver.c
===================================================================
--- trunk/mapserver/mapcache/src/source_mapserver.c 2011-10-25 15:26:54 UTC (rev 12696)
+++ trunk/mapserver/mapcache/src/source_mapserver.c 2011-10-25 15:28:33 UTC (rev 12697)
@@ -119,13 +119,13 @@
return;
}
- map->image = mapcache_image_create(ctx);
- map->image->w = map->width;
- map->image->h = map->height;
- map->image->stride = 4 * map->width;
- map->image->data = malloc(map->width*map->height*4);
- memcpy(map->image->data,rb.data.rgba.pixels,map->width*map->height*4);
- apr_pool_cleanup_register(ctx->pool, map->image->data,(void*)free, apr_pool_cleanup_null);
+ map->raw_image = mapcache_image_create(ctx);
+ map->raw_image->w = map->width;
+ map->raw_image->h = map->height;
+ map->raw_image->stride = 4 * map->width;
+ map->raw_image->data = malloc(map->width*map->height*4);
+ memcpy(map->raw_image->data,rb.data.rgba.pixels,map->width*map->height*4);
+ apr_pool_cleanup_register(ctx->pool, map->raw_image->data,(void*)free, apr_pool_cleanup_null);
msFreeImage(image);
msFreeMap(omap);
Modified: trunk/mapserver/mapcache/src/source_wms.c
===================================================================
--- trunk/mapserver/mapcache/src/source_wms.c 2011-10-25 15:26:54 UTC (rev 12696)
+++ trunk/mapserver/mapcache/src/source_wms.c 2011-10-25 15:28:33 UTC (rev 12697)
@@ -57,12 +57,12 @@
}
}
- map->data = mapcache_buffer_create(30000,ctx->pool);
- mapcache_http_do_request_with_params(ctx,wms->http,params,map->data,NULL,NULL);
+ map->encoded_data = mapcache_buffer_create(30000,ctx->pool);
+ mapcache_http_do_request_with_params(ctx,wms->http,params,map->encoded_data,NULL,NULL);
GC_CHECK_ERROR(ctx);
- if(!mapcache_imageio_is_valid_format(ctx,map->data)) {
- char *returned_data = apr_pstrndup(ctx->pool,(char*)map->data->buf,map->data->size);
+ if(!mapcache_imageio_is_valid_format(ctx,map->encoded_data)) {
+ char *returned_data = apr_pstrndup(ctx->pool,(char*)map->encoded_data->buf,map->encoded_data->size);
ctx->set_error(ctx, 502, "wms request for tileset %s returned an unsupported format:\n%s",
map->tileset->name, returned_data);
}
@@ -95,8 +95,8 @@
}
- map->data = mapcache_buffer_create(30000,ctx->pool);
- mapcache_http_do_request_with_params(ctx,wms->http,params,map->data,NULL,NULL);
+ fi->data = mapcache_buffer_create(30000,ctx->pool);
+ mapcache_http_do_request_with_params(ctx,wms->http,params,fi->data,NULL,NULL);
GC_CHECK_ERROR(ctx);
}
Modified: trunk/mapserver/mapcache/src/tileset.c
===================================================================
--- trunk/mapserver/mapcache/src/tileset.c 2011-10-25 15:26:54 UTC (rev 12696)
+++ trunk/mapserver/mapcache/src/tileset.c 2011-10-25 15:28:33 UTC (rev 12697)
@@ -249,7 +249,18 @@
mapcache_image fakeimg;
fakeimg.stride = srcimage->stride;
fakeimg.data = &(srcimage->data[oy*srcimage->stride+ox*4]);
- mapcache_imageio_decode_to_image(ctx,tile->data,&fakeimg);
+ if(!tile->raw_image) {
+ mapcache_imageio_decode_to_image(ctx,tile->encoded_data,&fakeimg);
+ } else {
+ int r;
+ unsigned char *srcptr = tile->raw_image->data;
+ unsigned char *dstptr = fakeimg.data;
+ for(r=0;r<tile->raw_image->h;r++) {
+ memcpy(dstptr,srcptr,tile->raw_image->stride);
+ srcptr += tile->raw_image->stride;
+ dstptr += fakeimg.stride;
+ }
+ }
}
assert(toplefttile);
More information about the mapserver-commits
mailing list