[QGIS Commit] r10146 - in trunk/qgis/src: core/raster providers/wms
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Mon Feb 9 22:45:16 EST 2009
Author: ersts
Date: 2009-02-09 22:45:16 -0500 (Mon, 09 Feb 2009)
New Revision: 10146
Modified:
trunk/qgis/src/core/raster/qgsrasterlayer.cpp
trunk/qgis/src/providers/wms/qgswmsprovider.cpp
Log:
-Updated transparency setting for WMS layers
-Should close ticket #1533
Modified: trunk/qgis/src/core/raster/qgsrasterlayer.cpp
===================================================================
--- trunk/qgis/src/core/raster/qgsrasterlayer.cpp 2009-02-09 20:07:04 UTC (rev 10145)
+++ trunk/qgis/src/core/raster/qgsrasterlayer.cpp 2009-02-10 03:45:16 UTC (rev 10146)
@@ -1508,9 +1508,19 @@
QgsDebugMsg( QString( "(int)origin y: %1" ).arg( static_cast<int>( myRasterViewPort->topLeftPoint.y() ) ) );
//Set the transparency for the whole layer
- QImage myAlphaChannel( image->width(), image->height(), QImage::Format_Indexed8 );
- myAlphaChannel.fill(( uint ) mTransparencyLevel );
- image->setAlphaChannel( myAlphaChannel );
+ //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++ )
+ {
+ for( int myWidthRunner = 0; myWidthRunner < myWidth; myWidthRunner++ )
+ {
+ myRgb = image->pixel( myWidthRunner, myHeightRunner );
+ image->setPixel( myWidthRunner, myHeightRunner, qRgba( qRed( myRgb ), qGreen( myRgb ), qBlue( myRgb ), mTransparencyLevel ) );
+ }
+ }
// Since GDAL's RasterIO can't handle floating point, we have to round to
// the nearest pixel. Add 0.5 to get rounding instead of truncation
Modified: trunk/qgis/src/providers/wms/qgswmsprovider.cpp
===================================================================
--- trunk/qgis/src/providers/wms/qgswmsprovider.cpp 2009-02-09 20:07:04 UTC (rev 10145)
+++ trunk/qgis/src/providers/wms/qgswmsprovider.cpp 2009-02-10 03:45:16 UTC (rev 10146)
@@ -523,9 +523,11 @@
{
delete cachedImage;
}
- cachedImage = new QImage();
- *cachedImage = QImage::fromData( imagesource );
+ //Create a local image from source then convert it to RGBA, so we can set the transparency later
+ QImage myLocalImage = QImage::fromData( imagesource );
+ cachedImage = new QImage( myLocalImage.convertToFormat( QImage::Format_ARGB32 ) );
+
// Remember settings for useful caching next time.
cachedViewExtent = viewExtent;
cachedPixelWidth = pixelWidth;
More information about the QGIS-commit
mailing list