[3.0] Ignore non-fatal libJPEGTurbo decode warnings / errors 52/127952/1
authorNick Holland <nick.holland@partner.samsung.com>
Tue, 2 May 2017 13:42:19 +0000 (14:42 +0100)
committerNick Holland <nick.holland@partner.samsung.com>
Tue, 2 May 2017 14:56:27 +0000 (15:56 +0100)
Currently a JPEG has been found that gives a "Invalid SOS parameters for sequential JPEG" but the JPEG should still be loaded.

Some history:

https://github.com/libjpeg-turbo/libjpeg-turbo/issues/113

Extends a previous patch
https://review.tizen.org/gerrit/#/c/62384/1

Change-Id: Ie1fa3d8930400d7e896bac24ecb3924fa4348c87

platform-abstractions/tizen/image-loaders/loader-jpeg-turbo.cpp

index 5f130c7..5e1b711 100755 (executable)
@@ -93,6 +93,21 @@ namespace
     /* Stop libjpeg from printing to stderr - Do Nothing */
   }
 
+  /**
+   * LibJPEG Turbo tjDecompress2 API doesn't distinguish between errors that still allow
+   * the JPEG to be displayed and fatal errors.
+   */
+  bool IsJpegErrorFatal( const std::string& errorMessage )
+  {
+    if( ( errorMessage.find("Corrupt JPEG data") != std::string::npos ) ||
+        ( errorMessage.find("Invalid SOS parameters") != std::string::npos ) )
+    {
+      return false;
+    }
+    return true;
+  }
+
+
   /** Simple struct to ensure xif data is deleted. */
   struct ExifAutoPtr
   {
@@ -334,7 +349,7 @@ bool LoadBitmapFromJpeg( const ResourceLoadingClient& client, const ImageLoader:
   {
     std::string errorString = tjGetErrorStr();
 
-    if( errorString.find("Corrupt JPEG data") == std::string::npos )
+    if( IsJpegErrorFatal( errorString ) )
     {
       DALI_LOG_ERROR("%s\n", errorString.c_str());
       return false;
@@ -343,10 +358,6 @@ bool LoadBitmapFromJpeg( const ResourceLoadingClient& client, const ImageLoader:
     {
       DALI_LOG_WARNING("%s\n", errorString.c_str());
     }
-
-    //TurboJPEG API functions will now return an error code if a warning is triggered in the underlying libjpeg API.
-    //So, we need to distinguish return of tjGetErrorStr() is warning or error.
-    //If the return string has 'Corrupt JPEG data' prefix, it means warning.
   }
 
   const unsigned int  bufferWidth  = GetTextureDimension( scaledPreXformWidth );