0031138: Visualization - Image_AlienPixMap fails to load PNG image with palette
authorkgv <kgv@opencascade.com>
Wed, 6 Nov 2019 20:53:53 +0000 (23:53 +0300)
committerbugmaster <bugmaster@opencascade.com>
Thu, 7 Nov 2019 17:19:38 +0000 (20:19 +0300)
Added fallback code converting unsupported pixel format into RGB24 using FreeImage itself.

src/Image/Image_AlienPixMap.cxx

index 5d4d8a9..463bb9c 100644 (file)
@@ -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;
   }