[mapserver-commits] r12429 - in trunk/mapserver/mapcache: include src

svn at osgeo.org svn at osgeo.org
Fri Aug 26 07:25:03 EDT 2011


Author: tbonfort
Date: 2011-08-26 04:25:03 -0700 (Fri, 26 Aug 2011)
New Revision: 12429

Modified:
   trunk/mapserver/mapcache/include/geocache.h
   trunk/mapserver/mapcache/src/image.c
   trunk/mapserver/mapcache/src/imageio.c
   trunk/mapserver/mapcache/src/imageio_jpeg.c
   trunk/mapserver/mapcache/src/imageio_png.c
   trunk/mapserver/mapcache/src/tileset.c
Log:
be a bit less verbose in sqlite3 detection
thomas.bonfort | 2011-08-15 15:03:04 +0200 (Mon, 15 Aug 2011)

Modified: trunk/mapserver/mapcache/include/geocache.h
===================================================================
--- trunk/mapserver/mapcache/include/geocache.h	2011-08-26 11:24:56 UTC (rev 12428)
+++ trunk/mapserver/mapcache/include/geocache.h	2011-08-26 11:25:03 UTC (rev 12429)
@@ -1249,7 +1249,15 @@
  */
 geocache_image* _geocache_imageio_png_decode(geocache_context *ctx, geocache_buffer *buffer);
 
+/**
+ * @param r
+ * @param buffer
+ * @return
+ */
+void _geocache_imageio_png_decode_to_image(geocache_context *ctx, geocache_buffer *buffer,
+      geocache_image *image);
 
+
 /**
  * \brief create a format capable of creating RGBA png
  * \memberof geocache_image_format_png
@@ -1295,6 +1303,14 @@
  */
 geocache_image* _geocache_imageio_jpeg_decode(geocache_context *ctx, geocache_buffer *buffer);
 
+/**
+ * @param r
+ * @param buffer
+ * @return
+ */
+void _geocache_imageio_jpeg_decode_to_image(geocache_context *ctx, geocache_buffer *buffer,
+      geocache_image *image);
+
 /** @} */
 
 /**
@@ -1313,7 +1329,12 @@
  */
 geocache_image* geocache_imageio_decode(geocache_context *ctx, geocache_buffer *buffer);
 
+/**
+ * decodes given buffer to an allocated image
+ */
+void geocache_imageio_decode_to_image(geocache_context *ctx, geocache_buffer *buffer, geocache_image *image);
 
+
 /** @} */
 
 typedef struct {

Modified: trunk/mapserver/mapcache/src/image.c
===================================================================
--- trunk/mapserver/mapcache/src/image.c	2011-08-26 11:24:56 UTC (rev 12428)
+++ trunk/mapserver/mapcache/src/image.c	2011-08-26 11:25:03 UTC (rev 12429)
@@ -19,6 +19,7 @@
 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;
+    img->data=NULL;
     return img;
 }
 

Modified: trunk/mapserver/mapcache/src/imageio.c
===================================================================
--- trunk/mapserver/mapcache/src/imageio.c	2011-08-26 11:24:56 UTC (rev 12428)
+++ trunk/mapserver/mapcache/src/imageio.c	2011-08-26 11:25:03 UTC (rev 12429)
@@ -57,6 +57,19 @@
    }
 }
 
+void geocache_imageio_decode_to_image(geocache_context *ctx, geocache_buffer *buffer,
+      geocache_image *image) {
+   geocache_image_format_type type = geocache_imageio_header_sniff(ctx,buffer);
+   if(type == GC_PNG) {
+      _geocache_imageio_png_decode_to_image(ctx,buffer,image);
+   } else if(type == GC_JPEG) {
+      _geocache_imageio_jpeg_decode_to_image(ctx,buffer,image);
+   } else {
+      ctx->set_error(ctx, 500, "geocache_imageio_decode: unrecognized image format");
+   }
+   return;
+}
+
 /** @} */
 
 /* vim: ai ts=3 sts=3 et sw=3

Modified: trunk/mapserver/mapcache/src/imageio_jpeg.c
===================================================================
--- trunk/mapserver/mapcache/src/imageio_jpeg.c	2011-08-26 11:24:56 UTC (rev 12428)
+++ trunk/mapserver/mapcache/src/imageio_jpeg.c	2011-08-26 11:25:03 UTC (rev 12429)
@@ -192,14 +192,15 @@
    return buffer;
 }
 
-geocache_image* _geocache_imageio_jpeg_decode(geocache_context *r, geocache_buffer *buffer) {
+void _geocache_imageio_jpeg_decode_to_image(geocache_context *r, geocache_buffer *buffer,
+      geocache_image *img) {
    struct jpeg_decompress_struct cinfo = {NULL};
    struct jpeg_error_mgr jerr;
    jpeg_create_decompress(&cinfo);
    cinfo.err = jpeg_std_error(&jerr);
-   geocache_image *img = geocache_image_create(r);
    if (_geocache_imageio_jpeg_mem_src(&cinfo,buffer->buf, buffer->size) != GEOCACHE_SUCCESS){
-      return NULL;
+      r->set_error(r,500,"failed to allocate jpeg decoding struct");
+      return;
    }
 
    jpeg_read_header(&cinfo, TRUE);
@@ -207,8 +208,11 @@
    img->w = cinfo.output_width;
    img->h = cinfo.output_height;
    int s = cinfo.output_components;
-   img->data = apr_pcalloc(r->pool,img->w*img->h*4*sizeof(unsigned char));
-   img->stride = img->w * 4;
+   if(!img->data) {
+      img->data = calloc(1,img->w*img->h*4*sizeof(unsigned char));
+      apr_pool_cleanup_register(r->pool, img->data, (void*)free, apr_pool_cleanup_null) ;
+      img->stride = img->w * 4;
+   }
 
    unsigned char *temp = apr_pcalloc(r->pool,img->w*s);
    while ((int)cinfo.output_scanline < img->h)
@@ -242,11 +246,19 @@
       {
          r->set_error(r, 500, "unsupported jpeg format");
          jpeg_destroy_decompress(&cinfo);
-         return NULL;
+         return;
       }
    }
    jpeg_finish_decompress(&cinfo);
    jpeg_destroy_decompress(&cinfo);
+}
+
+geocache_image* _geocache_imageio_jpeg_decode(geocache_context *r, geocache_buffer *buffer) {
+   geocache_image *img = geocache_image_create(r);
+   _geocache_imageio_jpeg_decode_to_image(r, buffer,img);
+   if(GC_HAS_ERROR(r)) {
+      return NULL;
+   }
    return img;
 
 }

Modified: trunk/mapserver/mapcache/src/imageio_png.c
===================================================================
--- trunk/mapserver/mapcache/src/imageio_png.c	2011-08-26 11:24:56 UTC (rev 12428)
+++ trunk/mapserver/mapcache/src/imageio_png.c	2011-08-26 11:25:03 UTC (rev 12429)
@@ -41,8 +41,8 @@
    // do nothing
 }
 
-geocache_image* _geocache_imageio_png_decode(geocache_context *ctx, geocache_buffer *buffer) {
-   geocache_image *img;
+void _geocache_imageio_png_decode_to_image(geocache_context *ctx, geocache_buffer *buffer,
+      geocache_image *img) {
    int bit_depth,color_type,i;
    unsigned char **row_pointers;
    png_structp png_ptr = NULL;
@@ -77,7 +77,6 @@
    png_set_read_fn(png_ptr,&b,_geocache_imageio_png_read_func);
 
    png_read_info(png_ptr,info_ptr);
-   img = geocache_image_create(ctx);
    if(!png_get_IHDR(png_ptr, info_ptr, &width, &height,&bit_depth, &color_type,NULL,NULL,NULL)) {
       ctx->set_error(ctx, 500, "failed to read png header");
       return NULL;
@@ -85,8 +84,11 @@
 
    img->w = width;
    img->h = height;
-   img->data = apr_pcalloc(ctx->pool,img->w*img->h*4*sizeof(unsigned char));
-   img->stride = img->w * 4;
+   if(!img->data) {
+      img->data = calloc(1,img->w*img->h*4*sizeof(unsigned char));
+      apr_pool_cleanup_register(ctx->pool, img->data, (void*)free, apr_pool_cleanup_null) ;
+      img->stride = img->w * 4;
+   }
    row_pointers = apr_pcalloc(ctx->pool,img->h * sizeof(unsigned char*));
 
    unsigned char *rowptr = img->data;
@@ -117,6 +119,15 @@
    return img;
 }
 
+   
+geocache_image* _geocache_imageio_png_decode(geocache_context *ctx, geocache_buffer *buffer) {
+   geocache_image *img = geocache_image_create(ctx);
+   _geocache_imageio_png_decode_to_image(ctx,buffer,img);
+   if(GC_HAS_ERROR(ctx))
+      return NULL;
+   return img;
+}
+
 /**
  * \brief encode an image to RGB(A) PNG format
  * \private \memberof geocache_image_format_png

Modified: trunk/mapserver/mapcache/src/tileset.c
===================================================================
--- trunk/mapserver/mapcache/src/tileset.c	2011-08-26 11:24:56 UTC (rev 12428)
+++ trunk/mapserver/mapcache/src/tileset.c	2011-08-26 11:25:03 UTC (rev 12429)
@@ -96,7 +96,8 @@
    image->w = width;
    image->h = height;
    image->stride = width*4;
-   image->data = apr_pcalloc(ctx->pool,width*height*4*sizeof(unsigned char));
+   image->data = calloc(1,width*height*4*sizeof(unsigned char));
+   apr_pool_cleanup_register(ctx->pool, image->data, (void*)free, apr_pool_cleanup_null) ;
    if(ntiles == 0) {
       return image;
    }
@@ -117,7 +118,8 @@
    srcimage->w = (Mx-mx+1)*tiles[0]->grid_link->grid->tile_sx;
    srcimage->h = (My-my+1)*tiles[0]->grid_link->grid->tile_sy;
    srcimage->stride = srcimage->w*4;
-   srcimage->data = apr_pcalloc(ctx->pool,srcimage->w*srcimage->h*4*sizeof(unsigned char));
+   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);
 
@@ -130,13 +132,10 @@
       int ox,oy; /* the offset from the start of the src image to the start of the tile */
       ox = (tile->x - mx) * tile->grid_link->grid->tile_sx;
       oy = (My - tile->y) * tile->grid_link->grid->tile_sy;
-      int row;
-      geocache_image *im = geocache_imageio_decode(ctx,tile->data);
-      for(row=0;row<tile->grid_link->grid->tile_sy;row++) {
-         unsigned char* dstrow = &(srcimage->data[(oy+row)*srcimage->stride+ox*4]);
-         unsigned char* srcrow = &(im->data[row*im->stride]);
-         memcpy(dstrow,srcrow,im->stride);
-      }
+      geocache_image fakeimg;
+      fakeimg.stride = srcimage->stride;
+      fakeimg.data = &(srcimage->data[oy*srcimage->stride+ox*4]);
+      geocache_imageio_decode_to_image(ctx,tile->data,&fakeimg);
    }
 
    assert(toplefttile);



More information about the mapserver-commits mailing list