Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Histogram: set an hard limit to bin count
(cherry picked from commit 67af97b)
  • Loading branch information
elpaso authored and nyalldawson committed Jul 21, 2020
1 parent 7bc73e4 commit 4e8b765
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/core/raster/qgsrasterinterface.cpp
Expand Up @@ -336,7 +336,7 @@ void QgsRasterInterface::initHistogram( QgsRasterHistogram &histogram,
}
QgsDebugMsgLevel( QStringLiteral( "theHistogram.width = %1 histogram.height = %2" ).arg( histogram.width ).arg( histogram.height ), 4 );

int myBinCount = binCount;
long myBinCount = binCount;
if ( myBinCount == 0 )
{
// TODO: this was OK when stats/histogram were calced in provider,
Expand All @@ -359,16 +359,17 @@ void QgsRasterInterface::initHistogram( QgsRasterHistogram &histogram,
mySrcDataType == Qgis::Int16 || mySrcDataType == Qgis::Int32 ||
mySrcDataType == Qgis::UInt16 || mySrcDataType == Qgis::UInt32 ) )
{
myBinCount = std::min( histogram.width * histogram.height, static_cast<int>( std::ceil( histogram.maximum - histogram.minimum + 1 ) ) );
myBinCount = std::min( static_cast<long>( histogram.width ) * static_cast<long>( histogram.height ), static_cast<long>( std::ceil( histogram.maximum - histogram.minimum + 1 ) ) );
}
else
{
// This is for not integer types where we cannot limit the bin size
myBinCount = histogram.width * histogram.height;
// This is for not integer types
myBinCount = static_cast<long>( histogram.width ) * static_cast<long>( histogram.height );
}
}
}
histogram.binCount = myBinCount;
// Hard limit 10'000'000
histogram.binCount = static_cast<int>( std::min( 10000000L, myBinCount ) );
QgsDebugMsgLevel( QStringLiteral( "theHistogram.binCount = %1" ).arg( histogram.binCount ), 4 );
}

Expand Down

0 comments on commit 4e8b765

Please sign in to comment.