(WebP Loader) Ensure member variables are initialised (SVACE issue)
[platform/core/uifw/dali-adaptor.git] / dali / internal / imaging / common / webp-loading.cpp
index 78e2e11..cc4246a 100644 (file)
 #include <dali/internal/imaging/common/webp-loading.h>
 
 // EXTERNAL INCLUDES
+#ifdef DALI_WEBP_AVAILABLE
 #include <webp/decode.h>
 #include <webp/demux.h>
+
+#if WEBP_DEMUX_ABI_VERSION > 0x0101
+#define DALI_WEBP_ENABLED 1
+#endif
+
+#endif
 #include <dali/integration-api/debug.h>
 #include <dali/public-api/images/pixel-data.h>
 
@@ -58,10 +65,9 @@ struct WebPLoading::Impl
 {
 public:
   Impl( const std::string& url, bool isLocalResource )
-  : mUrl( url ),
-    mLoadingFrame( 0 )
+  : mUrl( url )
   {
-#if WEBP_DEMUX_ABI_VERSION > 0x0101
+#ifdef DALI_WEBP_ENABLED
     if( ReadWebPInformation( isLocalResource ) )
     {
       WebPAnimDecoderOptions webPAnimDecoderOptions;
@@ -76,7 +82,7 @@ public:
 
   bool ReadWebPInformation( bool isLocalResource )
   {
-#if WEBP_DEMUX_ABI_VERSION > 0x0101
+#ifdef DALI_WEBP_ENABLED
     WebPDataInit( &mWebPData );
     if( isLocalResource )
     {
@@ -157,7 +163,7 @@ public:
 
   ~Impl()
   {
-#if WEBP_DEMUX_ABI_VERSION > 0x0101
+#ifdef DALI_WEBP_ENABLED
     if( &mWebPData != NULL )
     {
       free( (void*)mWebPData.bytes );
@@ -173,19 +179,19 @@ public:
 
   std::string mUrl;
   std::vector<uint32_t> mTimeStamp;
-  uint32_t mLoadingFrame;
+  uint32_t mLoadingFrame{0};
 
-#if WEBP_DEMUX_ABI_VERSION > 0x0101
-  WebPData mWebPData;
-  WebPAnimDecoder* mWebPAnimDecoder;
-  WebPAnimInfo mWebPAnimInfo;
+#ifdef DALI_WEBP_ENABLED
+  WebPData mWebPData{0};
+  WebPAnimDecoder* mWebPAnimDecoder{nullptr};
+  WebPAnimInfo mWebPAnimInfo{0};
 #endif
 };
 
 AnimatedImageLoadingPtr WebPLoading::New( const std::string &url, bool isLocalResource )
 {
-#if WEBP_DEMUX_ABI_VERSION <= 0x0101
-  DALI_LOG_ERROR( "The system do not support Animated WebP format.\n" );
+#ifndef DALI_WEBP_ENABLED
+  DALI_LOG_ERROR( "The system does not support Animated WebP format.\n" );
 #endif
   return AnimatedImageLoadingPtr( new WebPLoading( url, isLocalResource ) );
 }
@@ -202,7 +208,7 @@ WebPLoading::~WebPLoading()
 
 bool WebPLoading::LoadNextNFrames( uint32_t frameStartIndex, int count, std::vector<Dali::PixelData> &pixelData )
 {
-#if WEBP_DEMUX_ABI_VERSION > 0x0101
+#ifdef DALI_WEBP_ENABLED
   if( frameStartIndex  >= mImpl->mWebPAnimInfo.frame_count )
   {
     return false;
@@ -256,9 +262,53 @@ bool WebPLoading::LoadNextNFrames( uint32_t frameStartIndex, int count, std::vec
 #endif
 }
 
+Dali::Devel::PixelBuffer WebPLoading::LoadFrame( uint32_t frameIndex )
+{
+  Dali::Devel::PixelBuffer pixelBuffer;
+#ifdef DALI_WEBP_ENABLED
+  if( frameIndex  >= mImpl->mWebPAnimInfo.frame_count )
+  {
+    return pixelBuffer;
+  }
+
+  DALI_LOG_INFO( gWebPLoadingLogFilter, Debug::Concise, "LoadNextNFrames( frameIndex:%d )\n", frameIndex );
+
+  if( mImpl->mLoadingFrame > frameIndex  )
+  {
+    mImpl->mLoadingFrame = 0;
+    WebPAnimDecoderReset( mImpl->mWebPAnimDecoder );
+  }
+
+  for( ; mImpl->mLoadingFrame < frameIndex ; ++mImpl->mLoadingFrame )
+  {
+    uint8_t* frameBuffer;
+    int timestamp;
+    WebPAnimDecoderGetNext( mImpl->mWebPAnimDecoder, &frameBuffer, &timestamp );
+    mImpl->mTimeStamp[mImpl->mLoadingFrame] = timestamp;
+  }
+
+  const int bufferSize = mImpl->mWebPAnimInfo.canvas_width * mImpl->mWebPAnimInfo.canvas_height * sizeof( uint32_t );
+  uint8_t* frameBuffer;
+  int timestamp;
+  WebPAnimDecoderGetNext( mImpl->mWebPAnimDecoder, &frameBuffer, &timestamp );
+
+  pixelBuffer = Dali::Devel::PixelBuffer::New( mImpl->mWebPAnimInfo.canvas_width, mImpl->mWebPAnimInfo.canvas_height, Dali::Pixel::RGBA8888 );
+  memcpy( pixelBuffer.GetBuffer(), frameBuffer, bufferSize );
+  mImpl->mTimeStamp[mImpl->mLoadingFrame] = timestamp;
+
+  mImpl->mLoadingFrame++;
+  if( mImpl->mLoadingFrame >= mImpl->mWebPAnimInfo.frame_count )
+  {
+    mImpl->mLoadingFrame = 0;
+    WebPAnimDecoderReset( mImpl->mWebPAnimDecoder );
+  }
+#endif
+  return pixelBuffer;
+}
+
 ImageDimensions WebPLoading::GetImageSize() const
 {
-#if WEBP_DEMUX_ABI_VERSION > 0x0101
+#ifdef DALI_WEBP_ENABLED
   return ImageDimensions( mImpl->mWebPAnimInfo.canvas_width, mImpl->mWebPAnimInfo.canvas_height );
 #else
   return ImageDimensions();
@@ -267,7 +317,7 @@ ImageDimensions WebPLoading::GetImageSize() const
 
 uint32_t WebPLoading::GetImageCount() const
 {
-#if WEBP_DEMUX_ABI_VERSION > 0x0101
+#ifdef DALI_WEBP_ENABLED
   return mImpl->mWebPAnimInfo.frame_count;
 #else
   return 0u;
@@ -290,8 +340,13 @@ uint32_t WebPLoading::GetFrameInterval( uint32_t frameIndex ) const
   }
 }
 
+std::string WebPLoading::GetUrl() const
+{
+  return mImpl->mUrl;
+}
+
 } // namespace Adaptor
 
 } // namespace Internal
 
-} // namespace Dali
\ No newline at end of file
+} // namespace Dali