Skip to content
Permalink
Browse files

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.
  • Loading branch information
wonder-sk committed Jul 9, 2018
1 parent f6ab5f9 commit 73edd8fd730d5b34034e2efbf49b7ab757f0956d
Showing with 22 additions and 1 deletion.
  1. +22 −1 src/core/raster/qgsmultibandcolorrenderer.cpp
@@ -142,7 +142,7 @@ QgsRasterBlock *QgsMultiBandColorRenderer::block( int bandNo, QgsRectangle cons
//In some (common) cases, we can simplify the drawing loop considerably and save render time
bool fastDraw = ( !usesTransparency()
&& mRedBand > 0 && mGreenBand > 0 && mBlueBand > 0
&& mAlphaBand < 1 && !mRedContrastEnhancement && !mGreenContrastEnhancement && !mBlueContrastEnhancement );
&& mAlphaBand < 1 );

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

QRgb myDefaultColor = NODATA_COLOR;

if ( fastDraw )
{
// By default RGB raster layers have contrast enhancement assigned and normally that requires us to take the slow
// route that applies the enhancement. However if the algorithm type is "no enhancement" and all input bands are byte-sized,
// no transform would be applied to the input values and we can take the fast route.
bool hasEnhancement;
if ( hasByteRgb )
{
hasEnhancement =
( mRedContrastEnhancement && mRedContrastEnhancement->contrastEnhancementAlgorithm() != QgsContrastEnhancement::NoEnhancement ) ||
( mGreenContrastEnhancement && mGreenContrastEnhancement->contrastEnhancementAlgorithm() != QgsContrastEnhancement::NoEnhancement ) ||
( mBlueContrastEnhancement && mBlueContrastEnhancement->contrastEnhancementAlgorithm() != QgsContrastEnhancement::NoEnhancement );
}
else
{
hasEnhancement = mRedContrastEnhancement || mGreenContrastEnhancement || mBlueContrastEnhancement;
}
if ( hasEnhancement )
fastDraw = false;
}

qgssize count = ( qgssize )width * height;
for ( qgssize i = 0; i < count; i++ )
{

0 comments on commit 73edd8f

Please sign in to comment.
You can’t perform that action at this time.