Move MultiplyColorByAlpha() from main thread to resource thread
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / image-loader / image-atlas-impl.cpp
index da8fe90..d167499 100644 (file)
@@ -21,8 +21,7 @@
 // EXTERNAL INCLUDES
 #include <string.h>
 #include <dali/public-api/signals/callback.h>
-#include <dali/public-api/images/resource-image.h>
-#include <dali/devel-api/adaptor-framework/bitmap-loader.h>
+#include <dali/devel-api/adaptor-framework/image-loading.h>
 #include <dali/integration-api/debug.h>
 
 namespace Dali
@@ -33,6 +32,7 @@ namespace Toolkit
 
 namespace Internal
 {
+typedef unsigned char PixelBuffer;
 
 Texture ImageAtlas::PackToAtlas( const std::vector<PixelData>& pixelData, Dali::Vector<Vector4>& textureRects  )
 {
@@ -126,7 +126,7 @@ float ImageAtlas::GetOccupancyRate() const
 
 void ImageAtlas::SetBrokenImage( const std::string& brokenImageUrl )
 {
-  mBrokenImageSize = ResourceImage::GetImageSize( brokenImageUrl );
+  mBrokenImageSize = Dali::GetClosestImageSize( brokenImageUrl );
   if(mBrokenImageSize.GetWidth() > 0 && mBrokenImageSize.GetHeight() > 0 ) // check the url is valid
   {
     mBrokenImageUrl = brokenImageUrl;
@@ -144,7 +144,7 @@ bool ImageAtlas::Upload( Vector4& textureRect,
   ImageDimensions zero;
   if( size == zero ) // image size not provided
   {
-    dimensions = ResourceImage::GetImageSize( url );
+    dimensions = Dali::GetClosestImageSize( url );
     if( dimensions == zero ) // Fail to read the image & broken image file exists
     {
       if( !mBrokenImageUrl.empty() )
@@ -163,7 +163,7 @@ bool ImageAtlas::Upload( Vector4& textureRect,
   unsigned int packPositionY = 0;
   if( mPacker.Pack( dimensions.GetWidth(), dimensions.GetHeight(), packPositionX, packPositionY ) )
   {
-    unsigned short loadId = mAsyncLoader.Load( url, size, fittingMode, SamplingMode::BOX_THEN_LINEAR, orientationCorrection );
+    unsigned short loadId = mAsyncLoader.Load( url, size, fittingMode, SamplingMode::BOX_THEN_LINEAR, orientationCorrection);
     mLoadingTaskInfoContainer.PushBack( new LoadingTaskInfo( loadId, packPositionX, packPositionY, dimensions.GetWidth(), dimensions.GetHeight(), atlasUploadObserver ) );
     // apply the half pixel correction
     textureRect.x = ( static_cast<float>( packPositionX ) +0.5f ) / mWidth; // left
@@ -261,10 +261,9 @@ void ImageAtlas::UploadToAtlas( uint32_t id, PixelData pixelData )
 
 void ImageAtlas::UploadBrokenImage( const Rect<unsigned int>& area )
 {
-  BitmapLoader loader = BitmapLoader::New(mBrokenImageUrl, ImageDimensions( area.width, area.height ) );
-  loader.Load();
-  SizeType loadedWidth = loader.GetPixelData().GetWidth();
-  SizeType loadedHeight = loader.GetPixelData().GetHeight();
+  Devel::PixelBuffer brokenBuffer = LoadImageFromFile( mBrokenImageUrl, ImageDimensions( area.width, area.height ) );
+  SizeType loadedWidth = brokenBuffer.GetWidth();
+  SizeType loadedHeight = brokenBuffer.GetHeight();
 
   bool needBackgroundClear = false;
   SizeType packX = area.x;
@@ -284,16 +283,18 @@ void ImageAtlas::UploadBrokenImage( const Rect<unsigned int>& area )
   if( needBackgroundClear )
   {
     SizeType size = area.width * area.height * Pixel::GetBytesPerPixel( mPixelFormat );
-    PixelBuffer* buffer = new PixelBuffer [size];
-    PixelData background = PixelData::New( buffer, size, area.width, area.height, mPixelFormat, PixelData::DELETE_ARRAY );
+    Devel::PixelBuffer background = Devel::PixelBuffer::New( area.width, area.height, mPixelFormat );
+    unsigned char* buffer = background.GetBuffer();
     for( SizeType idx = 0; idx < size; idx++ )
     {
       buffer[idx] = 0x00;
     }
-    mAtlas.Upload( background, 0u, 0u, area.x, area.y, area.width, area.height );
+    PixelData pixelData = Devel::PixelBuffer::Convert( background );
+    mAtlas.Upload( pixelData, 0u, 0u, area.x, area.y, area.width, area.height );
   }
 
-  mAtlas.Upload( loader.GetPixelData(), 0u, 0u, packX, packY, loadedWidth, loadedHeight );
+  PixelData brokenPixelData = Devel::PixelBuffer::Convert( brokenBuffer );
+  mAtlas.Upload( brokenPixelData, 0u, 0u, packX, packY, loadedWidth, loadedHeight );
 }
 
 } // namespace Internal