Ignore non-fatal libJPEGTurbo decode warnings / errors
[platform/core/uifw/dali-adaptor.git] / platform-abstractions / tizen / image-loaders / loader-jpeg-turbo.cpp
index b567b6a..455d1f7 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
   {
@@ -255,7 +270,7 @@ bool LoadBitmapFromJpeg( const ResourceLoadingClient& client, const ImageLoader:
   // Pull the compressed JPEG image bytes out of a file and into memory:
   if( fread( jpegBufferPtr, 1, jpegBufferSize, fp ) != jpegBufferSize )
   {
-    DALI_LOG_WARNING("Error on image file read.");
+    DALI_LOG_WARNING("Error on image file read.\n");
     return false;
   }
 
@@ -297,7 +312,7 @@ bool LoadBitmapFromJpeg( const ResourceLoadingClient& client, const ImageLoader:
 
   if(preXformImageWidth == 0 || preXformImageHeight == 0)
   {
-    DALI_LOG_WARNING("Invalid Image!");
+    DALI_LOG_WARNING("Invalid Image!\n");
     return false;
   }
 
@@ -332,8 +347,17 @@ bool LoadBitmapFromJpeg( const ResourceLoadingClient& client, const ImageLoader:
 
   if( tjDecompress2( autoJpg.GetHandle(), jpegBufferPtr, jpegBufferSize, bitmapPixelBuffer, scaledPreXformWidth, 0, scaledPreXformHeight, DECODED_PIXEL_LIBJPEG_TYPE, flags ) == -1 )
   {
-    DALI_LOG_ERROR("%s\n", tjGetErrorStr());
-    return false;
+    std::string errorString = tjGetErrorStr();
+
+    if( IsJpegErrorFatal( errorString ) )
+    {
+        DALI_LOG_ERROR("%s\n", errorString.c_str());
+        return false;
+    }
+    else
+    {
+        DALI_LOG_WARNING("%s\n", errorString.c_str());
+    }
   }
 
   const unsigned int  bufferWidth  = GetTextureDimension( scaledPreXformWidth );
@@ -539,7 +563,7 @@ bool EncodeToJpeg( const unsigned char* const pixelBuffer, Vector< unsigned char
     }
     default:
     {
-      DALI_LOG_ERROR( "Unsupported pixel format for encoding to JPEG." );
+      DALI_LOG_ERROR( "Unsupported pixel format for encoding to JPEG.\n" );
       return false;
     }
   }
@@ -640,7 +664,7 @@ JPGFORM_CODE ConvertExifOrientation(ExifData* exifData)
       default:
       {
         // Try to keep loading the file, but let app developer know there was something fishy:
-        DALI_LOG_WARNING( "Incorrect/Unknown Orientation setting found in EXIF header of JPEG image (%x). Orientation setting will be ignored.", entry );
+        DALI_LOG_WARNING( "Incorrect/Unknown Orientation setting found in EXIF header of JPEG image (%x). Orientation setting will be ignored.\n", entry );
         break;
       }
     }
@@ -675,7 +699,7 @@ bool TransformSize( int requiredWidth, int requiredHeight,
   tjscalingfactor* factors = tjGetScalingFactors( &numFactors );
   if( factors == NULL )
   {
-    DALI_LOG_WARNING("TurboJpeg tjGetScalingFactors error!");
+    DALI_LOG_WARNING("TurboJpeg tjGetScalingFactors error!\n");
     success = false;
   }
   else