From 08b438b07684090e1a9b77f5ac9d152d4bec10c6 Mon Sep 17 00:00:00 2001 From: kgv Date: Wed, 6 Nov 2019 23:53:53 +0300 Subject: [PATCH] 0031138: Visualization - Image_AlienPixMap fails to load PNG image with palette Added fallback code converting unsupported pixel format into RGB24 using FreeImage itself. --- src/Image/Image_AlienPixMap.cxx | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/Image/Image_AlienPixMap.cxx b/src/Image/Image_AlienPixMap.cxx index 5d4d8a9b62..463bb9ca33 100644 --- a/src/Image/Image_AlienPixMap.cxx +++ b/src/Image/Image_AlienPixMap.cxx @@ -593,20 +593,34 @@ bool Image_AlienPixMap::Load (const Standard_Byte* theData, return false; } + Image_Format aFormat = Image_Format_UNKNOWN; if (FreeImage_GetBPP (anImage) == 1) { FIBITMAP* aTmpImage = FreeImage_ConvertTo8Bits (anImage); FreeImage_Unload (anImage); anImage = aTmpImage; } - - Image_Format aFormat = convertFromFreeFormat (FreeImage_GetImageType(anImage), - FreeImage_GetColorType(anImage), - FreeImage_GetBPP (anImage)); + if (anImage != NULL) + { + aFormat = convertFromFreeFormat (FreeImage_GetImageType(anImage), + FreeImage_GetColorType(anImage), + FreeImage_GetBPP (anImage)); + if (aFormat == Image_Format_UNKNOWN) + { + FIBITMAP* aTmpImage = FreeImage_ConvertTo24Bits (anImage); + FreeImage_Unload (anImage); + anImage = aTmpImage; + if (anImage != NULL) + { + aFormat = convertFromFreeFormat (FreeImage_GetImageType(anImage), + FreeImage_GetColorType(anImage), + FreeImage_GetBPP (anImage)); + } + } + } if (aFormat == Image_Format_UNKNOWN) { - //anImage = FreeImage_ConvertTo24Bits (anImage); - ::Message::DefaultMessenger()->Send ( TCollection_AsciiString ("Error: image '") + theImagePath + "' has unsupported pixel format.", + ::Message::DefaultMessenger()->Send (TCollection_AsciiString ("Error: image '") + theImagePath + "' has unsupported pixel format.", Message_Fail); return false; }