Skip to content
Permalink
Browse files
Merge pull request #4266 from nyalldawson/raster_proj
Avoid getting stuck in raster projector loop for long times
  • Loading branch information
nyalldawson committed Mar 17, 2017
2 parents 9887734 + 2dbb128 commit fa22fabec86d9686e7d8b06ea1fa80b312443567
@@ -110,33 +110,30 @@ QgsRasterBlock *QgsBrightnessContrastFilter::block( int bandNo, QgsRectangle co
Q_UNUSED( bandNo );
QgsDebugMsgLevel( QString( "width = %1 height = %2 extent = %3" ).arg( width ).arg( height ).arg( extent.toString() ), 4 );

QgsRasterBlock *outputBlock = new QgsRasterBlock();
std::unique_ptr< QgsRasterBlock > outputBlock( new QgsRasterBlock() );
if ( !mInput )
{
return outputBlock;
return outputBlock.release();
}

// At this moment we know that we read rendered image
int bandNumber = 1;
QgsRasterBlock *inputBlock = mInput->block( bandNumber, extent, width, height, feedback );
std::unique_ptr< QgsRasterBlock > inputBlock( mInput->block( bandNumber, extent, width, height, feedback ) );
if ( !inputBlock || inputBlock->isEmpty() )
{
QgsDebugMsg( "No raster data!" );
delete inputBlock;
return outputBlock;
return outputBlock.release();
}

if ( mBrightness == 0 && mContrast == 0 )
{
QgsDebugMsgLevel( "No brightness changes.", 4 );
delete outputBlock;
return inputBlock;
return inputBlock.release();
}

if ( !outputBlock->reset( Qgis::ARGB32_Premultiplied, width, height ) )
{
delete inputBlock;
return outputBlock;
return outputBlock.release();
}

// adjust image
@@ -164,8 +161,7 @@ QgsRasterBlock *QgsBrightnessContrastFilter::block( int bandNo, QgsRectangle co
outputBlock->setColor( i, qRgba( r, g, b, alpha ) );
}

delete inputBlock;
return outputBlock;
return outputBlock.release();
}

int QgsBrightnessContrastFilter::adjustColorComponent( int colorComponent, int alpha, int brightness, double contrastFactor ) const
@@ -31,7 +31,6 @@ class originally created circa 2004 by T.Sutton, Gary E.Sherman, Steve Halasz

QgsContrastEnhancement::QgsContrastEnhancement( Qgis::DataType dataType )
: mContrastEnhancementAlgorithm( NoEnhancement )
, mContrastEnhancementFunction( nullptr )
, mEnhancementDirty( false )
, mLookupTable( nullptr )
, mRasterDataType( dataType )
@@ -42,7 +41,7 @@ QgsContrastEnhancement::QgsContrastEnhancement( Qgis::DataType dataType )

mLookupTableOffset = mMinimumValue * -1;

mContrastEnhancementFunction = new QgsContrastEnhancementFunction( mRasterDataType, mMinimumValue, mMaximumValue );
mContrastEnhancementFunction.reset( new QgsContrastEnhancementFunction( mRasterDataType, mMinimumValue, mMaximumValue ) );

//If the data type is larger than 16-bit do not generate a lookup table
if ( mRasterDataTypeRange <= 65535.0 )
@@ -53,8 +52,7 @@ QgsContrastEnhancement::QgsContrastEnhancement( Qgis::DataType dataType )
}

QgsContrastEnhancement::QgsContrastEnhancement( const QgsContrastEnhancement &ce )
: mContrastEnhancementFunction( nullptr )
, mEnhancementDirty( true )
: mEnhancementDirty( true )
, mLookupTable( nullptr )
, mMinimumValue( ce.mMinimumValue )
, mMaximumValue( ce.mMaximumValue )
@@ -76,7 +74,6 @@ QgsContrastEnhancement::QgsContrastEnhancement( const QgsContrastEnhancement &ce
QgsContrastEnhancement::~QgsContrastEnhancement()
{
delete [] mLookupTable;
delete mContrastEnhancementFunction;
}
/*
*
@@ -249,23 +246,19 @@ void QgsContrastEnhancement::setContrastEnhancementAlgorithm( ContrastEnhancemen
switch ( algorithm )
{
case StretchToMinimumMaximum :
delete mContrastEnhancementFunction;
mContrastEnhancementFunction = new QgsLinearMinMaxEnhancement( mRasterDataType, mMinimumValue, mMaximumValue );
mContrastEnhancementFunction.reset( new QgsLinearMinMaxEnhancement( mRasterDataType, mMinimumValue, mMaximumValue ) );
break;
case StretchAndClipToMinimumMaximum :
delete mContrastEnhancementFunction;
mContrastEnhancementFunction = new QgsLinearMinMaxEnhancementWithClip( mRasterDataType, mMinimumValue, mMaximumValue );
mContrastEnhancementFunction.reset( new QgsLinearMinMaxEnhancementWithClip( mRasterDataType, mMinimumValue, mMaximumValue ) );
break;
case ClipToMinimumMaximum :
delete mContrastEnhancementFunction;
mContrastEnhancementFunction = new QgsClipToMinMaxEnhancement( mRasterDataType, mMinimumValue, mMaximumValue );
mContrastEnhancementFunction.reset( new QgsClipToMinMaxEnhancement( mRasterDataType, mMinimumValue, mMaximumValue ) );
break;
case UserDefinedEnhancement :
//Do nothing
break;
default:
delete mContrastEnhancementFunction;
mContrastEnhancementFunction = new QgsContrastEnhancementFunction( mRasterDataType, mMinimumValue, mMaximumValue );
mContrastEnhancementFunction.reset( new QgsContrastEnhancementFunction( mRasterDataType, mMinimumValue, mMaximumValue ) );
break;
}

@@ -289,8 +282,7 @@ void QgsContrastEnhancement::setContrastEnhancementFunction( QgsContrastEnhancem

if ( function )
{
delete mContrastEnhancementFunction;
mContrastEnhancementFunction = function;
mContrastEnhancementFunction.reset( function );
mContrastEnhancementAlgorithm = UserDefinedEnhancement;
generateLookupTable();
}
@@ -26,6 +26,7 @@ class originally created circa 2004 by T.Sutton, Gary E.Sherman, Steve Halasz

#include "qgis.h"
#include "qgsraster.h"
#include <memory>

class QgsContrastEnhancementFunction;
class QDomDocument;
@@ -120,7 +121,7 @@ class CORE_EXPORT QgsContrastEnhancement
ContrastEnhancementAlgorithm mContrastEnhancementAlgorithm;

//! \brief Pointer to the contrast enhancement function
QgsContrastEnhancementFunction *mContrastEnhancementFunction = nullptr;
std::unique_ptr< QgsContrastEnhancementFunction > mContrastEnhancementFunction;

//! \brief Flag indicating if the lookup table needs to be regenerated
bool mEnhancementDirty;
@@ -22,7 +22,7 @@
#include "qgsrasterinterface.h"
#include "qgsrasterblock.h"
#include "qgsrectangle.h"

#include <memory>

QgsHillshadeRenderer::QgsHillshadeRenderer( QgsRasterInterface *input, int band, double lightAzimuth, double lightAngle ):
QgsRasterRenderer( input, QStringLiteral( "hillshade" ) )
@@ -86,34 +86,30 @@ void QgsHillshadeRenderer::writeXml( QDomDocument &doc, QDomElement &parentElem
QgsRasterBlock *QgsHillshadeRenderer::block( int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback )
{
Q_UNUSED( bandNo );
QgsRasterBlock *outputBlock = new QgsRasterBlock();
std::unique_ptr< QgsRasterBlock > outputBlock( new QgsRasterBlock() );
if ( !mInput )
{
QgsDebugMsg( "No input raster!" );
return outputBlock;
return outputBlock.release();
}

QgsRasterBlock *inputBlock = mInput->block( mBand, extent, width, height, feedback );
std::shared_ptr< QgsRasterBlock > inputBlock( mInput->block( mBand, extent, width, height, feedback ) );

if ( !inputBlock || inputBlock->isEmpty() )
{
QgsDebugMsg( "No raster data!" );
delete inputBlock;
return outputBlock;
return outputBlock.release();
}

QgsRasterBlock *alphaBlock = nullptr;
std::shared_ptr< QgsRasterBlock > alphaBlock;

if ( mAlphaBand > 0 && mBand != mAlphaBand )
{

alphaBlock = mInput->block( mAlphaBand, extent, width, height, feedback );
alphaBlock.reset( mInput->block( mAlphaBand, extent, width, height, feedback ) );
if ( !alphaBlock || alphaBlock->isEmpty() )
{
// TODO: better to render without alpha
delete inputBlock;
delete alphaBlock;
return outputBlock;
return outputBlock.release();
}
}
else if ( mAlphaBand > 0 )
@@ -123,13 +119,9 @@ QgsRasterBlock *QgsHillshadeRenderer::block( int bandNo, const QgsRectangle &ext

if ( !outputBlock->reset( Qgis::ARGB32_Premultiplied, width, height ) )
{
delete inputBlock;
delete alphaBlock;
return outputBlock;
return outputBlock.release();
}



double cellXSize = extent.width() / double( width );
double cellYSize = extent.height() / double( height );
double zenithRad = qMax( 0.0, 90 - mLightAngle ) * M_PI / 180.0;
@@ -272,12 +264,7 @@ QgsRasterBlock *QgsHillshadeRenderer::block( int bandNo, const QgsRectangle &ext
}
}

delete inputBlock;
if ( mAlphaBand > 0 && mBand != mAlphaBand )
{
delete alphaBlock;
}
return outputBlock;
return outputBlock.release();
}

QList<int> QgsHillshadeRenderer::usesBands() const
@@ -119,33 +119,30 @@ QgsRasterBlock *QgsHueSaturationFilter::block( int bandNo, QgsRectangle const &
Q_UNUSED( bandNo );
QgsDebugMsgLevel( QString( "width = %1 height = %2 extent = %3" ).arg( width ).arg( height ).arg( extent.toString() ), 4 );

QgsRasterBlock *outputBlock = new QgsRasterBlock();
std::unique_ptr< QgsRasterBlock > outputBlock( new QgsRasterBlock() );
if ( !mInput )
{
return outputBlock;
return outputBlock.release();
}

// At this moment we know that we read rendered image
int bandNumber = 1;
QgsRasterBlock *inputBlock = mInput->block( bandNumber, extent, width, height, feedback );
std::unique_ptr< QgsRasterBlock > inputBlock( mInput->block( bandNumber, extent, width, height, feedback ) );
if ( !inputBlock || inputBlock->isEmpty() )
{
QgsDebugMsg( "No raster data!" );
delete inputBlock;
return outputBlock;
return outputBlock.release();
}

if ( mSaturation == 0 && mGrayscaleMode == GrayscaleOff && !mColorizeOn )
{
QgsDebugMsgLevel( "No hue/saturation change.", 4 );
delete outputBlock;
return inputBlock;
return inputBlock.release();
}

if ( !outputBlock->reset( Qgis::ARGB32_Premultiplied, width, height ) )
{
delete inputBlock;
return outputBlock;
return outputBlock.release();
}

// adjust image
@@ -216,8 +213,7 @@ QgsRasterBlock *QgsHueSaturationFilter::block( int bandNo, QgsRectangle const &
outputBlock->setColor( i, qRgba( r, g, b, alpha ) );
}

delete inputBlock;
return outputBlock;
return outputBlock.release();
}

// Process a colorization and update resultant HSL & RGB values
@@ -133,10 +133,10 @@ QgsRasterRenderer *QgsMultiBandColorRenderer::create( const QDomElement &elem, Q
QgsRasterBlock *QgsMultiBandColorRenderer::block( int bandNo, QgsRectangle const &extent, int width, int height, QgsRasterBlockFeedback *feedback )
{
Q_UNUSED( bandNo );
QgsRasterBlock *outputBlock = new QgsRasterBlock();
std::unique_ptr< QgsRasterBlock > outputBlock( new QgsRasterBlock() );
if ( !mInput )
{
return outputBlock;
return outputBlock.release();
}

//In some (common) cases, we can simplify the drawing loop considerably and save render time
@@ -161,7 +161,7 @@ QgsRasterBlock *QgsMultiBandColorRenderer::block( int bandNo, QgsRectangle cons
{
// no need to draw anything if no band is set
// TODO:: we should probably return default color block
return outputBlock;
return outputBlock.release();
}

if ( mAlphaBand > 0 )
@@ -195,7 +195,7 @@ QgsRasterBlock *QgsMultiBandColorRenderer::block( int bandNo, QgsRectangle cons
{
delete bandBlocks[*bandIt];
}
return outputBlock;
return outputBlock.release();
}
}

@@ -222,7 +222,7 @@ QgsRasterBlock *QgsMultiBandColorRenderer::block( int bandNo, QgsRectangle cons
{
delete bandBlocks.value( i );
}
return outputBlock;
return outputBlock.release();
}

QRgb myDefaultColor = NODATA_COLOR;
@@ -323,7 +323,7 @@ QgsRasterBlock *QgsMultiBandColorRenderer::block( int bandNo, QgsRectangle cons
delete bandDelIt.value();
}

return outputBlock;
return outputBlock.release();
}

void QgsMultiBandColorRenderer::writeXml( QDomDocument &doc, QDomElement &parentElem ) const
@@ -73,7 +73,7 @@ QgsRasterBlock *QgsRasterNuller::block( int bandNo, QgsRectangle const &extent,
return new QgsRasterBlock();
}

QgsRasterBlock *inputBlock = mInput->block( bandNo, extent, width, height, feedback );
std::unique_ptr< QgsRasterBlock > inputBlock( mInput->block( bandNo, extent, width, height, feedback ) );
if ( !inputBlock )
{
return new QgsRasterBlock();
@@ -82,10 +82,10 @@ QgsRasterBlock *QgsRasterNuller::block( int bandNo, QgsRectangle const &extent,
// We don't support nuller for color types
if ( QgsRasterBlock::typeIsColor( inputBlock->dataType() ) )
{
return inputBlock;
return inputBlock.release();
}

QgsRasterBlock *outputBlock = new QgsRasterBlock( inputBlock->dataType(), width, height );
std::unique_ptr< QgsRasterBlock > outputBlock( new QgsRasterBlock( inputBlock->dataType(), width, height ) );
if ( mHasOutputNoData.value( bandNo - 1 ) || inputBlock->hasNoDataValue() )
{
double noDataValue;
@@ -122,8 +122,6 @@ QgsRasterBlock *QgsRasterNuller::block( int bandNo, QgsRectangle const &extent,
}
}
}
delete inputBlock;

return outputBlock;
return outputBlock.release();
}

0 comments on commit fa22fab

Please sign in to comment.