Skip to content

Commit

Permalink
set min/max values if available for single band, set StretchToMinimum…
Browse files Browse the repository at this point in the history
…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 08293fd
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/core/raster/qgsrasterlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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 )
{
Expand Down

0 comments on commit 08293fd

Please sign in to comment.