@@ -1535,16 +1535,23 @@ bool QgsRasterLayer::draw( QgsRenderContext& rendererContext )
1535
1535
// Set the transparency for the whole layer
1536
1536
// QImage::setAlphaChannel does not work quite as expected so set each pixel individually
1537
1537
// Currently this is only done for WMS images, which should be small enough not to impact performance
1538
- int myWidth = image->width ();
1539
- int myHeight = image->height ();
1540
- QRgb myRgb;
1541
- for ( int myHeightRunner = 0 ; myHeightRunner < myHeight; myHeightRunner++ )
1538
+
1539
+ if (mTransparencyLevel != 255 ) // improve performance if layer transparency not altered
1542
1540
{
1543
- for ( int myWidthRunner = 0 ; myWidthRunner < myWidth; myWidthRunner++ )
1544
- {
1545
- myRgb = image->pixel ( myWidthRunner, myHeightRunner );
1546
- image->setPixel ( myWidthRunner, myHeightRunner, qRgba ( qRed ( myRgb ), qGreen ( myRgb ), qBlue ( myRgb ), mTransparencyLevel ) );
1547
- }
1541
+ int myWidth = image->width ();
1542
+ int myHeight = image->height ();
1543
+ QRgb myRgb;
1544
+ int newTransparency;
1545
+ for ( int myHeightRunner = 0 ; myHeightRunner < myHeight; myHeightRunner++ )
1546
+ {
1547
+ for ( int myWidthRunner = 0 ; myWidthRunner < myWidth; myWidthRunner++ )
1548
+ {
1549
+ myRgb = image->pixel ( myWidthRunner, myHeightRunner );
1550
+ // combine transparency from WMS and layer transparency
1551
+ newTransparency = (double ) mTransparencyLevel / 255.0 * (double )(qAlpha (myRgb));
1552
+ image->setPixel ( myWidthRunner, myHeightRunner, qRgba ( qRed ( myRgb ), qGreen ( myRgb ), qBlue ( myRgb ), newTransparency ));
1553
+ }
1554
+ }
1548
1555
}
1549
1556
1550
1557
// Since GDAL's RasterIO can't handle floating point, we have to round to
0 commit comments