[4.0] Fixed loading of compressed texture formats
[platform/core/uifw/dali-adaptor.git] / platform-abstractions / tizen / image-loaders / loader-ktx.cpp
index fc67104..e8e9e13 100755 (executable)
@@ -23,6 +23,7 @@
 #include <dali/public-api/common/compile-time-assert.h>
 #include <dali/integration-api/debug.h>
 #include <adaptors/devel-api/adaptor-framework/pixel-buffer.h>
+#include <adaptors/common/pixel-buffer-impl.h>
 
 namespace Dali
 {
@@ -587,13 +588,23 @@ bool LoadBitmapFromKtx( const ImageLoader::Input& input, Dali::Devel::PixelBuffe
 
   // Load up the image bytes:
   bitmap = Dali::Devel::PixelBuffer::New(width, height, pixelFormat);
+
+  // Compressed format won't allocate the buffer
   auto pixels = bitmap.GetBuffer();
+  if( !pixels )
+  {
+    // allocate buffer manually
+    auto &impl = GetImplementation(bitmap);
+    impl.AllocateFixedSize(imageByteCount);
+    pixels = bitmap.GetBuffer();
+  }
 
   if(!pixels)
   {
     DALI_LOG_ERROR( "Unable to reserve a pixel buffer to load the requested bitmap into.\n" );
     return false;
   }
+
   const size_t bytesRead = fread(pixels, 1, imageByteCount, fp);
   if(bytesRead != imageByteCount)
   {