Skip to content

Commit ccfd1af

Browse files
blazekalexbruy
authored andcommitted
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 f1b065b commit ccfd1af

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
@@ -2250,6 +2250,14 @@ void QgsRasterLayer::setDataProvider( QString const & provider,
22502250
mRasterType = GrayOrUndefined;
22512251
}
22522252

2253+
// Set min/max values for single band if we have them ready (no need to calculate which is slow)
2254+
// don't set min/max on multiband even if available because it would cause stretch of bands and thus colors distortion
2255+
if ( mDataProvider->bandCount() == 1 && ( mDataProvider->capabilities() & QgsRasterDataProvider::ExactMinimumMaximum ) )
2256+
{
2257+
setMinimumValue( 1, mDataProvider->minimumValue( 1 ) );
2258+
setMaximumValue( 1, mDataProvider->maximumValue( 1 ) );
2259+
}
2260+
22532261
QgsDebugMsg( "mRasterType = " + QString::number( mRasterType ) );
22542262
if ( mRasterType == ColorLayer )
22552263
{
@@ -2331,6 +2339,14 @@ void QgsRasterLayer::setDataProvider( QString const & provider,
23312339
mDrawingStyle = SingleBandGray; //sensible default
23322340
mGrayBandName = bandName( 1 );
23332341

2342+
// If we have min/max available (without calculation), it is better to use StretchToMinimumMaximum
2343+
// TODO: in GUI there is 'Contrast enhancement - Default' which is overwritten here
2344+
// and that is confusing
2345+
if ( mDataProvider->capabilities() & QgsRasterDataProvider::ExactMinimumMaximum )
2346+
{
2347+
setContrastEnhancementAlgorithm( QgsContrastEnhancement::StretchToMinimumMaximum );
2348+
}
2349+
23342350
// read standard deviations
23352351
if ( mContrastEnhancementAlgorithm == QgsContrastEnhancement::StretchToMinimumMaximum )
23362352
{

0 commit comments

Comments
 (0)