Skip to content

Commit ff683a6

Browse files
committed
[Raster] Do not crash when displaying a raster with complex datatype (fixes #16405)
That said, complex datatypes are not handled, so QGIS cannot do anything useful with such datasets.
1 parent 86247cf commit ff683a6

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

src/core/raster/qgscontrastenhancement.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,10 @@ int QgsContrastEnhancement::enhanceContrast( double theValue )
180180

181181
if ( mLookupTable && NoEnhancement != mContrastEnhancementAlgorithm )
182182
{
183-
return mLookupTable[static_cast <int>( theValue + mLookupTableOffset )];
183+
double shiftedValue = theValue + mLookupTableOffset;
184+
if ( shiftedValue >= 0 && shiftedValue < mRasterDataTypeRange + 1 )
185+
return mLookupTable[static_cast <int>( shiftedValue )];
186+
return 0;
184187
}
185188
else
186189
{

src/core/raster/qgscontrastenhancementfunction.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,8 @@ int QgsContrastEnhancementFunction::enhance( double theValue )
4949
bool QgsContrastEnhancementFunction::isValueInDisplayableRange( double theValue )
5050
{
5151
//A default check is to see if the provided value is with the range for the data type
52-
if ( theValue < QgsContrastEnhancement::minimumValuePossible( mQgsRasterDataType ) || theValue > QgsContrastEnhancement::maximumValuePossible( mQgsRasterDataType ) )
53-
{
54-
return false;
55-
}
56-
57-
return true;
52+
// Write the test as ( v >= min && v <= max ) so that v = NaN returns false
53+
return theValue >= QgsContrastEnhancement::minimumValuePossible( mQgsRasterDataType ) && theValue <= QgsContrastEnhancement::maximumValuePossible( mQgsRasterDataType );
5854
}
5955

6056
void QgsContrastEnhancementFunction::setMaximumValue( double theValue )

0 commit comments

Comments
 (0)