diff --git a/src/core/raster/qgsrasterlayer.cpp b/src/core/raster/qgsrasterlayer.cpp index 29e30726855..ad5a1a364c8 100644 --- a/src/core/raster/qgsrasterlayer.cpp +++ b/src/core/raster/qgsrasterlayer.cpp @@ -1535,16 +1535,23 @@ bool QgsRasterLayer::draw( QgsRenderContext& rendererContext ) //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