Revert "[Tizen] Webp-loading, Fix svace issue and change the way to get animation...
authorJaehyun Cho <jae_hyun.cho@samsung.com>
Thu, 21 Apr 2022 09:19:26 +0000 (18:19 +0900)
committerJaehyun Cho <jae_hyun.cho@samsung.com>
Thu, 21 Apr 2022 09:19:26 +0000 (18:19 +0900)
This reverts commit ef857a5e021fed9b1b36fb35b1cfb1be414b5b66.

dali/internal/imaging/common/webp-loading.cpp

index a5b8dab..0cb8932 100644 (file)
@@ -113,30 +113,12 @@ public:
     // mFrameCount will be 1 if the input image is non-animated image or animated image with single frame.
     if(DALI_LIKELY(ReadWebPInformation()))
     {
-#ifdef DALI_WEBP_AVAILABLE
-      WebPDataInit(&mWebPData);
-      mWebPData.size  = mBufferSize;
-      mWebPData.bytes = mBuffer;
-
-      WebPDemuxer* demuxer = WebPDemux(&mWebPData);
-      uint32_t flags = WebPDemuxGetI(demuxer, WEBP_FF_FORMAT_FLAGS);
-      if(flags & ANIMATION_FLAG)
-      {
-        mIsAnimatedImage = true;
-      }
-
-      if(!mIsAnimatedImage)
-      {
-        int32_t imageWidth, imageHeight;
-        if(WebPGetInfo(mBuffer, mBufferSize, &imageWidth, &imageHeight))
-        {
-          mImageSize = ImageDimensions(imageWidth, imageHeight);
-        }
-      }
-#endif
 #ifdef DALI_ANIMATED_WEBP_ENABLED
       if(mIsAnimatedImage)
       {
+        WebPDataInit(&mWebPData);
+        mWebPData.size  = mBufferSize;
+        mWebPData.bytes = mBuffer;
         WebPAnimDecoderOptions webPAnimDecoderOptions;
         WebPAnimDecoderOptionsInit(&webPAnimDecoderOptions);
         webPAnimDecoderOptions.color_mode = MODE_RGBA;
@@ -147,6 +129,16 @@ public:
         mImageSize  = ImageDimensions(mWebPAnimInfo.canvas_width, mWebPAnimInfo.canvas_height);
       }
 #endif
+#ifdef DALI_WEBP_AVAILABLE
+      if(!mIsAnimatedImage)
+      {
+        int32_t imageWidth, imageHeight;
+        if(WebPGetInfo(mBuffer, mBufferSize, &imageWidth, &imageHeight))
+        {
+          mImageSize = ImageDimensions(imageWidth, imageHeight);
+        }
+      }
+#endif
       mLoadSucceeded = true;
     }
     else
@@ -186,14 +178,32 @@ public:
         }
       }
 
-      if(fileReader)
-      {
-        fp = fileReader->GetFile();
-      }
+      fp = fileReader->GetFile();
     }
 
     if(DALI_LIKELY(fp != nullptr))
     {
+      if(DALI_LIKELY(!fseek(fp, 12, SEEK_SET)))
+      {
+        uint8_t mHeaderBuffer[5];
+        fread(mHeaderBuffer, sizeof(WebPByteType), 5, fp);
+        unsigned char VP8X[4]    = {'V', 'P', '8', 'X'};
+        bool          isExtended = true;
+        for(uint32_t i = 0; i < 4; ++i)
+        {
+          if(mHeaderBuffer[i] != VP8X[i])
+          {
+            isExtended = false;
+            break;
+          }
+        }
+        if(isExtended)
+        {
+          unsigned char extension = mHeaderBuffer[4];
+          mIsAnimatedImage        = ((extension >> 1) & 1) ? true : false;
+        }
+      }
+
       if(mBufferSize == 0)
       {
         if(DALI_UNLIKELY(fseek(fp, 0, SEEK_END) <= -1))
@@ -215,16 +225,14 @@ public:
 
   void ReleaseResource()
   {
-#ifdef DALI_WEBP_AVAILABLE
-    if(&mWebPData != nullptr)
-    {
-      mWebPData.bytes = nullptr;
-      WebPDataInit(&mWebPData);
-    }
-#endif
 #ifdef DALI_ANIMATED_WEBP_ENABLED
     if(mIsAnimatedImage)
     {
+      if(&mWebPData != nullptr)
+      {
+        mWebPData.bytes = nullptr;
+        WebPDataInit(&mWebPData);
+      }
       if(mWebPAnimDecoder != nullptr)
       {
         WebPAnimDecoderDelete(mWebPAnimDecoder);
@@ -265,11 +273,8 @@ public:
   bool            mIsAnimatedImage;
   bool            mIsLocalResource;
 
-#ifdef DALI_WEBP_AVAILABLE
-  WebPData                 mWebPData{0};
-#endif
-
 #ifdef DALI_ANIMATED_WEBP_ENABLED
+  WebPData                 mWebPData{0};
   WebPAnimDecoder*         mWebPAnimDecoder{nullptr};
   WebPAnimInfo             mWebPAnimInfo{0};
   Dali::Devel::PixelBuffer mPreLoadedFrame{};