@@ -1535,15 +1535,24 @@ 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++ )
1541
+ QImage* transparentImageCopy = new QImage (*image); // copy image if there is user transparency
1542
+ image = transparentImageCopy;
1543
+ int myWidth = image->width ();
1544
+ int myHeight = image->height ();
1545
+ QRgb myRgb;
1546
+ int newTransparency;
1547
+ for ( int myHeightRunner = 0 ; myHeightRunner < myHeight; myHeightRunner++ )
1544
1548
{
1549
+ for ( int myWidthRunner = 0 ; myWidthRunner < myWidth; myWidthRunner++ )
1550
+ {
1545
1551
myRgb = image->pixel ( myWidthRunner, myHeightRunner );
1546
- image->setPixel ( myWidthRunner, myHeightRunner, qRgba ( qRed ( myRgb ), qGreen ( myRgb ), qBlue ( myRgb ), mTransparencyLevel ) );
1552
+ // combine transparency from WMS and layer transparency
1553
+ newTransparency = (double ) mTransparencyLevel / 255.0 * (double )(qAlpha (myRgb));
1554
+ image->setPixel ( myWidthRunner, myHeightRunner, qRgba ( qRed ( myRgb ), qGreen ( myRgb ), qBlue ( myRgb ), newTransparency ));
1555
+ }
1547
1556
}
1548
1557
}
1549
1558
@@ -1562,6 +1571,11 @@ bool QgsRasterLayer::draw( QgsRenderContext& rendererContext )
1562
1571
),
1563
1572
*image );
1564
1573
1574
+ if (mTransparencyLevel != 255 )
1575
+ {
1576
+ delete image;
1577
+ }
1578
+
1565
1579
}
1566
1580
else
1567
1581
{
0 commit comments