Skip to content

Commit

Permalink
[Raster] Do not crash when displaying a raster with complex datatype (f…
Browse files Browse the repository at this point in the history
…ixes #16405)

That said, complex datatypes are not handled, so QGIS cannot do anything useful
with such datasets.
  • Loading branch information
rouault committed Nov 14, 2017
1 parent 020972c commit b861db4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/core/raster/qgscontrastenhancement.cpp
Expand Up @@ -175,7 +175,10 @@ int QgsContrastEnhancement::enhanceContrast( double value )

if ( mLookupTable && NoEnhancement != mContrastEnhancementAlgorithm )
{
return mLookupTable[static_cast <int>( value + mLookupTableOffset )];
double shiftedValue = value + mLookupTableOffset;
if ( shiftedValue >= 0 && shiftedValue < mRasterDataTypeRange + 1 )
return mLookupTable[static_cast <int>( shiftedValue )];
return 0;
}
else
{
Expand Down
3 changes: 2 additions & 1 deletion src/core/raster/qgscontrastenhancementfunction.cpp
Expand Up @@ -50,7 +50,8 @@ int QgsContrastEnhancementFunction::enhance( double value )
bool QgsContrastEnhancementFunction::isValueInDisplayableRange( double value )
{
//A default check is to see if the provided value is with the range for the data type
return !( value < QgsContrastEnhancement::minimumValuePossible( mQgsRasterDataType ) || value > QgsContrastEnhancement::maximumValuePossible( mQgsRasterDataType ) );
// Write the test as ( v >= min && v <= max ) so that v = NaN returns false
return value >= QgsContrastEnhancement::minimumValuePossible( mQgsRasterDataType ) && value <= QgsContrastEnhancement::maximumValuePossible( mQgsRasterDataType );
}

void QgsContrastEnhancementFunction::setMaximumValue( double value )
Expand Down

0 comments on commit b861db4

Please sign in to comment.