assign correct raster type to the paletted raster with alpha band (fix #61283)

This commit is contained in:
Alexander Bruy 2025-09-18 13:32:53 +01:00 committed by Nyall Dawson
parent 127ff85935
commit 4b5129f940

View File

@ -809,18 +809,29 @@ void QgsRasterLayer::setDataProvider( QString const &provider, const QgsDataProv
}
else if ( bandCount == 2 )
{
// handle singleband gray with alpha
// handle singleband gray and paletted with alpha
auto colorInterpretationIsGrayOrUndefined = []( Qgis::RasterColorInterpretation interpretation )
{
return interpretation == Qgis::RasterColorInterpretation::GrayIndex
|| interpretation == Qgis::RasterColorInterpretation::Undefined;
};
auto colorInterpretationIsPaletted = []( Qgis::RasterColorInterpretation interpretation )
{
return interpretation == Qgis::RasterColorInterpretation::PaletteIndex
|| interpretation == Qgis::RasterColorInterpretation::ContinuousPalette;
};
if ( ( colorInterpretationIsGrayOrUndefined( mDataProvider->colorInterpretation( 1 ) ) && mDataProvider->colorInterpretation( 2 ) == Qgis::RasterColorInterpretation::AlphaBand )
|| ( mDataProvider->colorInterpretation( 1 ) == Qgis::RasterColorInterpretation::AlphaBand && colorInterpretationIsGrayOrUndefined( mDataProvider->colorInterpretation( 2 ) ) ) )
{
mRasterType = Qgis::RasterLayerType::GrayOrUndefined;
}
else if ( ( colorInterpretationIsPaletted( mDataProvider->colorInterpretation( 1 ) ) && mDataProvider->colorInterpretation( 2 ) == Qgis::RasterColorInterpretation::AlphaBand )
|| ( mDataProvider->colorInterpretation( 1 ) == Qgis::RasterColorInterpretation::AlphaBand && colorInterpretationIsPaletted( mDataProvider->colorInterpretation( 2 ) ) ) )
{
mRasterType = Qgis::RasterLayerType::Palette;
}
else
{
mRasterType = Qgis::RasterLayerType::MultiBand;