X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fimaging%2Fcommon%2Fpixel-buffer-impl.h;h=d9898bf0255bdfbfbf8b57193a0dc518efe5fce6;hb=HEAD;hp=5c5c045fc01494206e83d6bd5615ac120336c93c;hpb=e0a7e95ba0d0d294630d3fe9908d04da2044f063;p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git diff --git a/dali/internal/imaging/common/pixel-buffer-impl.h b/dali/internal/imaging/common/pixel-buffer-impl.h old mode 100755 new mode 100644 index 5c5c045..d9898bf --- a/dali/internal/imaging/common/pixel-buffer-impl.h +++ b/dali/internal/imaging/common/pixel-buffer-impl.h @@ -2,7 +2,7 @@ #define DALI_INTERNAL_ADAPTOR_PIXEL_BUFFER_H /* - * Copyright (c) 2018 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. @@ -20,6 +20,7 @@ // INTERNAL INCLUDES #include +#include #include // For ImageDimensions #include #include @@ -30,20 +31,16 @@ namespace Dali { - namespace Internal { - namespace Adaptor { - class PixelBuffer; typedef IntrusivePtr 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 @@ -53,9 +50,9 @@ public: * @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. @@ -64,23 +61,25 @@ public: * @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. @@ -89,36 +88,54 @@ public: * @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 @@ -130,18 +147,18 @@ public: * 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 @@ -159,14 +176,14 @@ public: * @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 @@ -175,14 +192,14 @@ public: * @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 @@ -195,7 +212,7 @@ public: * * @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 @@ -215,12 +232,22 @@ public: * 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: /* @@ -231,17 +258,17 @@ private: /* * 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 @@ -252,7 +279,7 @@ private: * 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, @@ -264,7 +291,7 @@ private: * @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. @@ -273,16 +300,21 @@ private: * @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 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 + std::unique_ptr 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 @@ -292,24 +324,24 @@ private: /** * 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( object ); + return static_cast(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( object ); + return static_cast(object); } } // namespace Dali -#endif // __DALI_INTERNAL_ADAPTOR_PIXEL_BUFFER_H__ +#endif // DALI_INTERNAL_ADAPTOR_PIXEL_BUFFER_H