Skip to content

Commit 5ee5a17

Browse files
committed
Detect if transparency can be ignored for paletted renderer
1 parent 8dc45e4 commit 5ee5a17

5 files changed

Lines changed: 23 additions & 8 deletions

File tree

src/core/raster/qgspalettedrasterrenderer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "qgspalettedrasterrenderer.h"
1919
#include "qgsrastertransparency.h"
20+
#include "qgsrasterviewport.h"
2021
#include <QColor>
2122
#include <QImage>
2223

@@ -61,7 +62,8 @@ void QgsPalettedRasterRenderer::draw( QPainter* p, QgsRasterViewPort* viewPort,
6162
void* rasterData;
6263
double currentOpacity = mOpacity;
6364

64-
bool hasTransparency = usesTransparency();
65+
//rendering is faster without considering user-defined transparency
66+
bool hasTransparency = usesTransparency( viewPort->mSrcCRS, viewPort->mDestCRS );
6567
void* transparencyData;
6668

6769
while ( readNextRasterPart( mBandNumber, viewPort, nCols, nRows, &rasterData, topLeftCol, topLeftRow ) )

src/core/raster/qgsrasterrenderer.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,15 @@ void QgsRasterRenderer::removePartInfo( int bandNumber )
157157
}
158158
}
159159

160-
bool QgsRasterRenderer::usesTransparency() const
160+
bool QgsRasterRenderer::usesTransparency( QgsCoordinateReferenceSystem& srcSRS, QgsCoordinateReferenceSystem& dstSRS ) const
161161
{
162-
return ( mAlphaBand > 0 || ( mRasterTransparency && !mRasterTransparency->isEmpty() ) || !doubleNear( mOpacity, 1.0 ) );
162+
//transparency is always used if on-the-fly reprojection is enabled
163+
bool reprojectionEnabled = ( srcSRS.isValid() && dstSRS.isValid() && srcSRS != dstSRS );
164+
if ( !mProvider || reprojectionEnabled )
165+
{
166+
return true;
167+
}
168+
return ( mAlphaBand > 0 || ( mRasterTransparency && !mRasterTransparency->isEmpty( mProvider->noDataValue() ) ) || !doubleNear( mOpacity, 1.0 ) );
163169
}
164170

165171
void QgsRasterRenderer::drawImage( QPainter* p, QgsRasterViewPort* viewPort, const QImage& img, int topLeftCol, int topLeftRow,

src/core/raster/qgsrasterrenderer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class QgsRasterRenderer
4545
virtual ~QgsRasterRenderer();
4646
virtual void draw( QPainter* p, QgsRasterViewPort* viewPort, const QgsMapToPixel* theQgsMapToPixel ) = 0;
4747

48-
bool usesTransparency() const;
48+
bool usesTransparency( QgsCoordinateReferenceSystem& srcSRS, QgsCoordinateReferenceSystem& dstSRS ) const;
4949

5050
void setOpacity( double opacity ) { mOpacity = opacity; }
5151
double opacity() const { return mOpacity; }

src/core/raster/qgsrastertransparency.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ email : ersts@amnh.org
1818
#include <QList>
1919

2020
#include "qgsrastertransparency.h"
21+
#include "qgis.h"
2122

2223
QgsRasterTransparency::QgsRasterTransparency()
2324
{
@@ -169,7 +170,13 @@ int QgsRasterTransparency::alphaValue( double theRedValue, double theGreenValue,
169170
return theGlobalTransparency;
170171
}
171172

172-
bool QgsRasterTransparency::isEmpty() const
173+
bool QgsRasterTransparency::isEmpty( double nodataValue ) const
173174
{
174-
return ( mTransparentThreeValuePixelList.isEmpty() && mTransparentSingleValuePixelList.isEmpty() );
175+
return (
176+
( mTransparentSingleValuePixelList.isEmpty() ||
177+
( mTransparentSingleValuePixelList.size() == 1 && doubleNear( mTransparentSingleValuePixelList.at( 0 ).pixelValue, nodataValue ) ) )
178+
&&
179+
( mTransparentThreeValuePixelList.isEmpty() ||
180+
( mTransparentThreeValuePixelList.size() == 1 && doubleNear( mTransparentThreeValuePixelList.at( 0 ).red, nodataValue ) &&
181+
doubleNear( mTransparentThreeValuePixelList.at( 0 ).green, nodataValue ) && doubleNear( mTransparentThreeValuePixelList.at( 0 ).blue, nodataValue ) ) ) );
175182
}

src/core/raster/qgsrastertransparency.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ class CORE_EXPORT QgsRasterTransparency
7272
/** \brief Return the transparency value for a RGB Pixel */
7373
int alphaValue( double, double, double, int theGlobalTransparency = 255 ) const;
7474

75-
/**True if there are no entries in the pixel lists*/
76-
bool isEmpty() const;
75+
/**True if there are no entries in the pixel lists except the nodata value*/
76+
bool isEmpty( double nodataValue ) const;
7777

7878
private:
7979
/** \brief The list to hold transparency values for RGB layers */

0 commit comments

Comments
 (0)