Skip to content
Permalink
Browse files
set min/max values if available for single band, set StretchToMinimum…
…Maximum if min/max are available for grayscale, fixes part of #4193 - GRASS rasters are drawn in gray
  • Loading branch information
blazek committed Dec 18, 2011
1 parent d848aa0 commit 08293fd456fca032704d8e3571a51a37ed9aed74
Showing with 16 additions and 0 deletions.
  1. +16 −0 src/core/raster/qgsrasterlayer.cpp
@@ -2353,6 +2353,14 @@ void QgsRasterLayer::setDataProvider( QString const & provider,
mRasterType = GrayOrUndefined;
}

// Set min/max values for single band if we have them ready (no need to calculate which is slow)
// don't set min/max on multiband even if available because it would cause stretch of bands and thus colors distortion
if ( mDataProvider->bandCount() == 1 && ( mDataProvider->capabilities() & QgsRasterDataProvider::ExactMinimumMaximum ) )
{
setMinimumValue( 1, mDataProvider->minimumValue( 1 ) );
setMaximumValue( 1, mDataProvider->maximumValue( 1 ) );
}

QgsDebugMsg( "mRasterType = " + QString::number( mRasterType ) );
if ( mRasterType == ColorLayer )
{
@@ -2434,6 +2442,14 @@ void QgsRasterLayer::setDataProvider( QString const & provider,
mDrawingStyle = SingleBandGray; //sensible default
mGrayBandName = bandName( 1 );

// If we have min/max available (without calculation), it is better to use StretchToMinimumMaximum
// TODO: in GUI there is 'Contrast enhancement - Default' which is overwritten here
// and that is confusing
if ( mDataProvider->capabilities() & QgsRasterDataProvider::ExactMinimumMaximum )
{
setContrastEnhancementAlgorithm( QgsContrastEnhancement::StretchToMinimumMaximum );
}

// read standard deviations
if ( mContrastEnhancementAlgorithm == QgsContrastEnhancement::StretchToMinimumMaximum )
{

0 comments on commit 08293fd

Please sign in to comment.