/*
- * 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.
}
}
+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,
{
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;
#define DALI_INTERNAL_ADAPTOR_PIXEL_BUFFER_H
/*
- * 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.
*/
void SetMetadata(std::unique_ptr<Property::Map> metadata);
+ /**
+ * Allocates fixed amount of memory for the pixel data. Used by compressed formats.
+ * @param[in] size Size of memory to be allocated
+ */
+ void AllocateFixedSize( uint32_t size );
+
private:
/*
* Undefined copy constructor.
#include <dali/integration-api/debug.h>
#include <dali/public-api/images/pixel.h>
#include <adaptors/devel-api/adaptor-framework/pixel-buffer.h>
+#include <adaptors/common/pixel-buffer-impl.h>
namespace Dali
{
// allocate pixel data
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();
+ }
// Load the image data.
const size_t bytesRead = fread( pixels, 1, imageByteCount, filePointer );
#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
{
// 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)
{