Webp-loading, Fix svace issue and change the way to get animation flag 71/274071/2
authorseungho <sbsh.baek@samsung.com>
Thu, 21 Apr 2022 03:04:35 +0000 (12:04 +0900)
committerseungho <sbsh.baek@samsung.com>
Thu, 21 Apr 2022 03:30:16 +0000 (12:30 +0900)
Change-Id: I1043bc99f1bdbaf0a05f7bf4107495e759309b9f
Signed-off-by: seungho <sbsh.baek@samsung.com>
dali/internal/imaging/common/webp-loading.cpp

index 0cb8932..a5b8dab 100644 (file)
@@ -113,12 +113,30 @@ 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;
@@ -129,16 +147,6 @@ 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
@@ -178,32 +186,14 @@ public:
         }
       }
 
-      fp = fileReader->GetFile();
+      if(fileReader)
+      {
+        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))
@@ -225,14 +215,16 @@ 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);
@@ -273,8 +265,11 @@ public:
   bool            mIsAnimatedImage;
   bool            mIsLocalResource;
 
-#ifdef DALI_ANIMATED_WEBP_ENABLED
+#ifdef DALI_WEBP_AVAILABLE
   WebPData                 mWebPData{0};
+#endif
+
+#ifdef DALI_ANIMATED_WEBP_ENABLED
   WebPAnimDecoder*         mWebPAnimDecoder{nullptr};
   WebPAnimInfo             mWebPAnimInfo{0};
   Dali::Devel::PixelBuffer mPreLoadedFrame{};