Update BitmapLoader to use PixelData
[platform/core/uifw/dali-adaptor.git] / adaptors / common / bitmap-loader-impl.cpp
index 7aaeb7d..7af4351 100644 (file)
@@ -17,9 +17,6 @@
 // EXTERNAL INCLUDES
 #include <string>
 
-#include <dali/integration-api/resource-types.h>
-#include <dali/integration-api/resource-cache.h>
-
 // INTERNAL INCLUDES
 #include "bitmap-loader-impl.h"
 #include "image-loaders/image-loader.h"
@@ -29,15 +26,24 @@ namespace Dali
 namespace Internal
 {
 
-IntrusivePtr<BitmapLoader> BitmapLoader::New(const std::string& filename)
+IntrusivePtr<BitmapLoader> BitmapLoader::New(const std::string& url,
+                                             ImageDimensions size,
+                                             FittingMode::Type fittingMode,
+                                             SamplingMode::Type samplingMode,
+                                             bool orientationCorrection)
 {
-  IntrusivePtr<BitmapLoader> internal = new BitmapLoader();
-  internal->Initialize(filename);
+  IntrusivePtr<BitmapLoader> internal = new BitmapLoader( url, size, fittingMode, samplingMode, orientationCorrection );
   return internal;
 }
 
-BitmapLoader::BitmapLoader()
-: mBitmap(NULL)
+BitmapLoader::BitmapLoader(const std::string& url,
+                           ImageDimensions size,
+                           FittingMode::Type fittingMode,
+                           SamplingMode::Type samplingMode,
+                           bool orientationCorrection)
+: mResourceType( size, fittingMode, samplingMode, orientationCorrection ),
+  mPixelData(),
+  mUrl(url)
 {
 }
 
@@ -45,38 +51,37 @@ BitmapLoader::~BitmapLoader()
 {
 }
 
-void BitmapLoader::Initialize(const std::string& filename)
+void BitmapLoader::Load()
 {
-  ImageAttributes attributes;
-  Integration::BitmapResourceType bitmapResourceType( attributes );
-  Integration::ResourcePointer resource = TizenPlatform::ImageLoader::LoadResourceSynchronously( bitmapResourceType, filename );
-
-  mBitmap = static_cast<Integration::Bitmap*>(resource.Get());
-}
+  IntrusivePtr<Dali::RefObject> resource = TizenPlatform::ImageLoader::LoadResourceSynchronously( mResourceType, mUrl );
 
-unsigned char* BitmapLoader::GetPixelData() const
-{
-  return mBitmap->GetBuffer();
-}
+  if( resource )
+  {
+    Integration::Bitmap* bitmap = static_cast<Integration::Bitmap*>(resource.Get());
 
-unsigned int BitmapLoader::GetImageHeight() const
-{
-  return mBitmap->GetImageHeight();
+    // Use bitmap->GetBufferOwnership() to transfer the buffer ownership to pixelData.
+    // The destroy of bitmap will not release the buffer, instead, the pixelData is responsible for releasing when its reference count falls to zero.
+    mPixelData = PixelData::New( bitmap->GetBufferOwnership(),
+                                 bitmap->GetImageWidth(),
+                                 bitmap->GetImageHeight(),
+                                 bitmap->GetPixelFormat(),
+                                 PixelData::FREE);
+  }
 }
 
-unsigned int BitmapLoader::GetImageWidth() const
+bool BitmapLoader::IsLoaded()
 {
-  return mBitmap->GetImageWidth();
+  return mPixelData ? true : false ;
 }
 
-unsigned int BitmapLoader::GetBufferStride() const
+const std::string& BitmapLoader::GetUrl() const
 {
-  return mBitmap->GetPackedPixelsProfile()->GetBufferStride();
+  return mUrl;
 }
 
-Pixel::Format BitmapLoader::GetPixelFormat() const
+PixelDataPtr BitmapLoader::GetPixelData() const
 {
-  return mBitmap->GetPixelFormat();
+  return mPixelData;
 }
 
 } // namespace Internal