File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed
Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff 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 {
You can’t perform that action at this time.
0 commit comments