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

svn at osgeo.org svn at osgeo.org
Fri Aug 26 07:18:57 EDT 2011


Author: tbonfort
Date: 2011-08-26 04:18:57 -0700 (Fri, 26 Aug 2011)
New Revision: 12351

Modified:
   trunk/mapserver/mapcache/geocache.xml
   trunk/mapserver/mapcache/include/geocache.h
   trunk/mapserver/mapcache/src/configuration.c
   trunk/mapserver/mapcache/src/fastcgi_geocache.c
   trunk/mapserver/mapcache/src/image.c
   trunk/mapserver/mapcache/src/imageio.c
   trunk/mapserver/mapcache/src/imageio_png.c
   trunk/mapserver/mapcache/src/mod_geocache.c
   trunk/mapserver/mapcache/src/service_tms.c
   trunk/mapserver/mapcache/src/service_wmts.c
Log:
fix potential png corruption when quantizing images with many varying colors

closes issue 72
thomas.bonfort | 2011-04-20 10:00:32 +0200 (Wed, 20 Apr 2011)

Modified: trunk/mapserver/mapcache/geocache.xml
===================================================================
--- trunk/mapserver/mapcache/geocache.xml	2011-08-26 11:18:50 UTC (rev 12350)
+++ trunk/mapserver/mapcache/geocache.xml	2011-08-26 11:18:57 UTC (rev 12351)
@@ -203,6 +203,11 @@
       <compression>best</compression>
    </format>
 
+   <format name="mixed" type="MIXED">
+      <transparent>PNG_BEST</transparent>
+      <opaque>JPEG</opaque>
+   </format>
+
    <!--
    <source name="bluemarble" type="gdal">
       <data>/gro2/data/bluemarble/bluemarble.vrt</data>
@@ -274,7 +279,7 @@
          <params>
             <FORMAT>image/png</FORMAT>
             <LAYERS>default</LAYERS>
-            <MAP>/home/tbonfort/dev/mapserver-utils/osm-mapserver.map</MAP>
+            <MAP>/Users/tbonfort/dev/mapserver-utils/osm-mapserver.map</MAP>
          </params>
       </getmap>
    </source>
@@ -441,7 +446,7 @@
    <tileset name="test2">
       <source>nexrad</source>
       <cache>disk</cache>
-      <format>PNG</format>
+      <format>mixed</format>
       <grid>WGS84</grid>
    </tileset>
    <tileset name="test3">

Modified: trunk/mapserver/mapcache/include/geocache.h
===================================================================
--- trunk/mapserver/mapcache/include/geocache.h	2011-08-26 11:18:50 UTC (rev 12350)
+++ trunk/mapserver/mapcache/include/geocache.h	2011-08-26 11:18:57 UTC (rev 12351)
@@ -63,6 +63,7 @@
 
 
 typedef struct geocache_image_format geocache_image_format;
+typedef struct geocache_image_format_mixed geocache_image_format_mixed;
 typedef struct geocache_image_format_png geocache_image_format_png;
 typedef struct geocache_image_format_png_q geocache_image_format_png_q;
 typedef struct geocache_image_format_jpeg geocache_image_format_jpeg;
@@ -683,6 +684,13 @@
  * \returns GEOCACHE_FALSE if the image has more than one color
  */
 int geocache_image_blank_color(geocache_image* image);
+
+
+/**
+ * \brief check if image has some non opaque pixels
+ */
+int geocache_image_has_alpha(geocache_image *img);
+
 /** @} */
 
 
@@ -1158,6 +1166,16 @@
     geocache_compression_type compression_level; /**< PNG compression level to apply */
 };
 
+struct geocache_image_format_mixed {
+   geocache_image_format format;
+   geocache_image_format *transparent;
+   geocache_image_format *opaque;
+};
+
+
+geocache_image_format* geocache_imageio_create_mixed_format(apr_pool_t *pool,
+      char *name, geocache_image_format *transparent, geocache_image_format *opaque);
+
 /**\class geocache_image_format_png_q
  * \brief Quantized PNG format
  * \extends geocache_image_format_png
@@ -1232,10 +1250,6 @@
  */
 int geocache_imageio_is_valid_format(geocache_context *ctx, geocache_buffer *buffer);
 
-/**
- * \brief check if image has some non opaque pixels
- */
-int geocache_imageio_image_has_alpha(geocache_image *img);
 
 /**
  * decodes given buffer

Modified: trunk/mapserver/mapcache/src/configuration.c
===================================================================
--- trunk/mapserver/mapcache/src/configuration.c	2011-08-26 11:18:50 UTC (rev 12350)
+++ trunk/mapserver/mapcache/src/configuration.c	2011-08-26 11:18:57 UTC (rev 12351)
@@ -484,6 +484,25 @@
       }
       format = geocache_imageio_create_jpeg_format(ctx->pool,
             name,quality);
+   } else if(!strcmp(type,"MIXED")){
+      geocache_image_format *transparent=NULL, *opaque=NULL;
+      if ((cur_node = ezxml_child(node,"transparent")) != NULL) {
+         transparent = geocache_configuration_get_image_format(config,cur_node->txt);
+      }
+      if(!transparent) {
+         ctx->set_error(ctx,400, "mixed format %s references unknown transparent format %s"
+               "(order is important, format %s should appear first)",
+               name,cur_node->txt,cur_node->txt);
+      }
+      if ((cur_node = ezxml_child(node,"opaque")) != NULL) {
+         opaque = geocache_configuration_get_image_format(config,cur_node->txt);
+      }
+      if(!opaque) {
+         ctx->set_error(ctx,400, "mixed format %s references unknown opaque format %s"
+               "(order is important, format %s should appear first)",
+               name,cur_node->txt,cur_node->txt);
+      }
+      format = geocache_imageio_create_mixed_format(ctx->pool,name,transparent, opaque);
    } else {
       ctx->set_error(ctx, 400, "unknown format type %s for format \"%s\"", type, name);
       return;

Modified: trunk/mapserver/mapcache/src/fastcgi_geocache.c
===================================================================
--- trunk/mapserver/mapcache/src/fastcgi_geocache.c	2011-08-26 11:18:50 UTC (rev 12350)
+++ trunk/mapserver/mapcache/src/fastcgi_geocache.c	2011-08-26 11:18:57 UTC (rev 12351)
@@ -173,7 +173,7 @@
 
 static int geocache_fcgi_write_image_buffer(geocache_context_fcgi_request *ctx, geocache_buffer *im,
       geocache_image_format *format) {
-   if(format) {
+   if(format && format->mime_type) {
       if(!strcmp(format->extension,"png"))
          FCGX_FPrintF(ctx->out,"Content-type: image/png\r\n\r\n");
       else

Modified: trunk/mapserver/mapcache/src/image.c
===================================================================
--- trunk/mapserver/mapcache/src/image.c	2011-08-26 11:18:50 UTC (rev 12350)
+++ trunk/mapserver/mapcache/src/image.c	2011-08-26 11:18:57 UTC (rev 12351)
@@ -22,6 +22,21 @@
     return img;
 }
 
+int geocache_image_has_alpha(geocache_image *img) {
+   size_t i,j;
+   unsigned char *ptr, *rptr = img->data;
+   for(i=0;i<img->h;i++) {     
+      ptr = rptr;
+      for(j=0;j<img->w;j++) {
+         if(ptr[3]<(unsigned char)255)
+            return 1;
+         ptr += 4;
+      }
+      rptr += img->stride;
+   }
+   return 0;
+}
+
 void geocache_image_merge(geocache_context *ctx, geocache_image *base, geocache_image *overlay) {
    int i,j,starti,startj;
    unsigned char *browptr, *orowptr, *bptr, *optr;

Modified: trunk/mapserver/mapcache/src/imageio.c
===================================================================
--- trunk/mapserver/mapcache/src/imageio.c	2011-08-26 11:18:50 UTC (rev 12350)
+++ trunk/mapserver/mapcache/src/imageio.c	2011-08-26 11:18:57 UTC (rev 12351)
@@ -21,21 +21,6 @@
 /**\addtogroup imageio*/
 /** @{ */
 
-int geocache_imageio_image_has_alpha(geocache_image *img) {
-   size_t i,j;
-   unsigned char *ptr, *rptr = img->data;
-   for(i=0;i<img->h;i++) {     
-      ptr = rptr;
-      for(j=0;j<img->w;j++) {
-         if(ptr[3]<(unsigned char)255)
-            return 1;
-         ptr += 4;
-      }
-      rptr += img->stride;
-   }
-   return 0;
-}
-
 int geocache_imageio_is_valid_format(geocache_context *ctx, geocache_buffer *buffer) {
    geocache_image_format_type t = geocache_imageio_header_sniff(ctx,buffer);
    if(t==GC_PNG || t==GC_JPEG) {

Modified: trunk/mapserver/mapcache/src/imageio_png.c
===================================================================
--- trunk/mapserver/mapcache/src/imageio_png.c	2011-08-26 11:18:50 UTC (rev 12350)
+++ trunk/mapserver/mapcache/src/imageio_png.c	2011-08-26 11:18:57 UTC (rev 12351)
@@ -154,7 +154,7 @@
 
    png_set_write_fn(png_ptr, buffer, _geocache_imageio_png_write_func, _geocache_imageio_png_flush_func);
 
-   if(geocache_imageio_image_has_alpha(img))
+   if(geocache_image_has_alpha(img))
       color_type = PNG_COLOR_TYPE_RGB_ALPHA;
    else
       color_type = PNG_COLOR_TYPE_RGB;

Modified: trunk/mapserver/mapcache/src/mod_geocache.c
===================================================================
--- trunk/mapserver/mapcache/src/mod_geocache.c	2011-08-26 11:18:50 UTC (rev 12350)
+++ trunk/mapserver/mapcache/src/mod_geocache.c	2011-08-26 11:18:57 UTC (rev 12351)
@@ -174,7 +174,7 @@
    request_rec *r = ctx->request;
 
    ap_set_content_length(r,im->size);
-   if(format) {
+   if(format && format->mime_type) {
       ap_set_content_type(r, format->mime_type);
    } else {
       geocache_image_format_type t = geocache_imageio_header_sniff((geocache_context*)ctx,im);

Modified: trunk/mapserver/mapcache/src/service_tms.c
===================================================================
--- trunk/mapserver/mapcache/src/service_tms.c	2011-08-26 11:18:50 UTC (rev 12350)
+++ trunk/mapserver/mapcache/src/service_tms.c	2011-08-26 11:18:57 UTC (rev 12351)
@@ -106,7 +106,11 @@
          ezxml_t tileformat = ezxml_add_child(caps,"TileFormat",0);
          ezxml_set_attr(tileformat,"width",apr_psprintf(ctx->pool,"%d",grid->tile_sx));
          ezxml_set_attr(tileformat,"height",apr_psprintf(ctx->pool,"%d",grid->tile_sy));
-         ezxml_set_attr(tileformat,"mime-type",tileset->format->mime_type);
+         if(tileset->format->mime_type) {
+            ezxml_set_attr(tileformat,"mime-type",tileset->format->mime_type);
+         } else {
+            ezxml_set_attr(tileformat,"mime-type","image/unknown");
+         }
          ezxml_set_attr(tileformat,"extension",tileset->format->extension);
          
          ezxml_t tilesets = ezxml_add_child(caps,"TileSets",0);

Modified: trunk/mapserver/mapcache/src/service_wmts.c
===================================================================
--- trunk/mapserver/mapcache/src/service_wmts.c	2011-08-26 11:18:50 UTC (rev 12350)
+++ trunk/mapserver/mapcache/src/service_wmts.c	2011-08-26 11:18:57 UTC (rev 12351)
@@ -122,7 +122,10 @@
       ezxml_set_attr(style,"isDefault","true");
       ezxml_set_txt(ezxml_add_child(style,"ows:Identifier",0),"default");
       
-      ezxml_set_txt(ezxml_add_child(layer,"Format",0),tileset->format->mime_type);
+      if(tileset->format->mime_type)
+         ezxml_set_txt(ezxml_add_child(layer,"Format",0),tileset->format->mime_type);
+      else
+         ezxml_set_txt(ezxml_add_child(layer,"Format",0),"image/unknown");
    
 
       char *dimensionstemplate="";



More information about the mapserver-commits mailing list