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

svn at osgeo.org svn at osgeo.org
Sun Oct 16 08:27:47 EDT 2011


Author: tbonfort
Date: 2011-10-16 05:27:47 -0700 (Sun, 16 Oct 2011)
New Revision: 12665

Modified:
   trunk/mapserver/mapcache/include/mapcache.h
   trunk/mapserver/mapcache/src/cache_tiff.c
   trunk/mapserver/mapcache/src/configuration.c
   trunk/mapserver/mapcache/src/configuration_xml.c
   trunk/mapserver/mapcache/src/imageio_jpeg.c
   trunk/mapserver/mapcache/src/source_mapserver.c
Log:
add photometric (RGB/YCBCR) creation option for jpeg formats.
modify default WGS84 grid to remove the highest resolution as it results in a tile with extent (-180,-180,180,180)


Modified: trunk/mapserver/mapcache/include/mapcache.h
===================================================================
--- trunk/mapserver/mapcache/include/mapcache.h	2011-10-14 15:33:26 UTC (rev 12664)
+++ trunk/mapserver/mapcache/include/mapcache.h	2011-10-16 12:27:47 UTC (rev 12665)
@@ -1340,6 +1340,14 @@
     MAPCACHE_COMPRESSION_DEFAULT /**< default compression*/
 } mapcache_compression_type;
 
+/**
+ * photometric interpretation for jpeg bands
+ */
+typedef enum {
+    MAPCACHE_PHOTOMETRIC_RGB,
+    MAPCACHE_PHOTOMETRIC_YCBCR
+} mapcache_photometric;
+
 /**\interface mapcache_image_format
  * \brief an image format
  * \sa mapcache_image_format_jpeg
@@ -1444,9 +1452,11 @@
 struct mapcache_image_format_jpeg {
     mapcache_image_format format;
     int quality; /**< JPEG quality, 1-100 */
+    mapcache_photometric photometric;
 };
 
-mapcache_image_format* mapcache_imageio_create_jpeg_format(apr_pool_t *pool, char *name, int quality);
+mapcache_image_format* mapcache_imageio_create_jpeg_format(apr_pool_t *pool, char *name, int quality,
+      mapcache_photometric photometric);
 
 /**
  * @param r

Modified: trunk/mapserver/mapcache/src/cache_tiff.c
===================================================================
--- trunk/mapserver/mapcache/src/cache_tiff.c	2011-10-14 15:33:26 UTC (rev 12664)
+++ trunk/mapserver/mapcache/src/cache_tiff.c	2011-10-16 12:27:47 UTC (rev 12665)
@@ -502,6 +502,7 @@
    char errmsg[120];
    _mapcache_cache_tiff_tile_key(ctx, tile, &filename);
    mapcache_cache_tiff *dcache = (mapcache_cache_tiff*)tile->tileset->cache;
+   mapcache_image_format_jpeg *format = (mapcache_image_format_jpeg*) dcache->format;
    if(GC_HAS_ERROR(ctx)) {
       return;
    }
@@ -604,7 +605,6 @@
 
       TIFFSetField( hTIFF, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_UINT );
       TIFFSetField( hTIFF, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG );
-      TIFFSetField( hTIFF, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB );
       TIFFSetField( hTIFF, TIFFTAG_BITSPERSAMPLE, 8 );
       TIFFSetField( hTIFF, TIFFTAG_COMPRESSION, COMPRESSION_JPEG );
       TIFFSetField( hTIFF, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB );
@@ -640,8 +640,13 @@
       GTIFFree( psGTIF );
 #endif
    }
-   mapcache_image_format_jpeg *format = (mapcache_image_format_jpeg*) dcache->format;
    TIFFSetField(hTIFF, TIFFTAG_JPEGQUALITY, format->quality); 
+   if(format->photometric == MAPCACHE_PHOTOMETRIC_RGB) {
+      TIFFSetField( hTIFF, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
+   } else {
+      TIFFSetField( hTIFF, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_YCBCR);
+   }
+   TIFFSetField( hTIFF, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB );
 
    int tiff_offx, tiff_offy; /* the x and y offset of the tile inside the tiff image */
    int tiff_off; /* the index of the tile inside the list of tiles of the tiff image */

Modified: trunk/mapserver/mapcache/src/configuration.c
===================================================================
--- trunk/mapserver/mapcache/src/configuration.c	2011-10-14 15:33:26 UTC (rev 12664)
+++ trunk/mapserver/mapcache/src/configuration.c	2011-10-16 12:27:47 UTC (rev 12665)
@@ -95,8 +95,7 @@
 mapcache_cfg* mapcache_configuration_create(apr_pool_t *pool) {
    mapcache_grid *grid;
    int i;
-   double wgs84_resolutions[19]={
-         1.40625000000000,
+   double wgs84_resolutions[18]={
          0.703125000000000,
          0.351562500000000,
          0.175781250000000,
@@ -159,7 +158,7 @@
          mapcache_imageio_create_png_q_format(pool,"PNG8",MAPCACHE_COMPRESSION_FAST,256),
          "PNG8");
    mapcache_configuration_add_image_format(cfg,
-         mapcache_imageio_create_jpeg_format(pool,"JPEG",90),
+         mapcache_imageio_create_jpeg_format(pool,"JPEG",90,MAPCACHE_PHOTOMETRIC_YCBCR),
          "JPEG");
    cfg->default_image_format = mapcache_configuration_get_image_format(cfg,"JPEG");
    cfg->reporting = MAPCACHE_REPORT_MSG;
@@ -172,7 +171,7 @@
    grid->srs = apr_pstrdup(pool,"EPSG:4326");
    grid->unit = MAPCACHE_UNIT_DEGREES;
    grid->tile_sx = grid->tile_sy = 256;
-   grid->nlevels = 19;
+   grid->nlevels = 18;
    grid->extent[0] = wgs84_extent[0];
    grid->extent[1] = wgs84_extent[1];
    grid->extent[2] = wgs84_extent[2];

Modified: trunk/mapserver/mapcache/src/configuration_xml.c
===================================================================
--- trunk/mapserver/mapcache/src/configuration_xml.c	2011-10-14 15:33:26 UTC (rev 12664)
+++ trunk/mapserver/mapcache/src/configuration_xml.c	2011-10-16 12:27:47 UTC (rev 12665)
@@ -341,6 +341,7 @@
       }
    } else if(!strcmp(type,"JPEG")){
       int quality = 95;
+      mapcache_photometric photometric = MAPCACHE_PHOTOMETRIC_YCBCR;
       if ((cur_node = ezxml_child(node,"quality")) != NULL) {
          char *endptr;
          quality = (int)strtol(cur_node->txt,&endptr,10);
@@ -352,8 +353,19 @@
             return;
          }
       }
+      if ((cur_node = ezxml_child(node,"photometric")) != NULL) {
+         if(!strcasecmp(cur_node->txt,"RGB"))
+            photometric = MAPCACHE_PHOTOMETRIC_RGB;
+         else if(!strcasecmp(cur_node->txt,"YCBCR"))
+            photometric = MAPCACHE_PHOTOMETRIC_YCBCR;
+         else {
+            ctx->set_error(ctx,500,"failed to parse jpeg format %s photometric %s. expecting rgb or ycbcr",
+                  name,cur_node->txt);
+            return;
+         }
+      }
       format = mapcache_imageio_create_jpeg_format(ctx->pool,
-            name,quality);
+            name,quality,photometric);
    } else if(!strcmp(type,"MIXED")){
       mapcache_image_format *transparent=NULL, *opaque=NULL;
       if ((cur_node = ezxml_child(node,"transparent")) != NULL) {

Modified: trunk/mapserver/mapcache/src/imageio_jpeg.c
===================================================================
--- trunk/mapserver/mapcache/src/imageio_jpeg.c	2011-10-14 15:33:26 UTC (rev 12664)
+++ trunk/mapserver/mapcache/src/imageio_jpeg.c	2011-10-16 12:27:47 UTC (rev 12665)
@@ -176,6 +176,14 @@
    cinfo.in_color_space = JCS_RGB;
    jpeg_set_defaults(&cinfo);
    jpeg_set_quality(&cinfo, ((mapcache_image_format_jpeg*)format)->quality, TRUE);
+   switch(((mapcache_image_format_jpeg*)format)->photometric) {
+      case MAPCACHE_PHOTOMETRIC_RGB:
+         jpeg_set_colorspace(&cinfo, JCS_RGB);
+         break;
+      case MAPCACHE_PHOTOMETRIC_YCBCR:
+      default:
+         jpeg_set_colorspace(&cinfo, JCS_YCbCr);
+   }
    jpeg_start_compress(&cinfo, TRUE);
 
    rowdata = (JSAMPLE*)malloc(img->w*cinfo.input_components*sizeof(JSAMPLE));
@@ -304,7 +312,8 @@
    return buf;
 }
 
-mapcache_image_format* mapcache_imageio_create_jpeg_format(apr_pool_t *pool, char *name, int quality ) {
+mapcache_image_format* mapcache_imageio_create_jpeg_format(apr_pool_t *pool, char *name, int quality,
+      mapcache_photometric photometric) {
    mapcache_image_format_jpeg *format = apr_pcalloc(pool, sizeof(mapcache_image_format_jpeg));
    format->format.name = name;
    format->format.extension = apr_pstrdup(pool,"jpg");
@@ -313,6 +322,7 @@
    format->format.create_empty_image = _mapcache_imageio_jpg_create_empty;
    format->format.write = _mapcache_imageio_jpeg_encode;
    format->quality = quality;
+   format->photometric = photometric;
    format->format.type = GC_JPEG;
    return (mapcache_image_format*)format;
 }

Modified: trunk/mapserver/mapcache/src/source_mapserver.c
===================================================================
--- trunk/mapserver/mapcache/src/source_mapserver.c	2011-10-14 15:33:26 UTC (rev 12664)
+++ trunk/mapserver/mapcache/src/source_mapserver.c	2011-10-16 12:27:47 UTC (rev 12665)
@@ -43,6 +43,7 @@
    mapcache_source_mapserver *mapserver = (mapcache_source_mapserver*)map->tileset->source;
    static mapObj *origmap = NULL;
    if(!origmap) {
+   msSetup();
       origmap = msLoadMap(mapserver->mapfile,NULL);
    }
    if(!origmap) {
@@ -110,9 +111,14 @@
       return;
    }
    rasterBufferObj rb;
+   
+   if(image->format->vtable->supports_pixel_buffer) {
+      image->format->vtable->getRasterBufferHandle(image,&rb);
+   } else {
+      ctx->set_error(ctx,500,"format %s has no pixel export",image->format->name);
+      return;
+   }
 
-   image->format->vtable->getRasterBufferHandle(image,&rb);
-
    map->image = mapcache_image_create(ctx);
    map->image->w = map->width;
    map->image->h = map->height;



More information about the mapserver-commits mailing list