[Tizen] Revert "Remove TypeRegistration from deprecated Image classes
[platform/core/uifw/dali-core.git] / dali / internal / event / images / nine-patch-image-impl.cpp
index 7ff6859..7662edc 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 #include <dali/public-api/object/type-registry.h>
 #include <dali/integration-api/bitmap.h>
 #include <dali/internal/event/common/thread-local-storage.h>
-#include <dali/internal/event/resources/resource-client.h>
 #include <dali/internal/update/manager/update-manager.h>
-#include <dali/internal/event/images/image-factory.h>
 #include <dali/integration-api/platform-abstraction.h>
 #include <dali/integration-api/resource-types.h>
-#include <dali/integration-api/resource-cache.h>
 
 
 namespace
@@ -150,6 +147,15 @@ void GetRedOffsetAndMask(Dali::Pixel::Format pixelFormat, int& byteOffset, int&
       bitMask=0;
       break;
     }
+
+    case Dali::Pixel::RGB16F:
+    case Dali::Pixel::RGB32F:
+    {
+      DALI_LOG_ERROR("Pixel format not compatible.\n");
+      byteOffset=0;
+      bitMask=0;
+      break;
+    }
   }
 }
 
@@ -166,30 +172,38 @@ namespace
 TypeRegistration mType( typeid( Dali::NinePatchImage ), typeid( Dali::Image ), NULL );
 } // unnamed namespace
 
-NinePatchImagePtr NinePatchImage::New( const std::string& filename, ReleasePolicy releasePol )
+NinePatchImagePtr NinePatchImage::New( const std::string& filename )
 {
-  Internal::NinePatchImagePtr internal( new NinePatchImage( filename, releasePol ) );
+  Internal::NinePatchImagePtr internal( new NinePatchImage( filename ) );
   internal->Initialize();
   return internal;
 }
 
-NinePatchImage::NinePatchImage( const std::string& filename, ReleasePolicy releasePol )
-: ResourceImage( IMAGE_LOAD_POLICY_DEFAULT, releasePol ),
+NinePatchImage::NinePatchImage( const std::string& filename )
+: ResourceImage(),
   mParsedBorder(false)
 {
+  mUrl = filename;
   ThreadLocalStorage& tls = ThreadLocalStorage::Get();
-  mResourceClient = &tls.GetResourceClient();
 
   Integration::PlatformAbstraction& platformAbstraction = tls.GetPlatformAbstraction();
   Integration::BitmapResourceType resourceType;
 
   // Note, bitmap is only destroyed when the image is destroyed.
-  Integration::ResourcePointer resource = platformAbstraction.LoadResourceSynchronously( resourceType, filename );
+  Integration::ResourcePointer resource = platformAbstraction.LoadImageSynchronously( resourceType, filename );
   if( resource )
   {
     mBitmap = static_cast<Integration::Bitmap*>( resource.Get());
+
     mWidth = mBitmap->GetImageWidth();
     mHeight = mBitmap->GetImageHeight();
+    mTexture = Texture::New( Dali::TextureType::TEXTURE_2D, mBitmap->GetPixelFormat(), mWidth, mHeight );
+
+    uint32_t bufferSize = mBitmap->GetBufferSize();
+    uint8_t* buffer = new uint8_t[bufferSize];
+    memcpy( buffer, mBitmap->GetBuffer(), bufferSize );
+    PixelDataPtr pixelData = PixelData::New( buffer, bufferSize, mWidth, mHeight, mBitmap->GetPixelFormat(), Dali::PixelData::DELETE_ARRAY );
+    mTexture->Upload( pixelData );
   }
   else
   {
@@ -247,7 +261,7 @@ Internal::BufferImagePtr NinePatchImage::CreateCroppedBufferImage()
   {
     Pixel::Format pixelFormat = mBitmap->GetPixelFormat();
 
-    cropped = BufferImage::New( mWidth-2, mHeight-2, pixelFormat, Dali::Image::NEVER );
+    cropped = BufferImage::New( mWidth-2, mHeight-2, pixelFormat );
 
     Integration::Bitmap::PackedPixelsProfile* srcProfile = mBitmap->GetPackedPixelsProfile();
     DALI_ASSERT_DEBUG( srcProfile && "Wrong profile for source bitmap");
@@ -255,13 +269,13 @@ Internal::BufferImagePtr NinePatchImage::CreateCroppedBufferImage()
     if( srcProfile )
     {
       PixelBuffer* destPixels = cropped->GetBuffer();
-      unsigned int destStride = cropped->GetBufferStride();
-      unsigned int pixelWidth = GetBytesPerPixel(pixelFormat);
+      uint32_t destStride = cropped->GetBufferStride();
+      uint32_t pixelWidth = GetBytesPerPixel(pixelFormat);
 
       PixelBuffer* srcPixels = mBitmap->GetBuffer();
-      unsigned int srcStride = srcProfile->GetBufferStride();
+      uint32_t srcStride = srcProfile->GetBufferStride();
 
-      for( unsigned int row=1; row < mHeight-1; ++row )
+      for( uint32_t row=1; row < mHeight-1; ++row )
       {
         PixelBuffer* src  = srcPixels + row*srcStride + pixelWidth;
         PixelBuffer* dest = destPixels + (row-1)*destStride;
@@ -275,30 +289,11 @@ Internal::BufferImagePtr NinePatchImage::CreateCroppedBufferImage()
   return cropped;
 }
 
-void NinePatchImage::Connect()
+const std::string& NinePatchImage::GetUrl() const
 {
-  if( !mTicket )
-  {
-    if( mBitmap )
-    {
-      const ImageTicketPtr& t = mResourceClient->AddBitmapImage(mBitmap.Get());
-      mTicket = t.Get();
-      mTicket->AddObserver(*this);
-    }
-  }
-
-  ++mConnectionCount;
+  return mUrl;
 }
 
-void NinePatchImage::Disconnect()
-{
-  if( mConnectionCount > 0 )
-  {
-    --mConnectionCount;
-  }
-}
-
-
 void NinePatchImage::ParseBorders()
 {
   if( !mBitmap )
@@ -330,15 +325,15 @@ void NinePatchImage::ParseBorders()
       testValue = 0;           // Black == stretch
     }
 
-    unsigned int pixelWidth = GetBytesPerPixel( pixelFormat );
+    uint32_t pixelWidth = GetBytesPerPixel( pixelFormat );
     const PixelBuffer* srcPixels = mBitmap->GetBuffer();
-    unsigned int srcStride = srcProfile->GetBufferStride();
+    uint32_t srcStride = srcProfile->GetBufferStride();
 
     //TOP
     const PixelBuffer* top = srcPixels + pixelWidth;
-    unsigned int index = 0;
-    unsigned int width = mBitmap->GetImageWidth();
-    unsigned int height = mBitmap->GetImageHeight();
+    uint32_t index = 0;
+    uint32_t width = mBitmap->GetImageWidth();
+    uint32_t height = mBitmap->GetImageHeight();
 
     for(; index < width - 2; )
     {
@@ -399,9 +394,9 @@ void NinePatchImage::ParseBorders()
   }
 }
 
-Uint16Pair NinePatchImage::ParseRange( unsigned int& index, unsigned int width, const PixelBuffer* & pixel, unsigned int pixelStride, int testByte, int testBits, int testValue )
+Uint16Pair NinePatchImage::ParseRange( uint32_t& index, uint32_t width, const PixelBuffer* & pixel, uint32_t pixelStride, int testByte, int testBits, int testValue )
 {
-  unsigned int start = 0xFFFF;
+  uint32_t start = 0xFFFF;
   for( ; index < width; ++index, pixel += pixelStride )
   {
     if( ( pixel[ testByte ] & testBits ) == testValue )
@@ -413,7 +408,7 @@ Uint16Pair NinePatchImage::ParseRange( unsigned int& index, unsigned int width,
     }
   }
 
-  unsigned int end = width;
+  uint32_t end = width;
   for( ; index < width; ++index, pixel += pixelStride )
   {
     if( ( pixel[ testByte ] & testBits ) != testValue )