[mapserver-commits] r12219 - in trunk/mapserver/mapcache: . include
src
svn at osgeo.org
svn at osgeo.org
Fri Aug 26 07:08:18 EDT 2011
Author: tbonfort
Date: 2011-08-26 04:08:18 -0700 (Fri, 26 Aug 2011)
New Revision: 12219
Modified:
trunk/mapserver/mapcache/geocache.xml
trunk/mapserver/mapcache/include/geocache.h
trunk/mapserver/mapcache/src/configuration.c
trunk/mapserver/mapcache/src/image.c
trunk/mapserver/mapcache/src/imageio_jpeg.c
trunk/mapserver/mapcache/src/imageio_png.c
Log:
stop using lockfiles for metatile locking, use posix semaphores
thomas.bonfort | 2011-01-08 12:03:31 +0100 (Sat, 08 Jan 2011)
Modified: trunk/mapserver/mapcache/geocache.xml
===================================================================
--- trunk/mapserver/mapcache/geocache.xml 2011-08-26 11:08:11 UTC (rev 12218)
+++ trunk/mapserver/mapcache/geocache.xml 2011-08-26 11:08:18 UTC (rev 12219)
@@ -67,8 +67,8 @@
<tileset name="test">
<source>vmap0</source>
<cache>disk</cache>
+ <watermark>/Users/tbonfort/Documents/terriscope/logo-watermark.png</watermark>
<grid>WGS84</grid>
- <format>PNG_BEST</format>
<expires>3600</expires>
</tileset>
<tileset name="test2">
@@ -90,6 +90,7 @@
<title>osm mapserver served map of midi-pyrénées</title>
<abstract>see http://mapserver-utils.googlecode.com</abstract>
</metadata>
+ <watermark>/Users/tbonfort/Documents/terriscope/logo-watermark.png</watermark>
<source>osm</source>
<cache>disk</cache>
<format>PNG</format>
Modified: trunk/mapserver/mapcache/include/geocache.h
===================================================================
--- trunk/mapserver/mapcache/include/geocache.h 2011-08-26 11:08:11 UTC (rev 12218)
+++ trunk/mapserver/mapcache/include/geocache.h 2011-08-26 11:08:18 UTC (rev 12219)
@@ -498,17 +498,32 @@
*/
#define GET_IMG_PIXEL(img,x,y) (&((img).data[(y)*(img).stride + (x)*4]))
+
/**
+ * \brief initialize a new geocache_image
+ */
+geocache_image* geocache_image_create(geocache_context *ctx);
+
+/**
\brief merge a set of tiles into a single image
\param tiles the list of tiles to merge
\param ntiles the number of tiles in the list of tiles
\param format the format to encode the resulting image
- \param r the context
+ \param ctx the context
\returns a new tile with the merged image
*/
geocache_tile* geocache_image_merge_tiles(geocache_context *ctx, geocache_image_format *format, geocache_tile **tiles, int ntiles);
/**
+ * \brief merge two images
+ * \param base the imae to merge onto
+ * \param overlay the image to overlay onto
+ * \param ctx the context
+ * when finished, base will be modified and have overlay merged onto it
+ */
+void geocache_image_merge(geocache_context *ctx, geocache_image *base, geocache_image *overlay);
+
+/**
* \brief split the given metatile into tiles
* \param mt the metatile to split
* \param r the context
@@ -749,6 +764,11 @@
* a list of parameters that can be forwarded from the client to the geocache_tileset::source
*/
apr_table_t *forwarded_params;
+
+ /**
+ * image to be used as a watermark
+ */
+ geocache_image *watermark;
/**
* handle to the configuration this tileset belongs to
Modified: trunk/mapserver/mapcache/src/configuration.c
===================================================================
--- trunk/mapserver/mapcache/src/configuration.c 2011-08-26 11:08:11 UTC (rev 12218)
+++ trunk/mapserver/mapcache/src/configuration.c 2011-08-26 11:08:18 UTC (rev 12219)
@@ -612,6 +612,42 @@
tileset->metasize_x = values[0];
tileset->metasize_y = values[1];
xmlFree(value);
+ } else if(!xmlStrcmp(cur_node->name, BAD_CAST "watermark")) {
+ value = (char*)xmlNodeGetContent(cur_node);
+ if(!value || !*value) {
+ ctx->set_error(ctx,GEOCACHE_PARSE_ERROR, "watermark config entry empty");
+ return;
+ }
+ apr_pool_t *tmppool;
+ apr_pool_create(&tmppool,ctx->pool);
+ apr_file_t *f;
+ apr_finfo_t finfo;
+ int rv;
+ if(apr_file_open(&f, value, APR_FOPEN_READ|APR_FOPEN_BUFFERED|APR_FOPEN_BINARY,
+ APR_OS_DEFAULT, tmppool) != APR_SUCCESS) {
+ ctx->set_error(ctx,GEOCACHE_DISK_ERROR, "failed to open watermark image %s",value);
+ return;
+ }
+ rv = apr_file_info_get(&finfo, APR_FINFO_SIZE, f);
+ if(!finfo.size) {
+ ctx->set_error(ctx, GEOCACHE_DISK_ERROR, "watermark %s has no data",value);
+ return;
+ }
+
+ geocache_buffer *watermarkdata = geocache_buffer_create(finfo.size,tmppool);
+ //manually add the data to our buffer
+ apr_size_t size;
+ apr_file_read(f,(void*)watermarkdata->buf,&size);
+ watermarkdata->size = size;
+ apr_file_close(f);
+ if(size != finfo.size) {
+ ctx->set_error(ctx, GEOCACHE_DISK_ERROR, "failed to copy watermark image data, got %d of %d bytes",(int)size, (int)finfo.size);
+ return;
+ }
+ tileset->watermark = geocache_imageio_decode(ctx,watermarkdata);
+ GC_CHECK_ERROR(ctx);
+ apr_pool_destroy(tmppool);
+ xmlFree(value);
} else if(!xmlStrcmp(cur_node->name, BAD_CAST "expires")) {
value = (char*)xmlNodeGetContent(cur_node);
char *endptr;
@@ -686,11 +722,30 @@
if(!tileset->format && (
tileset->metasize_x != 1 ||
tileset->metasize_y != 1 ||
- tileset->metabuffer != 0)) {
- tileset->format = config->merge_format;
+ tileset->metabuffer != 0 ||
+ tileset->watermark)) {
+ if(tileset->watermark) {
+ ctx->set_error(ctx,GEOCACHE_PARSE_ERROR,"tileset \"%s\" has no <format> configured, but it is needed for the watermark",
+ tileset->name);
+ return;
+ } else {
+ ctx->set_error(ctx,GEOCACHE_PARSE_ERROR,"tileset \"%s\" has no <format> configured, but it is needed for metatiling",
+ tileset->name);
+ return;
+ }
}
+ if(tileset->watermark) {
+ if(tileset->watermark->h != tileset->grid->tile_sy ||
+ tileset->watermark->w != tileset->grid->tile_sx) {
+ ctx->set_error(ctx,GEOCACHE_IMAGE_ERROR,"watermark size (%d,%d) does not match tile size (%d,%d)",
+ tileset->watermark->w, tileset->watermark->h,
+ tileset->grid->tile_sx, tileset->grid->tile_sx);
+ return;
+ }
+ }
+
geocache_configuration_add_tileset(config,tileset,name);
return;
}
Modified: trunk/mapserver/mapcache/src/image.c
===================================================================
--- trunk/mapserver/mapcache/src/image.c 2011-08-26 11:08:11 UTC (rev 12218)
+++ trunk/mapserver/mapcache/src/image.c 2011-08-26 11:08:18 UTC (rev 12219)
@@ -16,7 +16,13 @@
#include "geocache.h"
-void _geocache_image_merge(geocache_context *ctx, geocache_image *base, geocache_image *overlay) {
+geocache_image* geocache_image_create(geocache_context *ctx) {
+ geocache_image *img = (geocache_image*)apr_pcalloc(ctx->pool,sizeof(geocache_image));
+ img->w= img->h= 0;
+ return img;
+}
+
+void geocache_image_merge(geocache_context *ctx, geocache_image *base, geocache_image *overlay) {
int i,j;
unsigned char *browptr, *orowptr, *bptr, *optr;
if(base->w != overlay->w || base->h != overlay->h) {
@@ -73,7 +79,7 @@
if(tiles[i]->expires && ((tile->expires < tiles[i]->expires) || !tile->expires)) {
tile->expires = tiles[i]->expires;
}
- _geocache_image_merge(ctx, base, overlay);
+ geocache_image_merge(ctx, base, overlay);
if(GC_HAS_ERROR(ctx)) {
return NULL;
}
@@ -109,6 +115,10 @@
sx = mt->tile.tileset->metabuffer + i * tileimg.w;
sy = mt->tile.sy - (mt->tile.tileset->metabuffer + (j+1) * tileimg.w);
tileimg.data = &(metatile->data[sy*metatile->stride + 4 * sx]);
+ if(mt->tile.tileset->watermark) {
+ geocache_image_merge(ctx,&tileimg,mt->tile.tileset->watermark);
+ GC_CHECK_ERROR(ctx);
+ }
mt->tiles[i*mt->tile.tileset->metasize_x+j].data = mt->tile.tileset->format->write(ctx, &tileimg, mt->tile.tileset->format);
GC_CHECK_ERROR(ctx);
}
@@ -121,8 +131,8 @@
ctx->set_error(ctx, GEOCACHE_IMAGE_ERROR, "##### BUG ##### using a metatile with no format");
return;
}
+#endif
mt->tiles[0].data = mt->tile.data;
-#endif
}
}
Modified: trunk/mapserver/mapcache/src/imageio_jpeg.c
===================================================================
--- trunk/mapserver/mapcache/src/imageio_jpeg.c 2011-08-26 11:08:11 UTC (rev 12218)
+++ trunk/mapserver/mapcache/src/imageio_jpeg.c 2011-08-26 11:08:18 UTC (rev 12219)
@@ -198,7 +198,7 @@
struct jpeg_error_mgr jerr;
jpeg_create_decompress(&cinfo);
cinfo.err = jpeg_std_error(&jerr);
- geocache_image *img = apr_pcalloc(r->pool,sizeof(geocache_image));
+ geocache_image *img = geocache_image_create(r);
if (_geocache_imageio_jpeg_mem_src(&cinfo,buffer->buf, buffer->size) != GEOCACHE_SUCCESS){
return NULL;
}
Modified: trunk/mapserver/mapcache/src/imageio_png.c
===================================================================
--- trunk/mapserver/mapcache/src/imageio_png.c 2011-08-26 11:08:11 UTC (rev 12218)
+++ trunk/mapserver/mapcache/src/imageio_png.c 2011-08-26 11:08:18 UTC (rev 12219)
@@ -76,7 +76,7 @@
png_set_read_fn(png_ptr,&b,_geocache_imageio_png_read_func);
png_read_info(png_ptr,info_ptr);
- img = apr_pcalloc(ctx->pool,sizeof(geocache_image));
+ img = geocache_image_create(ctx);
if(!png_get_IHDR(png_ptr, info_ptr, &img->w, &img->h,&bit_depth, &color_type,NULL,NULL,NULL)) {
ctx->set_error(ctx, GEOCACHE_IMAGE_ERROR, "failed to read png header");
return NULL;
More information about the mapserver-commits
mailing list