[mapserver-commits] r10006 - trunk/mapserver

svn at osgeo.org svn at osgeo.org
Thu Mar 25 00:29:16 EDT 2010


Author: warmerdam
Date: 2010-03-25 00:29:16 -0400 (Thu, 25 Mar 2010)
New Revision: 10006

Modified:
   trunk/mapserver/HISTORY.TXT
   trunk/mapserver/mapdrawgdal.c
Log:
incorporate support for GDAL nodata on RGB images (#2404)

Modified: trunk/mapserver/HISTORY.TXT
===================================================================
--- trunk/mapserver/HISTORY.TXT	2010-03-25 04:27:02 UTC (rev 10005)
+++ trunk/mapserver/HISTORY.TXT	2010-03-25 04:29:16 UTC (rev 10006)
@@ -14,6 +14,8 @@
 Current Version (SVN trunk):
 ----------------------------
 
+- Incorporate support for GDAL nodata on RGB images (#2404)
+
 - Incorporated support for GDAL masks (GDAL RFC 15) (#2640)
 
 - Fixed XML transformation issues with expressions and symbols (#3397)

Modified: trunk/mapserver/mapdrawgdal.c
===================================================================
--- trunk/mapserver/mapdrawgdal.c	2010-03-25 04:27:02 UTC (rev 10005)
+++ trunk/mapserver/mapdrawgdal.c	2010-03-25 04:29:16 UTC (rev 10006)
@@ -58,7 +58,9 @@
 		layerObj *layer, 
 		int src_xoff, int src_yoff, int src_xsize, int src_ysize, 
 		GByte *pabyBuffer,
-		int dst_xsize, int dst_ysize );
+		int dst_xsize, int dst_ysize,
+                int *pbHaveRGBNoData, 
+                int *pnNoData1, int *pnNoData2, int *pnNoData3 );
 static int 
 msDrawRasterLayerGDAL_RawMode(
     mapObj *map, layerObj *layer, imageObj *image, GDALDatasetH hDS, 
@@ -151,6 +153,8 @@
     GDALDatasetH hDS = hDSVoid;
     GDALColorTableH hColorMap;
     GDALRasterBandH hBand1=NULL, hBand2=NULL, hBand3=NULL, hBandAlpha=NULL;
+    int bHaveRGBNoData = FALSE;
+    int nNoData1=-1,nNoData2=-1,nNoData3=-1;
   
     memset( cmap, 0xff, MAXCOLORS * sizeof(int) );
     memset( rb_cmap, 0, sizeof(rb_cmap) );
@@ -818,12 +822,17 @@
      */
     if( LoadGDALImages( hDS, band_numbers, band_count, layer, 
                         src_xoff, src_yoff, src_xsize, src_ysize, 
-                        pabyRaw1, dst_xsize, dst_ysize ) == -1 )
+                        pabyRaw1, dst_xsize, dst_ysize,
+                        &bHaveRGBNoData, 
+                        &nNoData1, &nNoData2, &nNoData3 ) == -1 )
     {
         free( pabyRaw1 );
         return -1;
     }
 
+    if( bHaveRGBNoData && layer->debug )
+        msDebug( "msDrawGDAL(): using RGB nodata values from GDAL dataset.\n" );
+
 /* -------------------------------------------------------------------- */
 /*      If there was no alpha band, but we have a dataset level mask    */
 /*      load it as massage it so it will function as our alpha for      */
@@ -1097,7 +1106,13 @@
                     && pabyRaw2[k] == layer->offsite.green
                     && pabyRaw3[k] == layer->offsite.blue )
                     continue;
-              
+
+                if( bHaveRGBNoData 
+                    && pabyRaw1[k] == nNoData1 
+                    && pabyRaw2[k] == nNoData2 
+                    && pabyRaw3[k] == nNoData3 )
+                    continue;
+
                 if( pabyRawAlpha == NULL || pabyRawAlpha[k] == 255 )
                 {
                     RB_SET_PIXEL( rb, j, i, 
@@ -1154,6 +1169,12 @@
                         && pabyRaw3[k] == layer->offsite.blue )
                         continue;
 
+                    if( bHaveRGBNoData 
+                        && pabyRaw1[k] == nNoData1 
+                        && pabyRaw2[k] == nNoData2 
+                        && pabyRaw3[k] == nNoData3 )
+                        continue;
+
                     if( pabyRawAlpha != NULL && pabyRawAlpha[k] == 0 )
                         continue;
 
@@ -1185,6 +1206,12 @@
                         && pabyRaw3[k] == layer->offsite.blue )
                         continue;
                   
+                    if( bHaveRGBNoData 
+                        && pabyRaw1[k] == nNoData1 
+                        && pabyRaw2[k] == nNoData2 
+                        && pabyRaw3[k] == nNoData3 )
+                        continue;
+
                     if( pabyRawAlpha != NULL && pabyRawAlpha[k] == 0 )
                         continue;
 
@@ -1206,6 +1233,12 @@
                         && pabyRaw3[k] == layer->offsite.blue )
                         continue;
                   
+                    if( bHaveRGBNoData 
+                        && pabyRaw1[k] == nNoData1 
+                        && pabyRaw2[k] == nNoData2 
+                        && pabyRaw3[k] == nNoData3 )
+                        continue;
+
                     if( pabyRawAlpha == NULL || pabyRawAlpha[k] == 255 )
                     {
                         gdImg->tpixels[i][j] = 
@@ -1514,7 +1547,9 @@
 		layerObj *layer, 
 		int src_xoff, int src_yoff, int src_xsize, int src_ysize, 
 		GByte *pabyWholeBuffer,
-		int dst_xsize, int dst_ysize )
+		int dst_xsize, int dst_ysize,
+                int *pbHaveRGBNoData, 
+                int *pnNoData1, int *pnNoData2, int *pnNoData3 )
     
 {
     int    iColorIndex, result_code=0;
@@ -1522,6 +1557,31 @@
     float *pafWholeRawData;
 
 /* -------------------------------------------------------------------- */
+/*      If we have no alpha band, but we do have three input            */
+/*      bands, then check for nodata values.  If we only have one       */
+/*      input band, then nodata will already have been adderssed as     */
+/*      part of the real or manufactured color table.                   */
+/* -------------------------------------------------------------------- */
+    if( band_count == 3 )
+    {
+        *pnNoData1 = (int) 
+            msGetGDALNoDataValue( layer, 
+                                  GDALGetRasterBand(hDS,band_numbers[0]), 
+                                  pbHaveRGBNoData);
+
+        if( *pbHaveRGBNoData )
+            *pnNoData2 = (int) 
+                msGetGDALNoDataValue( layer, 
+                                  GDALGetRasterBand(hDS,band_numbers[1]), 
+                                  pbHaveRGBNoData);
+        if( *pbHaveRGBNoData )
+            *pnNoData3 = (int) 
+                msGetGDALNoDataValue( layer, 
+                                  GDALGetRasterBand(hDS,band_numbers[2]), 
+                                  pbHaveRGBNoData);
+    }
+
+/* -------------------------------------------------------------------- */
 /*      Are we doing a simple, non-scaling case?  If so, read directly  */
 /*      and return.                                                     */
 /* -------------------------------------------------------------------- */
@@ -1558,6 +1618,11 @@
     }
 
 /* -------------------------------------------------------------------- */
+/*      Disable use of nodata if we are doing scaling.                  */
+/* -------------------------------------------------------------------- */
+    *pbHaveRGBNoData = FALSE;
+
+/* -------------------------------------------------------------------- */
 /*      We need to do some scaling.  Will load into either a 16bit      */
 /*      unsigned or a floating point buffer depending on the source     */
 /*      data.  We offer a special case for 16U data because it is       */



More information about the mapserver-commits mailing list