[QGIS Commit] r10262 - trunk/qgis/src/core/raster

svn_qgis at osgeo.org svn_qgis at osgeo.org
Wed Mar 4 08:26:38 EST 2009


Author: mhugent
Date: 2009-03-04 08:26:38 -0500 (Wed, 04 Mar 2009)
New Revision: 10262

Modified:
   trunk/qgis/src/core/raster/qgsrasterlayer.cpp
Log:
For WMS layers: combine the transparency of WMS and the layer transparency

Modified: trunk/qgis/src/core/raster/qgsrasterlayer.cpp
===================================================================
--- trunk/qgis/src/core/raster/qgsrasterlayer.cpp	2009-03-03 22:09:19 UTC (rev 10261)
+++ trunk/qgis/src/core/raster/qgsrasterlayer.cpp	2009-03-04 13:26:38 UTC (rev 10262)
@@ -1535,16 +1535,23 @@
     //Set the transparency for the whole layer
     //QImage::setAlphaChannel does not work quite as expected so set each pixel individually
     //Currently this is only done for WMS images, which should be small enough not to impact performance
-    int myWidth = image->width();
-    int myHeight = image->height();
-    QRgb myRgb;
-    for ( int myHeightRunner = 0; myHeightRunner < myHeight; myHeightRunner++ )
+
+    if(mTransparencyLevel != 255) //improve performance if layer transparency not altered
     {
-      for ( int myWidthRunner = 0; myWidthRunner < myWidth; myWidthRunner++ )
-      {
-        myRgb = image->pixel( myWidthRunner, myHeightRunner );
-        image->setPixel( myWidthRunner, myHeightRunner, qRgba( qRed( myRgb ), qGreen( myRgb ), qBlue( myRgb ), mTransparencyLevel ) );
-      }
+        int myWidth = image->width();
+        int myHeight = image->height();
+        QRgb myRgb;
+        int newTransparency;
+        for ( int myHeightRunner = 0; myHeightRunner < myHeight; myHeightRunner++ )
+        {
+          for ( int myWidthRunner = 0; myWidthRunner < myWidth; myWidthRunner++ )
+          {
+            myRgb = image->pixel( myWidthRunner, myHeightRunner );
+            //combine transparency from WMS and layer transparency
+            newTransparency =  (double) mTransparencyLevel / 255.0 * (double)(qAlpha(myRgb));
+            image->setPixel( myWidthRunner, myHeightRunner, qRgba( qRed( myRgb ), qGreen( myRgb ), qBlue( myRgb ), newTransparency ));
+          }
+        }
     }
 
     // Since GDAL's RasterIO can't handle floating point, we have to round to



More information about the QGIS-commit mailing list