Skip to content

Commit 73edd8f

Browse files
committedJul 10, 2018
Improve rendering speed of RGB images in the common case
Avoid doing contrast enhancement unless it is really necessary. This improved rendering speed of RGB image tiles in my test from around ~130 ms to ~40 ms.
1 parent f6ab5f9 commit 73edd8f

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed
 

‎src/core/raster/qgsmultibandcolorrenderer.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ QgsRasterBlock *QgsMultiBandColorRenderer::block( int bandNo, QgsRectangle cons
142142
//In some (common) cases, we can simplify the drawing loop considerably and save render time
143143
bool fastDraw = ( !usesTransparency()
144144
&& mRedBand > 0 && mGreenBand > 0 && mBlueBand > 0
145-
&& mAlphaBand < 1 && !mRedContrastEnhancement && !mGreenContrastEnhancement && !mBlueContrastEnhancement );
145+
&& mAlphaBand < 1 );
146146

147147
QSet<int> bands;
148148
if ( mRedBand > 0 )
@@ -239,6 +239,27 @@ QgsRasterBlock *QgsMultiBandColorRenderer::block( int bandNo, QgsRectangle cons
239239

240240
QRgb myDefaultColor = NODATA_COLOR;
241241

242+
if ( fastDraw )
243+
{
244+
// By default RGB raster layers have contrast enhancement assigned and normally that requires us to take the slow
245+
// route that applies the enhancement. However if the algorithm type is "no enhancement" and all input bands are byte-sized,
246+
// no transform would be applied to the input values and we can take the fast route.
247+
bool hasEnhancement;
248+
if ( hasByteRgb )
249+
{
250+
hasEnhancement =
251+
( mRedContrastEnhancement && mRedContrastEnhancement->contrastEnhancementAlgorithm() != QgsContrastEnhancement::NoEnhancement ) ||
252+
( mGreenContrastEnhancement && mGreenContrastEnhancement->contrastEnhancementAlgorithm() != QgsContrastEnhancement::NoEnhancement ) ||
253+
( mBlueContrastEnhancement && mBlueContrastEnhancement->contrastEnhancementAlgorithm() != QgsContrastEnhancement::NoEnhancement );
254+
}
255+
else
256+
{
257+
hasEnhancement = mRedContrastEnhancement || mGreenContrastEnhancement || mBlueContrastEnhancement;
258+
}
259+
if ( hasEnhancement )
260+
fastDraw = false;
261+
}
262+
242263
qgssize count = ( qgssize )width * height;
243264
for ( qgssize i = 0; i < count; i++ )
244265
{

0 commit comments

Comments
 (0)
Please sign in to comment.