[mapserver-commits] r12454 - in trunk/mapserver/mapcache: . include
src
svn at osgeo.org
svn at osgeo.org
Fri Aug 26 07:27:51 EDT 2011
Author: tbonfort
Date: 2011-08-26 04:27:51 -0700 (Fri, 26 Aug 2011)
New Revision: 12454
Modified:
trunk/mapserver/mapcache/INSTALL
trunk/mapserver/mapcache/Makefile.inc.in
trunk/mapserver/mapcache/configure.in
trunk/mapserver/mapcache/include/geocache.h
trunk/mapserver/mapcache/src/configuration_xml.c
trunk/mapserver/mapcache/src/core.c
trunk/mapserver/mapcache/src/image.c
trunk/mapserver/mapcache/src/tileset.c
Log:
Modified: trunk/mapserver/mapcache/INSTALL
===================================================================
--- trunk/mapserver/mapcache/INSTALL 2011-08-26 11:27:45 UTC (rev 12453)
+++ trunk/mapserver/mapcache/INSTALL 2011-08-26 11:27:51 UTC (rev 12454)
@@ -87,19 +87,6 @@
this is the path where the libjpeg headers and libs can be located.
the configure script will be looking for [path]/include/jpeg.h and [path]/lib/libjpeg.so
-cairo (optional)
-=================
-
---with-pkg-config=/path/to/pkg-config
---with-cairo=/path/to/cairo.pc
-
-cairo support is required if you want to enable full wms getmap support, i.e. reconstructing a full getmap request
-by assembling tiles next to one another.
-cairo configuration step requires the pkg-config utility.
-if your cairo libs and headers aren't in a default location, there's a chance they won't be picked up by the default
-pkg-config utility. In that case, you can use the --with-cairo=/path/to/cairo.pc to explicitely tell pkg-config
-where to find the configuration options for your version of cairo.
-
gdal (from 0.4 onwards) (optional)
===================================
Modified: trunk/mapserver/mapcache/Makefile.inc.in
===================================================================
--- trunk/mapserver/mapcache/Makefile.inc.in 2011-08-26 11:27:45 UTC (rev 12453)
+++ trunk/mapserver/mapcache/Makefile.inc.in 2011-08-26 11:27:51 UTC (rev 12454)
@@ -44,18 +44,14 @@
GEOS_LIB=@GEOS_LIB@
GEOS_ENABLED=@GEOS_ENABLED@
-CAIRO_INC=@CAIRO_INC@
-CAIRO_LIB=@CAIRO_LIB@
-CAIRO_ENABLED=@CAIRO_ENABLED@
-
SQLITE_INC=@SQLITE_INC@
SQLITE_LIB=@SQLITE_LIB@
SQLITE_ENABLED=@SQLITE_ENABLED@
MISC_ENABLED=@MISC_ENABLED@ -DTHREADED_MPM=$(shell $(HTTPD) -V | grep "Server MPM" | grep -q "Prefork"; echo $$?)
-INCLUDES=-I../include $(MISC_ENABLED) $(CAIRO_ENABLED) $(CAIRO_INC) $(CURL_CFLAGS) $(PNG_INC) $(JPEG_INC) $(GDAL_INC) $(GEOS_INC) $(APR_INC) $(APU_INC) $(MEMCACHE_ENABLED) $(PCRE_CFLAGS) $(PCRE_ENABLED) $(OGR_ENABLED) $(GEOS_ENABLED) $(SQLITE_ENABLED)
-LIBS=$(CURL_LIBS) $(CAIRO_LIB) $(PNG_LIB) $(JPEG_LIB) $(APR_LIBS) $(APU_LIBS) $(PCRE_LIBS) $(SQLITE_LIB)
+INCLUDES=-I../include $(MISC_ENABLED) $(CURL_CFLAGS) $(PNG_INC) $(JPEG_INC) $(GDAL_INC) $(GEOS_INC) $(APR_INC) $(APU_INC) $(MEMCACHE_ENABLED) $(PCRE_CFLAGS) $(PCRE_ENABLED) $(OGR_ENABLED) $(GEOS_ENABLED) $(SQLITE_ENABLED)
+LIBS=$(CURL_LIBS) $(PNG_LIB) $(JPEG_LIB) $(APR_LIBS) $(APU_LIBS) $(PCRE_LIBS) $(SQLITE_LIB)
SEEDER_EXTRALIBS=$(GDAL_LIB) $(GEOS_LIB)
Modified: trunk/mapserver/mapcache/configure.in
===================================================================
--- trunk/mapserver/mapcache/configure.in 2011-08-26 11:27:45 UTC (rev 12453)
+++ trunk/mapserver/mapcache/configure.in 2011-08-26 11:27:51 UTC (rev 12454)
@@ -711,7 +711,7 @@
APU_CHECK
SQLITE_CHECK
PKGCONFIG_CHECK
-CAIRO_CHECK
+# CAIRO_CHECK
PNG_CHECK
JPEG_CHECK
Modified: trunk/mapserver/mapcache/include/geocache.h
===================================================================
--- trunk/mapserver/mapcache/include/geocache.h 2011-08-26 11:27:45 UTC (rev 12453)
+++ trunk/mapserver/mapcache/include/geocache.h 2011-08-26 11:27:51 UTC (rev 12454)
@@ -742,6 +742,12 @@
*/
geocache_tile* geocache_image_merge_tiles(geocache_context *ctx, geocache_image_format *format, geocache_tile **tiles, int ntiles);
+void geocache_image_copy_resampled_nearest(geocache_context *ctx, geocache_image *src, geocache_image *dst,
+ double off_x, double off_y, double scale_x, double scale_y);
+void geocache_image_copy_resampled_bilinear(geocache_context *ctx, geocache_image *src, geocache_image *dst,
+ double off_x, double off_y, double scale_x, double scale_y);
+
+
/**
* \brief merge two images
* \param base the imae to merge onto
@@ -1075,13 +1081,11 @@
int *ntiles,
geocache_tile ***tiles);
-#ifdef USE_CAIRO
geocache_image* geocache_tileset_assemble_map_tiles(geocache_context *ctx, geocache_tileset *tileset,
geocache_grid_link *grid_link,
double *bbox, int width, int height,
int ntiles,
geocache_tile **tiles);
-#endif
/**
* compute x,y,z value given a bbox.
Modified: trunk/mapserver/mapcache/src/configuration_xml.c
===================================================================
--- trunk/mapserver/mapcache/src/configuration_xml.c 2011-08-26 11:27:45 UTC (rev 12453)
+++ trunk/mapserver/mapcache/src/configuration_xml.c 2011-08-26 11:27:51 UTC (rev 12454)
@@ -1094,11 +1094,7 @@
config->getmap_strategy = GEOCACHE_GETMAP_ERROR;
if ((node = ezxml_child(doc,"full_wms")) != NULL) {
if(!strcmp(node->txt,"assemble")) {
-#ifdef USE_CAIRO
config->getmap_strategy = GEOCACHE_GETMAP_ASSEMBLE;
-#else
- ctx->set_error(ctx,400, "\"assemble\" <full_wms> not supported with current build. reconfigure with --enable-cairo");
-#endif
} else if(!strcmp(node->txt,"forward")) {
config->getmap_strategy = GEOCACHE_GETMAP_FORWARD;
} else if(*node->txt && strcmp(node->txt,"error")) {
Modified: trunk/mapserver/mapcache/src/core.c
===================================================================
--- trunk/mapserver/mapcache/src/core.c 2011-08-26 11:27:45 UTC (rev 12453)
+++ trunk/mapserver/mapcache/src/core.c 2011-08-26 11:27:51 UTC (rev 12454)
@@ -46,7 +46,6 @@
return rettile;
}
-#ifdef USE_CAIRO
geocache_image* _core_get_single_map(geocache_context *ctx, geocache_map *map) {
geocache_tile **maptiles;
@@ -75,7 +74,6 @@
nmaptiles, maptiles);
return getmapim;
}
-#endif
geocache_map *geocache_core_get_map(geocache_context *ctx, geocache_request_get_map *req_map) {
#ifdef DEBUG
@@ -89,7 +87,6 @@
ctx->set_error(ctx, 404, "full wms support disabled");
return NULL;
} else if(ctx->config->getmap_strategy == GEOCACHE_GETMAP_ASSEMBLE) {
-#ifdef USE_CAIRO
int i;
geocache_map *basemap = req_map->maps[0];
geocache_image *baseim = _core_get_single_map(ctx,basemap);
@@ -107,10 +104,6 @@
basemap->data = basemap->tileset->format->write(ctx,baseim,basemap->tileset->format);
return basemap;
-#else
- ctx->set_error(ctx,501,"cairo not enabled: wms getmap handling by assembling tiles not configured in this build");
- return NULL;
-#endif
} else /*if(ctx->config->getmap_strategy == GEOCACHE_GETMAP_FORWARD)*/ {
int i;
geocache_map *basemap = req_map->maps[0];
Modified: trunk/mapserver/mapcache/src/image.c
===================================================================
--- trunk/mapserver/mapcache/src/image.c 2011-08-26 11:27:45 UTC (rev 12453)
+++ trunk/mapserver/mapcache/src/image.c 2011-08-26 11:27:51 UTC (rev 12454)
@@ -81,6 +81,79 @@
}
}
+#include <math.h>
+
+void geocache_image_copy_resampled_nearest(geocache_context *ctx, geocache_image *src, geocache_image *dst,
+ double off_x, double off_y, double scale_x, double scale_y) {
+ int dstx,dsty;
+ unsigned char *dstrowptr = dst->data;
+ for(dsty=0; dsty<dst->h; dsty++) {
+ int *dstptr = (int*)dstrowptr;
+ int srcy = round((dsty-off_y)/scale_y);
+ if(srcy >= 0 && srcy < src->h) {
+ for(dstx=0; dstx<dst->w;dstx++) {
+ int srcx = round((dstx-off_x)/scale_x);
+ if(srcx >= 0 && srcx < src->w) {
+ *dstptr = *((int*)&(src->data[srcy*src->stride+srcx*4]));
+ }
+ dstptr ++;
+ }
+ }
+ dstrowptr += dst->stride;
+ }
+}
+
+static inline void bilinear_pixel(geocache_image *img, double x, double y, unsigned char *dst) {
+ int px,py;
+ px = (int)x;
+ py = (int)y;
+
+ int px1 = (px==(img->w-1))?(px):(px+1);
+ int py1 = (py==(img->h-1))?(py):(py+1);
+
+ unsigned char *p1 = &img->data[py*img->stride+px*4];
+ unsigned char *p2 = &img->data[py*img->stride+px1*4];
+ unsigned char *p3 = &img->data[py1*img->stride+px*4];
+ unsigned char *p4 = &img->data[py1*img->stride+px1*4];
+
+ // Calculate the weights for each pixel
+ float fx = x - px;
+ float fy = y - py;
+ float fx1 = 1.0f - fx;
+ float fy1 = 1.0f - fy;
+
+ int w1 = fx1 * fy1 * 256.0f;
+ int w2 = fx * fy1 * 256.0f;
+ int w3 = fx1 * fy * 256.0f;
+ int w4 = fx * fy * 256.0f;
+
+ // Calculate the weighted sum of pixels (for each color channel)
+ dst[0] = (p1[0] * w1 + p2[0] * w2 + p3[0] * w3 + p4[0] * w4) >> 8;
+ dst[1] = (p1[1] * w1 + p2[1] * w2 + p3[1] * w3 + p4[1] * w4) >> 8;
+ dst[2] = (p1[2] * w1 + p2[2] * w2 + p3[2] * w3 + p4[2] * w4) >> 8;
+ dst[3] = (p1[3] * w1 + p2[3] * w2 + p3[3] * w3 + p4[3] * w4) >> 8;
+}
+
+void geocache_image_copy_resampled_bilinear(geocache_context *ctx, geocache_image *src, geocache_image *dst,
+ double off_x, double off_y, double scale_x, double scale_y) {
+ int dstx,dsty;
+ unsigned char *dstrowptr = dst->data;
+ for(dsty=0; dsty<dst->h; dsty++) {
+ unsigned char *dstptr = dstrowptr;
+ double srcy = (dsty-off_y)/scale_y;
+ if(srcy >= 0 && srcy < src->h) {
+ for(dstx=0; dstx<dst->w;dstx++) {
+ double srcx = (dstx-off_x)/scale_x;
+ if(srcx >= 0 && srcx < src->w) {
+ bilinear_pixel(src,srcx,srcy,dstptr);
+ }
+ dstptr += 4;
+ }
+ }
+ dstrowptr += dst->stride;
+ }
+}
+
geocache_tile* geocache_image_merge_tiles(geocache_context *ctx, geocache_image_format *format, geocache_tile **tiles, int ntiles) {
geocache_image *base,*overlay;
int i;
Modified: trunk/mapserver/mapcache/src/tileset.c
===================================================================
--- trunk/mapserver/mapcache/src/tileset.c 2011-08-26 11:27:45 UTC (rev 12453)
+++ trunk/mapserver/mapcache/src/tileset.c 2011-08-26 11:27:51 UTC (rev 12454)
@@ -76,11 +76,6 @@
*ntiles = i;
}
-#ifdef USE_CAIRO
-
-#include <cairo/cairo.h>
-#include <math.h>
-
geocache_image* geocache_tileset_assemble_map_tiles(geocache_context *ctx, geocache_tileset *tileset,
geocache_grid_link *grid_link,
double *bbox, int width, int height,
@@ -101,9 +96,6 @@
if(ntiles == 0) {
return image;
}
- cairo_surface_t* dstsurface= cairo_image_surface_create_for_data(image->data, CAIRO_FORMAT_ARGB32,
- width, height,image->stride);
- cairo_t *cr = cr = cairo_create (dstsurface);
/* compute the number of tiles horizontally and vertically */
for(i=0;i<ntiles;i++) {
@@ -120,8 +112,6 @@
srcimage->stride = srcimage->w*4;
srcimage->data = calloc(1,srcimage->w*srcimage->h*4*sizeof(unsigned char));
apr_pool_cleanup_register(ctx->pool, srcimage->data, (void*)free, apr_pool_cleanup_null) ;
- cairo_surface_t* srcsurface= cairo_image_surface_create_for_data(srcimage->data, CAIRO_FORMAT_ARGB32,
- srcimage->w, srcimage->h,srcimage->stride);
/* copy the tiles data into the src image */
for(i=0;i<ntiles;i++) {
@@ -150,31 +140,22 @@
double dstminy = (bbox[3]-tilebbox[3])/vresolution;
double hf = tileresolution/hresolution;
double vf = tileresolution/vresolution;
- cairo_translate (cr, dstminx,dstminy);
- cairo_scale (cr, hf, vf);
- cairo_set_source_surface (cr, srcsurface, 0, 0);
if(fabs(hf-1)<0.0001 && fabs(vf-1)<0.0001) {
//use nearest resampling if we are at the resolution of the tiles
- cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_NEAREST);
+ geocache_image_copy_resampled_nearest(ctx,srcimage,image,dstminx,dstminy,hf,vf);
} else {
switch(ctx->config->resample_mode) {
case GEOCACHE_RESAMPLE_BILINEAR:
- cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_BILINEAR);
+ geocache_image_copy_resampled_bilinear(ctx,srcimage,image,dstminx,dstminy,hf,vf);
break;
default:
- cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_NEAREST);
+ geocache_image_copy_resampled_nearest(ctx,srcimage,image,dstminx,dstminy,hf,vf);
break;
}
}
- cairo_paint (cr);
- cairo_surface_destroy(srcsurface);
- cairo_surface_destroy(dstsurface);
- cairo_destroy(cr);
return image;
}
-#endif
-
/*
* compute the metatile that should be rendered for the given tile
*/
More information about the mapserver-commits
mailing list