Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 authored and alexbruy committed Dec 19, 2011
1 parent f1b065b commit ccfd1af
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/core/raster/qgsrasterlayer.cpp
Expand Up @@ -2250,6 +2250,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 @@ -2331,6 +2339,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 ccfd1af

Please sign in to comment.