#define DALI_INTERNAL_ADAPTOR_PIXEL_BUFFER_H
/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 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.
// INTERNAL INCLUDES
#include <dali/devel-api/adaptor-framework/pixel-buffer.h>
+#include <dali/integration-api/debug.h>
#include <dali/public-api/images/image-operations.h> // For ImageDimensions
#include <dali/public-api/images/pixel-data.h>
#include <dali/public-api/object/base-object.h>
namespace Dali
{
-
namespace Internal
{
-
namespace Adaptor
{
-
class PixelBuffer;
typedef IntrusivePtr<PixelBuffer> PixelBufferPtr;
class PixelBuffer : public BaseObject
{
public:
-
/**
* @brief Create a PixelBuffer object with a pre-allocated buffer.
* The PixelBuffer object owns this buffer, which may be retrieved
* @param [in] height Buffer height in pixels
* @param [in] pixelFormat The pixel format
*/
- static PixelBufferPtr New( unsigned int width,
- unsigned int height,
- Pixel::Format pixelFormat );
+ static PixelBufferPtr New(uint32_t width,
+ uint32_t height,
+ Pixel::Format pixelFormat);
/**
* @brief Create a PixelBuffer object. For internal use only.
* @param [in] bufferSize The size of the buffer in bytes
* @param [in] width Buffer width in pixels
* @param [in] height Buffer height in pixels
+ * @param [in] stride Buffer stride in pixels, 0 means the buffer is tightly packed
* @param [in] pixelFormat The pixel format
- * @param [in] releaseFunction The function used to release the memory.
*/
- static PixelBufferPtr New( unsigned char* buffer,
- unsigned int bufferSize,
- unsigned int width,
- unsigned int height,
- Pixel::Format pixelFormat );
+ static PixelBufferPtr New(uint8_t* buffer,
+ uint32_t bufferSize,
+ uint32_t width,
+ uint32_t height,
+ uint32_t stride,
+ Pixel::Format pixelFormat);
/**
* Convert a pixelBuffer object into a PixelData object.
* The new object takes ownership of the buffer data, and the
* mBuffer pointer is reset to NULL.
* @param[in] pixelBuffer The buffer to convert
+ * @param[in] releaseAfterUpload Whether converted PixelData released after upload or not.
* @return the pixelData
*/
- static Dali::PixelData Convert( PixelBuffer& pixelBuffer );
+ static Dali::PixelData Convert(PixelBuffer& pixelBuffer, bool releaseAfterUpload);
/**
* @brief Constructor.
* @param [in] bufferSize The size of the buffer in bytes
* @param [in] width Buffer width in pixels
* @param [in] height Buffer height in pixels
+ * @param [in] stride Buffer stride in pixels, 0 means the buffer is tightly packed
* @param [in] pixelFormat The pixel format
*/
- PixelBuffer( unsigned char* buffer,
- unsigned int bufferSize,
- unsigned int width,
- unsigned int height,
- Pixel::Format pixelFormat );
+ PixelBuffer(uint8_t* buffer,
+ uint32_t bufferSize,
+ uint32_t width,
+ uint32_t height,
+ uint32_t stride,
+ Pixel::Format pixelFormat);
protected:
-
/**
* @brief Destructor.
*
* Release the pixel buffer if exists.
*/
- ~PixelBuffer();
+ ~PixelBuffer() override;
public:
+ /**
+ * Get the total allocated size of current pixel buffers
+ */
+ static uint32_t GetTotalAllocatedSize()
+ {
+#if defined(DEBUG_ENABLED)
+ return gPixelBufferAllocationTotal;
+#else
+ return 0;
+#endif
+ }
/**
* Get the width of the buffer in pixels.
* @return The width of the buffer in pixels
*/
- unsigned int GetWidth() const;
+ uint32_t GetWidth() const;
/**
* Get the height of the buffer in pixels
* @return The height of the buffer in pixels
*/
- unsigned int GetHeight() const;
+ uint32_t GetHeight() const;
+
+ /**
+ * @brief Gets the stride of the buffer in pixels.
+ * @return The stride of the buffer in pixels. 0 means the buffer is tightly packed.
+ */
+ uint32_t GetStride() const;
/**
* Get the pixel format
* Get the pixel buffer if it's present.
* @return The buffer if exists, or NULL if there is no pixel buffer.
*/
- unsigned char* GetBuffer() const;
+ uint8_t* GetBuffer() const;
/**
* @copydoc Devel::PixelBuffer::GetBuffer()
*/
- const unsigned char* const GetConstBuffer() const;
+ const uint8_t* GetConstBuffer() const;
/**
* Get the size of the buffer in bytes
* @return The size of the buffer
*/
- unsigned int GetBufferSize() const;
+ uint32_t GetBufferSize() const;
/**
* Copy the buffer into a new PixelData
* @param[in] cropToMask Whether to crop the output to the mask size (true) or scale the
* mask to the content size (false)
*/
- void ApplyMask( const PixelBuffer& mask, float contentScale, bool cropToMask );
+ void ApplyMask(const PixelBuffer& mask, float contentScale, bool cropToMask);
/**
* @brief Apply a Gaussian blur to the current buffer with the given radius.
*
* @param[in] blurRadius The radius for Gaussian blur
*/
- void ApplyGaussianBlur( const float blurRadius );
+ void ApplyGaussianBlur(const float blurRadius);
/**
* Crops this buffer to the given crop rectangle. Assumes the crop rectangle
* @param[in] y The top left corner's y
* @param[in] cropDimensions The dimensions of the crop
*/
- void Crop( uint16_t x, uint16_t y, ImageDimensions cropDimensions );
+ void Crop(uint16_t x, uint16_t y, ImageDimensions cropDimensions);
/**
* Resizes the buffer to the given dimensions. Uses either Lanczos4 for downscaling
* or Mitchell for upscaling
* @param[in] outDimensions The new dimensions
*/
- void Resize( ImageDimensions outDimensions );
+ void Resize(ImageDimensions outDimensions);
/**
* Multiplies the image's color values by the alpha value. This provides better
*
* @param map Property map containing Exif fields
*/
- void SetMetadata( const Property::Map& map );
+ void SetMetadata(const Property::Map& map);
/**
* @brief Returns image metadata as a property map
* 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 );
+ void AllocateFixedSize(uint32_t size);
/**
* @copydoc Devel::PixelBuffer::Rotate()
*/
- bool Rotate( Degree angle );
+ bool Rotate(Degree angle);
/**
* @copydoc Devel::PixelBuffer::IsAlphaPreMultiplied()
*/
bool IsAlphaPreMultiplied() const;
+ /**
+ * @copydoc Devel::PixelBuffer::GetBrightness()
+ */
+ uint32_t GetBrightness() const;
+
private:
/*
* Undefined copy constructor.
/*
* Undefined assignment operator.
*/
- PixelBuffer& operator= (const PixelBuffer& other);
+ PixelBuffer& operator=(const PixelBuffer& other);
/**
* Internal method to apply the mask to this buffer. Expects that they are the same size.
*/
- void ApplyMaskInternal( const PixelBuffer& mask );
+ void ApplyMaskInternal(const PixelBuffer& mask);
/**
* Takes ownership of the other object's pixel buffer.
*/
- void TakeOwnershipOfBuffer( PixelBuffer& pixelBuffer );
+ void TakeOwnershipOfBuffer(PixelBuffer& pixelBuffer);
/**
* Release the buffer
* Scales this buffer buffer by the given factor, and crops at the center to the
* given dimensions.
*/
- void ScaleAndCrop( float scaleFactor, ImageDimensions cropDimensions );
+ void ScaleAndCrop(float scaleFactor, ImageDimensions cropDimensions);
/**
* Creates a new buffer which is a crop of the passed in buffer,
* @param[in] cropDimensions The dimensions of the crop
* @return the new pixel buffer
*/
- static PixelBufferPtr NewCrop( const PixelBuffer& inBuffer, uint16_t x, uint16_t y, ImageDimensions cropDimensions );
+ static PixelBufferPtr NewCrop(const PixelBuffer& inBuffer, uint16_t x, uint16_t y, ImageDimensions cropDimensions);
/**
* Creates a new buffer which is a resized version of the passed in buffer.
* @param[in] outDimensions The new dimensions
* @return a new buffer of the given size.
*/
- static PixelBufferPtr NewResize( const PixelBuffer& inBuffer, ImageDimensions outDimensions );
+ static PixelBufferPtr NewResize(const PixelBuffer& inBuffer, ImageDimensions outDimensions);
private:
-
- std::unique_ptr<Property::Map> mMetadata; ///< Metadata fields
- unsigned char* mBuffer; ///< The raw pixel data
- unsigned int mBufferSize; ///< Buffer sized in bytes
- unsigned int mWidth; ///< Buffer width in pixels
- unsigned int mHeight; ///< Buffer height in pixels
- Pixel::Format mPixelFormat; ///< Pixel format
- bool mPreMultiplied; ///< PreMultiplied
+ std::unique_ptr<Property::Map> mMetadata; ///< Metadata fields
+ uint8_t* mBuffer; ///< The raw pixel data
+ uint32_t mBufferSize; ///< Buffer sized in bytes
+ uint32_t mWidth; ///< Buffer width in pixels
+ uint32_t mHeight; ///< Buffer height in pixels
+ uint32_t mStride; ///< Buffer stride in bytes, 0 means the buffer is tightly packed
+ Pixel::Format mPixelFormat; ///< Pixel format
+ bool mPreMultiplied; ///< PreMultiplied
+
+#if defined(DEBUG_ENABLED)
+ static uint32_t gPixelBufferAllocationTotal;
+#endif
};
} // namespace Adaptor
/**
* Helper methods for public API
*/
-inline Internal::Adaptor::PixelBuffer& GetImplementation( Devel::PixelBuffer& handle )
+inline Internal::Adaptor::PixelBuffer& GetImplementation(Devel::PixelBuffer& handle)
{
- DALI_ASSERT_ALWAYS( handle && "handle is empty" );
+ DALI_ASSERT_ALWAYS(handle && "handle is empty");
BaseObject& object = handle.GetBaseObject();
- return static_cast<Internal::Adaptor::PixelBuffer&>( object );
+ return static_cast<Internal::Adaptor::PixelBuffer&>(object);
}
-inline const Internal::Adaptor::PixelBuffer& GetImplementation( const Devel::PixelBuffer& handle )
+inline const Internal::Adaptor::PixelBuffer& GetImplementation(const Devel::PixelBuffer& handle)
{
- DALI_ASSERT_ALWAYS( handle && "handle is empty" );
+ DALI_ASSERT_ALWAYS(handle && "handle is empty");
const BaseObject& object = handle.GetBaseObject();
- return static_cast<const Internal::Adaptor::PixelBuffer&>( object );
+ return static_cast<const Internal::Adaptor::PixelBuffer&>(object);
}
} // namespace Dali