Skip to content

Commit cba5acb

Browse files
author
ersts
committed
-Fix a problem with generating the highest value of contrast enhancement 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/qgis@7953 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 06197e3 commit cba5acb

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

src/core/raster/qgscontrastenhancement.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ QgsContrastEnhancement::QgsContrastEnhancement(QgsRasterDataType theDataType)
4848
//If the data type is larger than 16-bit do not generate a lookup table
4949
if(mRasterDataTypeRange <= 65535.0)
5050
{
51-
mLookupTable = new int[static_cast <int>(mRasterDataTypeRange)];
51+
mLookupTable = new int[static_cast <int>(mRasterDataTypeRange+1)];
5252
}
5353

5454
}
@@ -175,8 +175,9 @@ bool QgsContrastEnhancement::generateLookupTable()
175175
QgsDebugMsg("***MinimumValue : "+ QString::number(mMinimumValue));
176176
QgsDebugMsg("***MaximumValue : "+ QString::number(mMaximumValue));
177177
QgsDebugMsg("***mLookupTableOffset : "+ QString::number(mLookupTableOffset));
178+
QgsDebugMsg("***mRasterDataTypeRange : "+ QString::number(mRasterDataTypeRange));
178179
#endif
179-
for(int myIterator = 0; myIterator < mRasterDataTypeRange; myIterator++)
180+
for(int myIterator = 0; myIterator <= mRasterDataTypeRange; myIterator++)
180181
{
181182
mLookupTable[myIterator] = mContrastEnhancementFunction->enhanceValue((double)myIterator - mLookupTableOffset);
182183
}

src/core/raster/qgsrasterlayer.cpp

+21-12
Original file line numberDiff line numberDiff line change
@@ -1443,9 +1443,14 @@ void QgsRasterLayer::drawSingleBandGray(QPainter * theQPainter, QgsRasterViewPor
14431443
}
14441444
else if(QgsContrastEnhancement::NO_STRETCH != getContrastEnhancementAlgorithm() && !mUserDefinedGrayMinMaxFlag)
14451445
{
1446-
myGrayBandStats = getRasterBandStats(theBandNo);
1447-
setMaximumValue(theBandNo, myGrayBandStats.maxVal);
1448-
setMinimumValue(theBandNo, myGrayBandStats.minVal);
1446+
//This case will be true the first time the image is loaded, so just approimate the min max to keep
1447+
//from calling generate raster band stats
1448+
double GDALrange[2];
1449+
GDALComputeRasterMinMax( myGdalBand, 1, GDALrange ); //Approximate
1450+
1451+
setMaximumValue(theBandNo, GDALrange[1]);
1452+
setMinimumValue(theBandNo, GDALrange[0]);
1453+
14491454
}
14501455

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

2085-
setMaximumValue(myRedBandNo, myRedBandStats.maxVal);
2086-
setMinimumValue(myRedBandNo, myRedBandStats.minVal);
2087-
setMaximumValue(myGreenBandNo, myGreenBandStats.maxVal);
2088-
setMinimumValue(myGreenBandNo, myGreenBandStats.minVal);
2089-
setMaximumValue(myBlueBandNo, myBlueBandStats.maxVal);
2090-
setMinimumValue(myBlueBandNo, myBlueBandStats.minVal);
2093+
GDALComputeRasterMinMax( myGdalGreenBand, 1, GDALrange ); //Approximate
2094+
setMaximumValue(myGreenBandNo, GDALrange[1]);
2095+
setMinimumValue(myGreenBandNo, GDALrange[0]);
2096+
2097+
GDALComputeRasterMinMax( myGdalBlueBand, 1, GDALrange ); //Approximate
2098+
setMaximumValue(myBlueBandNo, GDALrange[1]);
2099+
setMinimumValue(myBlueBandNo, GDALrange[0]);
20912100
}
20922101

20932102
//Read and display pixels

0 commit comments

Comments
 (0)