Skip to content
Permalink
Browse files

Faster draw for multiband color in case there is no transparency, str…

…ech, inversion
  • Loading branch information
mhugent committed Jan 28, 2012
1 parent 91c37fb commit 3b36620c49dfb33176f6f32db5a4db65d30e2292
@@ -18,6 +18,7 @@
#include "qgsmultibandcolorrenderer.h"
#include "qgscontrastenhancement.h"
#include "qgsrastertransparency.h"
#include "qgsrasterviewport.h"
#include <QImage>
#include <QSet>

@@ -41,6 +42,13 @@ void QgsMultiBandColorRenderer::draw( QPainter* p, QgsRasterViewPort* viewPort,
return;
}

//In some (common) cases, we can simplify the drawing loop considerably and save render time
bool fastDraw = (
!usesTransparency( viewPort->mSrcCRS, viewPort->mDestCRS )
&& mRedBand > 0 && mGreenBand > 0 && mBlueBand > 0
&& mAlphaBand < 1 && !mRedContrastEnhancement && !mGreenContrastEnhancement && !mBlueContrastEnhancement
&& !mInvertColor );

QgsRasterDataProvider::DataType redType;
if ( mRedBand > 0 )
{
@@ -155,15 +163,26 @@ void QgsMultiBandColorRenderer::draw( QPainter* p, QgsRasterViewPort* viewPort,
imageScanLine = ( QRgb* )( img.scanLine( i ) );
for ( int j = 0; j < nRasterCols; ++j )
{
if ( mRedBand )

if ( fastDraw ) //fast rendering if no transparency, stretching, color inversion, etc.
{
redVal = readValue( redData, redType, currentRasterPos );
greenVal = readValue( greenData, greenType, currentRasterPos );
blueVal = readValue( blueData, blueType, currentRasterPos );
imageScanLine[j] = qRgba( redVal, greenVal, blueVal, 255 );
++currentRasterPos;
continue;
}

if ( mRedBand > 0 )
{
redVal = readValue( redData, redType, currentRasterPos );
}
if ( mGreenBand )
if ( mGreenBand > 0 )
{
greenVal = readValue( greenData, greenType, currentRasterPos );
}
if ( mBlueBand )
if ( mBlueBand > 0 )
{
blueVal = readValue( blueData, blueType, currentRasterPos );
}
@@ -693,21 +693,30 @@ void QgsRasterLayer::setRendererForDrawingStyle( const DrawingStyle & theDrawin
if ( mRedBandName != TRSTRING_NOT_SET )
{
red = bandNumber( mRedBandName );
redEnhancement = contrastEnhancement( red );
if ( contrastEnhancementAlgorithm() != QgsContrastEnhancement::NoEnhancement )
{
redEnhancement = contrastEnhancement( red );
}
}
int green = -1;
QgsContrastEnhancement* greenEnhancement = 0;
if ( mGreenBandName != TRSTRING_NOT_SET )
{
green = bandNumber( mGreenBandName );
greenEnhancement = contrastEnhancement( green );
if ( contrastEnhancementAlgorithm() != QgsContrastEnhancement::NoEnhancement )
{
greenEnhancement = contrastEnhancement( green );
}
}
int blue = -1;
QgsContrastEnhancement* blueEnhancement = 0;
if ( mBlueBandName != TRSTRING_NOT_SET )
{
blue = bandNumber( mBlueBandName );
blueEnhancement = contrastEnhancement( blue );
if ( contrastEnhancementAlgorithm() != QgsContrastEnhancement::NoEnhancement )
{
blueEnhancement = contrastEnhancement( blue );
}
}
renderer = new QgsMultiBandColorRenderer( mDataProvider, red, green, blue,
redEnhancement, greenEnhancement, blueEnhancement );
@@ -177,6 +177,6 @@ bool QgsRasterTransparency::isEmpty( double nodataValue ) const
( mTransparentSingleValuePixelList.size() == 1 && doubleNear( mTransparentSingleValuePixelList.at( 0 ).pixelValue, nodataValue ) ) )
&&
( mTransparentThreeValuePixelList.isEmpty() ||
( mTransparentThreeValuePixelList.size() == 1 && doubleNear( mTransparentThreeValuePixelList.at( 0 ).red, nodataValue ) &&
( mTransparentThreeValuePixelList.size() < 4 && doubleNear( mTransparentThreeValuePixelList.at( 0 ).red, nodataValue ) &&
doubleNear( mTransparentThreeValuePixelList.at( 0 ).green, nodataValue ) && doubleNear( mTransparentThreeValuePixelList.at( 0 ).blue, nodataValue ) ) ) );
}

0 comments on commit 3b36620

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