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 86247cf commit ff683a6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/core/raster/qgscontrastenhancement.cpp
Expand Up @@ -180,7 +180,10 @@ int QgsContrastEnhancement::enhanceContrast( double theValue )

if ( mLookupTable && NoEnhancement != mContrastEnhancementAlgorithm )
{
return mLookupTable[static_cast <int>( theValue + mLookupTableOffset )];
double shiftedValue = theValue + mLookupTableOffset;
if ( shiftedValue >= 0 && shiftedValue < mRasterDataTypeRange + 1 )
return mLookupTable[static_cast <int>( shiftedValue )];
return 0;
}
else
{
Expand Down
8 changes: 2 additions & 6 deletions src/core/raster/qgscontrastenhancementfunction.cpp
Expand Up @@ -49,12 +49,8 @@ int QgsContrastEnhancementFunction::enhance( double theValue )
bool QgsContrastEnhancementFunction::isValueInDisplayableRange( double theValue )
{
//A default check is to see if the provided value is with the range for the data type
if ( theValue < QgsContrastEnhancement::minimumValuePossible( mQgsRasterDataType ) || theValue > QgsContrastEnhancement::maximumValuePossible( mQgsRasterDataType ) )
{
return false;
}

return true;
// Write the test as ( v >= min && v <= max ) so that v = NaN returns false
return theValue >= QgsContrastEnhancement::minimumValuePossible( mQgsRasterDataType ) && theValue <= QgsContrastEnhancement::maximumValuePossible( mQgsRasterDataType );
}

void QgsContrastEnhancementFunction::setMaximumValue( double theValue )
Expand Down

0 comments on commit ff683a6

Please sign in to comment.