[mapserver-commits] r10060 - trunk/mapserver

svn at osgeo.org svn at osgeo.org
Tue Apr 6 21:09:44 EDT 2010


Author: warmerdam
Date: 2010-04-06 21:09:44 -0400 (Tue, 06 Apr 2010)
New Revision: 10060

Modified:
   trunk/mapserver/HISTORY.TXT
   trunk/mapserver/mapresample.c
Log:
improve rounding when averaging (#1932)

Modified: trunk/mapserver/HISTORY.TXT
===================================================================
--- trunk/mapserver/HISTORY.TXT	2010-04-06 23:26:54 UTC (rev 10059)
+++ trunk/mapserver/HISTORY.TXT	2010-04-07 01:09:44 UTC (rev 10060)
@@ -14,6 +14,8 @@
 Current Version (SVN trunk):
 ----------------------------
 
+- Change rounding rules for average resampling (#1932)
+
 - Implement support for filename encryption per RFC 18 for rasters (#3416)
 
 - Fixed segfault when using shapefile with empty geometry and tileindex (#3365)

Modified: trunk/mapserver/mapresample.c
===================================================================
--- trunk/mapserver/mapresample.c	2010-04-06 23:26:54 UTC (rev 10059)
+++ trunk/mapserver/mapresample.c	2010-04-07 01:09:44 UTC (rev 10060)
@@ -751,9 +751,9 @@
                     nSetPoints++;
                     if( dfAlpha01 > 0.99 )
                         dstImg->tpixels[nDstY][nDstX] = 
-                            gdTrueColor( (int) padfPixelSum[0], 
-                                         (int) padfPixelSum[1], 
-                                         (int) padfPixelSum[2] );
+                            gdTrueColor( (int) (padfPixelSum[0]+0.5), 
+                                         (int) (padfPixelSum[1]+0.5), 
+                                         (int) (padfPixelSum[2]+0.5) );
                     else
                     {
                         int gd_color;
@@ -761,9 +761,9 @@
 
                         gd_alpha = MAX(0,MIN(127,gd_alpha));
                         gd_color = gdTrueColorAlpha(
-                            (int) padfPixelSum[0], 
-                            (int) padfPixelSum[1], 
-                            (int) padfPixelSum[2], 
+                            (int) (padfPixelSum[0]+0.5), 
+                            (int) (padfPixelSum[1]+0.5), 
+                            (int) (padfPixelSum[2]+0.5), 
                             gd_alpha );
                         
                         dstImg->tpixels[nDstY][nDstX] = 
@@ -786,11 +786,15 @@
 
                 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];
+                    dst_rb->r[dst_rb_off] = 
+                        (unsigned char) (padfPixelSum[0]+0.5);
+                    dst_rb->g[dst_rb_off] = 
+                        (unsigned char) (padfPixelSum[1]+0.5);
+                    dst_rb->b[dst_rb_off] = 
+                        (unsigned char) (padfPixelSum[2]+0.5);
                     if( dst_rb->a )
-                        dst_rb->a[dst_rb_off] = (unsigned char) dfAlpha01*255;
+                        dst_rb->a[dst_rb_off] = 
+                            (unsigned char) (dfAlpha01*255+0.5);
                 }
             }
             else if( MS_RENDERER_RAWDATA(psSrcImage->format) )
@@ -805,7 +809,7 @@
                     if( psSrcImage->format->imagemode == MS_IMAGEMODE_INT16 )
                     {
                         psDstImage->img.raw_16bit[dst_off] 
-                            = (short) padfPixelSum[band];
+                            = (short) (padfPixelSum[band]+0.5);
                     }
                     else if( psSrcImage->format->imagemode == MS_IMAGEMODE_FLOAT32)
                     {



More information about the mapserver-commits mailing list