56674965bdb4bebc72db5775c6a4ed4846f1398e
[platform/core/uifw/dali-core.git] / dali / internal / event / images / pixel-data-impl.h
1 #ifndef DALI_INTERNAL_PIXEL_DATA_H
2 #define DALI_INTERNAL_PIXEL_DATA_H
3
4 /*
5  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/devel-api/images/pixel-data-devel.h>
23 #include <dali/public-api/images/pixel-data.h>
24 #include <dali/public-api/object/base-object.h>
25
26 namespace Dali
27 {
28 namespace Internal
29 {
30 class PixelData;
31 using PixelDataPtr = IntrusivePtr<PixelData>;
32
33 class PixelData : public BaseObject
34 {
35 public:
36   /**
37    * @brief Create a PixelData object.
38    *
39    * @param [in] buffer           The raw pixel data.
40    * @param [in] bufferSize       The size of the buffer in bytes
41    * @param [in] width            Buffer width in pixels
42    * @param [in] height           Buffer height in pixels
43    * @param [in] stride           Buffer stride in pixels, 0 means the buffer is tightly packed
44    * @param [in] pixelFormat      The pixel format
45    * @param [in] releaseFunction  The function used to release the memory.
46    */
47   static PixelDataPtr New(uint8_t*                         buffer,
48                           uint32_t                         bufferSize,
49                           uint32_t                         width,
50                           uint32_t                         height,
51                           uint32_t                         stride,
52                           Pixel::Format                    pixelFormat,
53                           Dali::PixelData::ReleaseFunction releaseFunction);
54
55   /**
56    * @brief Constructor.
57    *
58    * @param [in] buffer           The raw pixel data.
59    * @param [in] bufferSize       The size of the buffer in bytes
60    * @param [in] width            Buffer width in pixels
61    * @param [in] height           Buffer height in pixels
62    * @param [in] stride           Buffer stride in pixels, 0 means the buffer is tightly packed
63    * @param [in] pixelFormat      The pixel format
64    * @param [in] releaseFunction  The function used to release the memory.
65    */
66   PixelData(uint8_t*                         buffer,
67             uint32_t                         bufferSize,
68             uint32_t                         width,
69             uint32_t                         height,
70             uint32_t                         stride,
71             Pixel::Format                    pixelFormat,
72             Dali::PixelData::ReleaseFunction releaseFunction);
73
74 protected:
75   /**
76    * @brief Destructor.
77    *
78    * Release the pixel buffer if exists.
79    */
80   ~PixelData() override;
81
82 public:
83   /**
84    * Get the width of the buffer in pixels.
85    * @return The width of the buffer in pixels
86    */
87   uint32_t GetWidth() const;
88
89   /**
90    * Get the height of the buffer in pixels
91    * @return The height of the buffer in pixels
92    */
93   uint32_t GetHeight() const;
94
95   /**
96    * Get the pixel format
97    * @return The pixel format
98    */
99   Pixel::Format GetPixelFormat() const;
100
101   /**
102    * Get the pixel buffer if it's present.
103    * @return The buffer if exists, or NULL if there is no pixel buffer.
104    */
105   uint8_t* GetBuffer() const;
106
107   /**
108    * Get the size of the buffer in bytes
109    * @return The size of the buffer
110    */
111   uint32_t GetBufferSize() const;
112
113   /**
114    * Return the buffer pointer and reset the internal buffer to zero.
115    * @return The buffer pointer and associated data.
116    */
117   DevelPixelData::PixelDataBuffer ReleaseBuffer();
118
119   /**
120    * @copydoc PixelData::GetStride()
121    */
122   uint32_t GetStride() const;
123
124 private:
125   /*
126    * Undefined copy constructor.
127    */
128   PixelData(const PixelData& other);
129
130   /*
131    * Undefined assignment operator.
132    */
133   PixelData& operator=(const PixelData& other);
134
135 private:
136   uint8_t*                         mBuffer;          ///< The raw pixel data
137   uint32_t                         mBufferSize;      ///< Buffer size in bytes
138   uint32_t                         mWidth;           ///< Buffer width in pixels
139   uint32_t                         mHeight;          ///< Buffer height in pixels
140   uint32_t                         mStride;          ///< Buffer stride in pixels, 0 means the buffer is tightly packed
141   Pixel::Format                    mPixelFormat;     ///< Pixel format
142   Dali::PixelData::ReleaseFunction mReleaseFunction; ///< Function for releasing memory
143 };
144
145 } // namespace Internal
146
147 /**
148  * Helper methods for public API
149  */
150 inline Internal::PixelData& GetImplementation(Dali::PixelData& handle)
151 {
152   DALI_ASSERT_ALWAYS(handle && "handle is empty");
153
154   BaseObject& object = handle.GetBaseObject();
155
156   return static_cast<Internal::PixelData&>(object);
157 }
158
159 inline const Internal::PixelData& GetImplementation(const Dali::PixelData& handle)
160 {
161   DALI_ASSERT_ALWAYS(handle && "handle is empty");
162
163   const BaseObject& object = handle.GetBaseObject();
164
165   return static_cast<const Internal::PixelData&>(object);
166 }
167
168 } // namespace Dali
169
170 #endif // __DALI_INTERNAL_PIXEL_DATA_H__