Skip to content
Permalink
Browse files

[backport] Fix bug where histogram can be assigned negative frequency…

… for a pixel range. Also fix potential memory leak as new histogram vector was assigned to band stats without clearing the old.
  • Loading branch information
timlinux committed Jun 30, 2011
1 parent b2b6c5a commit 4888f51d54960b4e01a57b3a4bc8d50d38397c35
Showing with 11 additions and 3 deletions.
  1. +1 −1 src/core/raster/qgsrasterlayer.cpp
  2. +10 −2 src/providers/gdal/qgsgdalprovider.cpp
@@ -2440,7 +2440,7 @@ void QgsRasterLayer::setDataProvider( QString const & provider,
myRasterBandStats.bandName = mDataProvider->generateBandName( i );
myRasterBandStats.bandNumber = i;
myRasterBandStats.statsGathered = false;
myRasterBandStats.histogramVector = new QgsRasterBandStats::HistogramVector();
myRasterBandStats.histogramVector->clear();
//Store the default color table
//readColorTable( i, &myRasterBandStats.colorTable );
QList<QgsColorRampShader::ColorRampItem> ct;
@@ -1327,8 +1327,16 @@ void QgsGdalProvider::populateHistogram( int theBandNo, QgsRasterBandStats & t

for ( int myBin = 0; myBin < theBinCount; myBin++ )
{
theBandStats.histogramVector->push_back( myHistogramArray[myBin] );
QgsDebugMsg( "Added " + QString::number( myHistogramArray[myBin] ) + " to histogram vector" );
if ( myHistogramArray[myBin] < 0 ) //can't have less than 0 pixels of any value
{
theBandStats.histogramVector->push_back( 0 );
QgsDebugMsg( "Added 0 to histogram vector as freq was negative!" );
}
else
{
theBandStats.histogramVector->push_back( myHistogramArray[myBin] );
QgsDebugMsg( "Added " + QString::number( myHistogramArray[myBin] ) + " to histogram vector" );
}
}

}

0 comments on commit 4888f51

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