[mapserver-commits] r9890 - trunk/mapserver

svn at osgeo.org svn at osgeo.org
Tue Feb 23 16:38:48 EST 2010


Author: warmerdam
Date: 2010-02-23 16:38:47 -0500 (Tue, 23 Feb 2010)
New Revision: 9890

Modified:
   trunk/mapserver/mapdrawgdal.c
   trunk/mapserver/mapresample.c
   trunk/mapserver/maputil.c
Log:
extended plugin raster support to resampling, improved alpha blending

Modified: trunk/mapserver/mapdrawgdal.c
===================================================================
--- trunk/mapserver/mapdrawgdal.c	2010-02-23 21:32:46 UTC (rev 9889)
+++ trunk/mapserver/mapdrawgdal.c	2010-02-23 21:38:47 UTC (rev 9890)
@@ -926,12 +926,12 @@
           {
               int	src_pixel, src_alpha, cmap_alpha, merged_alpha;
 
+              src_pixel = pabyRaw1[k];
               src_alpha = pabyRawAlpha[k];
-              cmap_alpha = rb_cmap[3][k];
+              cmap_alpha = rb_cmap[3][src_pixel];
 
-              merged_alpha = (src_alpha * cmap_alpha) / 256;
+              merged_alpha = (src_alpha * cmap_alpha) / 255;
 
-              src_pixel = pabyRaw1[k];
               if( merged_alpha < 2 )
                   /* do nothing - transparent */;
               else if( merged_alpha > 253 )

Modified: trunk/mapserver/mapresample.c
===================================================================
--- trunk/mapserver/mapresample.c	2010-02-23 21:32:46 UTC (rev 9889)
+++ trunk/mapserver/mapresample.c	2010-02-23 21:38:47 UTC (rev 9890)
@@ -82,8 +82,10 @@
 /************************************************************************/
 
 static int 
-msNearestRasterResampler( imageObj *psSrcImage, colorObj offsite,
-                          imageObj *psDstImage, int *panCMap,
+msNearestRasterResampler( imageObj *psSrcImage, rasterBufferObj *src_rb, 
+                          colorObj offsite,
+                          imageObj *psDstImage, rasterBufferObj *dst_rb,
+                          int *panCMap,
                           SimpleTransformer pfnTransform, void *pCBData,
                           int debug )
 
@@ -174,6 +176,56 @@
                     }
                 }
             }
+            else if( MS_RENDERER_PLUGIN(psSrcImage->format) )
+            {
+                int src_rb_off;
+
+                src_rb_off = nSrcX * src_rb->pixel_step 
+                    + nSrcY * src_rb->row_step;
+
+                assert( src_rb && dst_rb );
+
+                if( src_rb->a == NULL || src_rb->a[src_rb_off] > 253 )
+                {
+                    int dst_rb_off;
+
+                    dst_rb_off = nDstX * dst_rb->pixel_step 
+                        + nDstY * dst_rb->row_step;
+
+                    nSetPoints++;
+
+                    dst_rb->r[dst_rb_off] = src_rb->r[src_rb_off];
+                    dst_rb->g[dst_rb_off] = src_rb->g[src_rb_off];
+                    dst_rb->b[dst_rb_off] = src_rb->b[src_rb_off];
+                    if( dst_rb->a )
+                    {
+                        if( src_rb->a )
+                            dst_rb->a[dst_rb_off] = src_rb->a[src_rb_off];
+                        else
+                            dst_rb->a[dst_rb_off] = 255;
+                    }
+                }
+                else if( src_rb->a[src_rb_off] != 0 )
+                {
+                    int dst_rb_off;
+
+                    dst_rb_off = nDstX * dst_rb->pixel_step 
+                        + nDstY * dst_rb->row_step;
+
+                    nSetPoints++;
+                    
+                    /* actual alpha blending is required */
+                    msAlphaBlend2( src_rb->r[src_rb_off],
+                                   src_rb->g[src_rb_off],
+                                   src_rb->b[src_rb_off],
+                                   src_rb->a[src_rb_off],
+                                   dst_rb->r + dst_rb_off, 
+                                   dst_rb->g + dst_rb_off, 
+                                   dst_rb->b + dst_rb_off, 
+                                   dst_rb->a + dst_rb_off );
+                    
+                }
+            }
             else if( MS_RENDERER_RAWDATA(psSrcImage->format) )
             {
                 int band;
@@ -264,8 +316,8 @@
 /*                            msSourceSample()                          */
 /************************************************************************/
 
-static void msSourceSample( imageObj *psSrcImage, int iSrcX, int iSrcY,
-                            double *padfPixelSum,
+static void msSourceSample( imageObj *psSrcImage, rasterBufferObj *rb,
+                            int iSrcX, int iSrcY, double *padfPixelSum,
                             double dfWeight, double *pdfWeightSum,
                             colorObj *offsite )
 
@@ -293,7 +345,7 @@
             }
         }
     }
-    else
+    else if( MS_RENDERER_RAWDATA(psSrcImage->format) )
     {
         int band;
 
@@ -348,6 +400,18 @@
         }
         *pdfWeightSum += dfWeight;
     }
+    else if( rb && MS_RENDERER_PLUGIN(psSrcImage->format) )
+    {
+        int rb_off = iSrcX * rb->pixel_step + iSrcY * rb->row_step;
+
+        if( rb->a == NULL || rb->a[rb_off] > 1 )
+        {
+            padfPixelSum[0] += rb->r[rb_off] * dfWeight;
+            padfPixelSum[1] += rb->g[rb_off] * dfWeight;
+            padfPixelSum[2] += rb->b[rb_off] * dfWeight;
+            *pdfWeightSum += dfWeight; /* should we be using src alpha? */
+        }
+    }
 }
 
 /************************************************************************/
@@ -355,8 +419,10 @@
 /************************************************************************/
 
 static int 
-msBilinearRasterResampler( imageObj *psSrcImage, colorObj offsite,
-                           imageObj *psDstImage, int *panCMap,
+msBilinearRasterResampler( imageObj *psSrcImage, rasterBufferObj *src_rb, 
+                           colorObj offsite,
+                           imageObj *psDstImage, rasterBufferObj *dst_rb,
+                           int *panCMap,
                            SimpleTransformer pfnTransform, void *pCBData,
                            int debug )
 
@@ -432,19 +498,19 @@
 
             memset( padfPixelSum, 0, sizeof(double) * bandCount);
 
-            msSourceSample( psSrcImage, nSrcX, nSrcY, padfPixelSum, 
+            msSourceSample( psSrcImage, src_rb, nSrcX, nSrcY, padfPixelSum, 
                             (1.0 - dfRatioX2) * (1.0 - dfRatioY2),
                             &dfWeightSum, &offsite );
             
-            msSourceSample( psSrcImage, nSrcX2, nSrcY, padfPixelSum, 
+            msSourceSample( psSrcImage, src_rb, nSrcX2, nSrcY, padfPixelSum, 
                             (dfRatioX2) * (1.0 - dfRatioY2),
                             &dfWeightSum, &offsite );
             
-            msSourceSample( psSrcImage, nSrcX, nSrcY2, padfPixelSum, 
+            msSourceSample( psSrcImage, src_rb, nSrcX, nSrcY2, padfPixelSum, 
                             (1.0 - dfRatioX2) * (dfRatioY2),
                             &dfWeightSum, &offsite );
             
-            msSourceSample( psSrcImage, nSrcX2, nSrcY2, padfPixelSum, 
+            msSourceSample( psSrcImage, src_rb, nSrcX2, nSrcY2, padfPixelSum, 
                             (dfRatioX2) * (dfRatioY2),
                             &dfWeightSum, &offsite );
 
@@ -491,6 +557,27 @@
                     }
                 }
             }
+            else if( MS_RENDERER_PLUGIN(psSrcImage->format) )
+            {
+                int dst_rb_off;
+
+                assert( src_rb != NULL && dst_rb != NULL );
+
+                dst_rb_off = nDstX * dst_rb->pixel_step \
+                    + nDstY * dst_rb->row_step;
+
+                nSetPoints++;
+
+                if( dfWeightSum > 0.001 )
+                    msAlphaBlend2( (unsigned char) padfPixelSum[0],
+                                   (unsigned char) padfPixelSum[1],
+                                   (unsigned char) padfPixelSum[2],
+                                   (unsigned char) (dfWeightSum * 255),
+                                   dst_rb->r + dst_rb_off, 
+                                   dst_rb->g + dst_rb_off, 
+                                   dst_rb->b + dst_rb_off, 
+                                   (dst_rb->a == NULL) ? NULL : dst_rb->a + dst_rb_off );
+            }
             else if( MS_RENDERER_RAWDATA(psSrcImage->format) )
             {
                 int band;
@@ -550,7 +637,7 @@
 /************************************************************************/
 
 static int
-msAverageSample( imageObj *psSrcImage, 
+msAverageSample( imageObj *psSrcImage, rasterBufferObj *src_rb,
                  double dfXMin, double dfYMin, double dfXMax, double dfYMax,
                  colorObj *offsite, double *padfPixelSum, 
                  double *pdfAlpha01 )
@@ -583,7 +670,7 @@
 
             dfWeight = (dfXCellMax-dfXCellMin) * (dfYCellMax-dfYCellMin);
 
-            msSourceSample( psSrcImage, iX, iY, padfPixelSum, 
+            msSourceSample( psSrcImage, src_rb, iX, iY, padfPixelSum, 
                             dfWeight, &dfWeightSum, offsite );
             dfMaxWeight += dfWeight;
         }
@@ -605,8 +692,10 @@
 /************************************************************************/
 
 static int 
-msAverageRasterResampler( imageObj *psSrcImage, colorObj offsite,
-                          imageObj *psDstImage, int *panCMap,
+msAverageRasterResampler( imageObj *psSrcImage, rasterBufferObj *src_rb,
+                          colorObj offsite,
+                          imageObj *psDstImage, rasterBufferObj *dst_rb,
+                          int *panCMap,
                           SimpleTransformer pfnTransform, void *pCBData,
                           int debug )
 
@@ -675,7 +764,8 @@
                 
             memset( padfPixelSum, 0, sizeof(double)*bandCount );
     
-            if( !msAverageSample( psSrcImage, dfXMin, dfYMin, dfXMax, dfYMax,
+            if( !msAverageSample( psSrcImage, src_rb,
+                                  dfXMin, dfYMin, dfXMax, dfYMax,
                                   &offsite, padfPixelSum, &dfAlpha01 ) )
                 continue;
 
@@ -717,6 +807,26 @@
                     }
                 }
             }
+            else if( MS_RENDERER_PLUGIN(psSrcImage->format) )
+            {
+                int dst_rb_off;
+
+                assert( src_rb != NULL && dst_rb != NULL );
+
+                dst_rb_off = nDstX * dst_rb->pixel_step \
+                    + nDstY * dst_rb->row_step;
+
+                nSetPoints++;
+
+                if( dfAlpha01 > 0 )
+                {
+                    dst_rb->r[dst_rb_off] = (unsigned char) padfPixelSum[0];
+                    dst_rb->g[dst_rb_off] = (unsigned char) padfPixelSum[1];
+                    dst_rb->b[dst_rb_off] = (unsigned char) padfPixelSum[2];
+                    if( dst_rb->a )
+                        dst_rb->a[dst_rb_off] = (unsigned char) dfAlpha01*255;
+                }
+            }
             else if( MS_RENDERER_RAWDATA(psSrcImage->format) )
             {
                 int band;
@@ -1335,6 +1445,7 @@
     char       **papszAlteredProcessing = NULL;
     int         nLoadImgXSize, nLoadImgYSize;
     double      dfOversampleRatio;
+    rasterBufferObj *src_rb = NULL, src_rb_buffer;
     const char *resampleMode = CSLFetchNameValue( layer->processing, 
                                                   "RESAMPLE" );
 
@@ -1560,6 +1671,23 @@
         sDummyMap.imagecolor.blue = map->imagecolor.blue;
     }
 /* -------------------------------------------------------------------- */
+/*      We are using a plugable image.                                  */
+/* -------------------------------------------------------------------- */
+    else if( MS_RENDERER_PLUGIN(sDummyMap.outputformat) )
+    {
+        assert( sDummyMap.outputformat->imagemode == MS_IMAGEMODE_RGB
+                || sDummyMap.outputformat->imagemode == MS_IMAGEMODE_RGBA );
+
+        /* does forcing this stuff make sense in the plugin context? */
+        sDummyMap.outputformat->transparent = MS_TRUE;
+        sDummyMap.outputformat->imagemode = MS_IMAGEMODE_RGBA;
+
+        sDummyMap.imagecolor.red = map->imagecolor.red;
+        sDummyMap.imagecolor.green = map->imagecolor.green;
+        sDummyMap.imagecolor.blue = map->imagecolor.blue;
+    }
+
+/* -------------------------------------------------------------------- */
 /*      Setup a dummy map object we can use to read from the source     */
 /*      raster, with the newly established extents, and resolution.     */
 /* -------------------------------------------------------------------- */
@@ -1570,6 +1698,16 @@
     if (srcImage == NULL)
         return -1; /* msSetError() should have been called already */
 
+    if( MS_RENDERER_PLUGIN( srcImage->format ) )
+    {
+        if( srcImage->format->vtable->supports_pixel_buffer )
+        {
+            memset( &src_rb_buffer, 0, sizeof(src_rb_buffer) );
+            src_rb = &src_rb_buffer;
+            srcImage->format->vtable->getRasterBuffer( srcImage, src_rb );
+        }
+    }
+
 /* -------------------------------------------------------------------- */
 /*      Draw into the temporary image.  Temporarily replace the         */
 /*      layer processing directive so that we use our RAW_WINDOW.       */
@@ -1580,7 +1718,7 @@
         layer->processing = papszAlteredProcessing;
 
         result = msDrawRasterLayerGDAL( &sDummyMap, layer, srcImage, 
-                                        NULL, hDS );
+                                        src_rb, hDS );
 
         layer->processing = papszSavedProcessing;
         CSLDestroy( papszAlteredProcessing );
@@ -1644,17 +1782,20 @@
 /* -------------------------------------------------------------------- */
     if( EQUAL(resampleMode,"AVERAGE") )
         result = 
-            msAverageRasterResampler( srcImage, layer->offsite, image,
+            msAverageRasterResampler( srcImage, src_rb, layer->offsite, 
+                                      image, rb, 
                                       anCMap, msApproxTransformer, pACBData,
                                       layer->debug );
     else if( EQUAL(resampleMode,"BILINEAR") )
         result = 
-            msBilinearRasterResampler( srcImage, layer->offsite, image,
+            msBilinearRasterResampler( srcImage, src_rb, layer->offsite, 
+                                       image, rb,
                                        anCMap, msApproxTransformer, pACBData,
                                        layer->debug );
     else
         result = 
-            msNearestRasterResampler( srcImage, layer->offsite, image,
+            msNearestRasterResampler( srcImage, src_rb, layer->offsite, 
+                                      image, rb,
                                       anCMap, msApproxTransformer, pACBData,
                                       layer->debug );
 

Modified: trunk/mapserver/maputil.c
===================================================================
--- trunk/mapserver/maputil.c	2010-02-23 21:32:46 UTC (rev 9889)
+++ trunk/mapserver/maputil.c	2010-02-23 21:38:47 UTC (rev 9890)
@@ -1880,7 +1880,8 @@
         *red_dst = red_src;
         *green_dst = green_src;
         *blue_dst = blue_src;
-        *alpha_dst = alpha_src;
+        if( alpha_dst )
+            *alpha_dst = alpha_src;
         return;
     }
 
@@ -1902,11 +1903,11 @@
     if( alpha_dst != NULL )
         *alpha_dst = tot_weight;
 
-    *red_dst   = ((src_weight * *red_dst  ) + (dst_weight * red_src  )) 
+    *red_dst   = ((dst_weight * *red_dst  ) + (src_weight * red_src  )) 
         / tot_weight;
-    *green_dst = ((src_weight * *green_dst) + (dst_weight * green_src)) 
+    *green_dst = ((dst_weight * *green_dst) + (src_weight * green_src)) 
         / tot_weight;
-    *blue_dst  = ((src_weight * *blue_dst ) + (dst_weight * blue_src )) 
+    *blue_dst  = ((dst_weight * *blue_dst ) + (src_weight * blue_src )) 
         / tot_weight;
 }
 



More information about the mapserver-commits mailing list