Skip to content

Commit 08293fd

Browse files
committedDec 18, 2011
set min/max values if available for single band, set StretchToMinimumMaximum if min/max are available for grayscale, fixes part of #4193 - GRASS rasters are drawn in gray
1 parent d848aa0 commit 08293fd

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
 

‎src/core/raster/qgsrasterlayer.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2353,6 +2353,14 @@ void QgsRasterLayer::setDataProvider( QString const & provider,
23532353
mRasterType = GrayOrUndefined;
23542354
}
23552355

2356+
// Set min/max values for single band if we have them ready (no need to calculate which is slow)
2357+
// don't set min/max on multiband even if available because it would cause stretch of bands and thus colors distortion
2358+
if ( mDataProvider->bandCount() == 1 && ( mDataProvider->capabilities() & QgsRasterDataProvider::ExactMinimumMaximum ) )
2359+
{
2360+
setMinimumValue( 1, mDataProvider->minimumValue( 1 ) );
2361+
setMaximumValue( 1, mDataProvider->maximumValue( 1 ) );
2362+
}
2363+
23562364
QgsDebugMsg( "mRasterType = " + QString::number( mRasterType ) );
23572365
if ( mRasterType == ColorLayer )
23582366
{
@@ -2434,6 +2442,14 @@ void QgsRasterLayer::setDataProvider( QString const & provider,
24342442
mDrawingStyle = SingleBandGray; //sensible default
24352443
mGrayBandName = bandName( 1 );
24362444

2445+
// If we have min/max available (without calculation), it is better to use StretchToMinimumMaximum
2446+
// TODO: in GUI there is 'Contrast enhancement - Default' which is overwritten here
2447+
// and that is confusing
2448+
if ( mDataProvider->capabilities() & QgsRasterDataProvider::ExactMinimumMaximum )
2449+
{
2450+
setContrastEnhancementAlgorithm( QgsContrastEnhancement::StretchToMinimumMaximum );
2451+
}
2452+
24372453
// read standard deviations
24382454
if ( mContrastEnhancementAlgorithm == QgsContrastEnhancement::StretchToMinimumMaximum )
24392455
{

0 commit comments

Comments
 (0)
Please sign in to comment.