Skip to content

Commit

Permalink
-Fix a problem with generating the highest value of contrast enhancem…
Browse files Browse the repository at this point in the history
…ent lookup table

-Added min max estimate on loading to prevent full raster stats from being generated to improve loading speed

git-svn-id: http://svn.osgeo.org/qgis/trunk@7953 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
ersts committed Jan 14, 2008
1 parent 4c31165 commit 5324435
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
5 changes: 3 additions & 2 deletions src/core/raster/qgscontrastenhancement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ QgsContrastEnhancement::QgsContrastEnhancement(QgsRasterDataType theDataType)
//If the data type is larger than 16-bit do not generate a lookup table
if(mRasterDataTypeRange <= 65535.0)
{
mLookupTable = new int[static_cast <int>(mRasterDataTypeRange)];
mLookupTable = new int[static_cast <int>(mRasterDataTypeRange+1)];
}

}
Expand Down Expand Up @@ -175,8 +175,9 @@ bool QgsContrastEnhancement::generateLookupTable()
QgsDebugMsg("***MinimumValue : "+ QString::number(mMinimumValue));
QgsDebugMsg("***MaximumValue : "+ QString::number(mMaximumValue));
QgsDebugMsg("***mLookupTableOffset : "+ QString::number(mLookupTableOffset));
QgsDebugMsg("***mRasterDataTypeRange : "+ QString::number(mRasterDataTypeRange));
#endif
for(int myIterator = 0; myIterator < mRasterDataTypeRange; myIterator++)
for(int myIterator = 0; myIterator <= mRasterDataTypeRange; myIterator++)
{
mLookupTable[myIterator] = mContrastEnhancementFunction->enhanceValue((double)myIterator - mLookupTableOffset);
}
Expand Down
33 changes: 21 additions & 12 deletions src/core/raster/qgsrasterlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1443,9 +1443,14 @@ void QgsRasterLayer::drawSingleBandGray(QPainter * theQPainter, QgsRasterViewPor
}
else if(QgsContrastEnhancement::NO_STRETCH != getContrastEnhancementAlgorithm() && !mUserDefinedGrayMinMaxFlag)
{
myGrayBandStats = getRasterBandStats(theBandNo);
setMaximumValue(theBandNo, myGrayBandStats.maxVal);
setMinimumValue(theBandNo, myGrayBandStats.minVal);
//This case will be true the first time the image is loaded, so just approimate the min max to keep
//from calling generate raster band stats
double GDALrange[2];
GDALComputeRasterMinMax( myGdalBand, 1, GDALrange ); //Approximate

setMaximumValue(theBandNo, GDALrange[1]);
setMinimumValue(theBandNo, GDALrange[0]);

}

QgsDebugMsg("Starting main render loop");
Expand Down Expand Up @@ -2078,16 +2083,20 @@ void QgsRasterLayer::drawMultiBandColor(QPainter * theQPainter, QgsRasterViewPor
}
else if(QgsContrastEnhancement::NO_STRETCH != getContrastEnhancementAlgorithm() && !mUserDefinedRGBMinMaxFlag)
{
myRedBandStats = getRasterBandStats(myRedBandNo);
myGreenBandStats = getRasterBandStats(myGreenBandNo);
myBlueBandStats = getRasterBandStats(myBlueBandNo);
//This case will be true the first time the image is loaded, so just approimate the min max to keep
//from calling generate raster band stats
double GDALrange[2];
GDALComputeRasterMinMax( myGdalRedBand, 1, GDALrange ); //Approximate
setMaximumValue(myRedBandNo, GDALrange[1]);
setMinimumValue(myRedBandNo, GDALrange[0]);

setMaximumValue(myRedBandNo, myRedBandStats.maxVal);
setMinimumValue(myRedBandNo, myRedBandStats.minVal);
setMaximumValue(myGreenBandNo, myGreenBandStats.maxVal);
setMinimumValue(myGreenBandNo, myGreenBandStats.minVal);
setMaximumValue(myBlueBandNo, myBlueBandStats.maxVal);
setMinimumValue(myBlueBandNo, myBlueBandStats.minVal);
GDALComputeRasterMinMax( myGdalGreenBand, 1, GDALrange ); //Approximate
setMaximumValue(myGreenBandNo, GDALrange[1]);
setMinimumValue(myGreenBandNo, GDALrange[0]);

GDALComputeRasterMinMax( myGdalBlueBand, 1, GDALrange ); //Approximate
setMaximumValue(myBlueBandNo, GDALrange[1]);
setMinimumValue(myBlueBandNo, GDALrange[0]);
}

//Read and display pixels
Expand Down

0 comments on commit 5324435

Please sign in to comment.