[4.0] Fixed loading of compressed texture formats
[platform/core/uifw/dali-adaptor.git] / adaptors / common / pixel-buffer-impl.cpp
index 7f12bac..b5b5ca4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017 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.
@@ -43,7 +43,8 @@ PixelBuffer::PixelBuffer( unsigned char* buffer,
                           unsigned int width,
                           unsigned int height,
                           Dali::Pixel::Format pixelFormat )
-: mBuffer( buffer ),
+: mMetadata(),
+  mBuffer( buffer ),
   mBufferSize( bufferSize ),
   mWidth( width ),
   mHeight( height ),
@@ -203,6 +204,13 @@ void PixelBuffer::ReleaseBuffer()
   }
 }
 
+void PixelBuffer::AllocateFixedSize( uint32_t size )
+{
+  ReleaseBuffer();
+  mBuffer = reinterpret_cast<unsigned char*>(malloc( size ));
+  mBufferSize = size;
+}
+
 void PixelBuffer::ScaleAndCrop( float scaleFactor, ImageDimensions cropDimensions )
 {
   ImageDimensions outDimensions( float(mWidth) * scaleFactor,
@@ -265,6 +273,26 @@ PixelBufferPtr PixelBuffer::NewCrop( const PixelBuffer& inBuffer, uint16_t x, ui
 
 }
 
+void PixelBuffer::SetMetadata( const Property::Map& map )
+{
+  mMetadata.reset(new Property::Map(map));
+}
+
+bool PixelBuffer::GetMetadata(Property::Map& outMetadata) const
+{
+  if( !mMetadata )
+  {
+    return false;
+  }
+  outMetadata = *mMetadata;
+  return true;
+}
+
+void PixelBuffer::SetMetadata(std::unique_ptr<Property::Map> metadata)
+{
+  mMetadata = std::move(metadata);
+}
+
 void PixelBuffer::Resize( ImageDimensions outDimensions )
 {
   if( mWidth != outDimensions.GetWidth() || mHeight != outDimensions.GetHeight() )
@@ -331,7 +359,9 @@ void PixelBuffer::MultiplyColorByAlpha()
 {
   auto bytesPerPixel = Pixel::GetBytesPerPixel( mPixelFormat );
 
-  if( Pixel::HasAlpha(mPixelFormat) )
+  // Compressed textures have unknown size of the pixel. Alpha premultiplication
+  // must be skipped in such case
+  if( Pixel::GetBytesPerPixel(mPixelFormat) && Pixel::HasAlpha(mPixelFormat) )
   {
     unsigned char* pixel = mBuffer;
     const unsigned int bufferSize = mWidth * mHeight;