1 #ifndef DALI_INTERNAL_PIXEL_DATA_H
2 #define DALI_INTERNAL_PIXEL_DATA_H
5 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/devel-api/images/pixel-data-devel.h>
23 #include <dali/integration-api/debug.h>
24 #include <dali/public-api/images/pixel-data.h>
25 #include <dali/public-api/object/base-object.h>
32 using PixelDataPtr = IntrusivePtr<PixelData>;
34 class PixelData : public BaseObject
38 * @brief Create a PixelData object.
40 * @param [in] buffer The raw pixel data.
41 * @param [in] bufferSize The size of the buffer in bytes
42 * @param [in] width Buffer width in pixels
43 * @param [in] height Buffer height in pixels
44 * @param [in] stride Buffer stride in pixels, 0 means the buffer is tightly packed
45 * @param [in] pixelFormat The pixel format
46 * @param [in] releaseFunction The function used to release the memory.
48 static PixelDataPtr New(uint8_t* buffer,
53 Pixel::Format pixelFormat,
54 Dali::PixelData::ReleaseFunction releaseFunction);
59 * @param [in] buffer The raw pixel data.
60 * @param [in] bufferSize The size of the buffer in bytes
61 * @param [in] width Buffer width in pixels
62 * @param [in] height Buffer height in pixels
63 * @param [in] stride Buffer stride in pixels, 0 means the buffer is tightly packed
64 * @param [in] pixelFormat The pixel format
65 * @param [in] releaseFunction The function used to release the memory.
67 PixelData(uint8_t* buffer,
72 Pixel::Format pixelFormat,
73 Dali::PixelData::ReleaseFunction releaseFunction);
79 * Release the pixel buffer if exists.
81 ~PixelData() override;
85 * Get the width of the buffer in pixels.
86 * @return The width of the buffer in pixels
88 uint32_t GetWidth() const;
91 * Get the height of the buffer in pixels
92 * @return The height of the buffer in pixels
94 uint32_t GetHeight() const;
97 * Get the pixel format
98 * @return The pixel format
100 Pixel::Format GetPixelFormat() const;
103 * Get the pixel buffer if it's present.
104 * @return The buffer if exists, or NULL if there is no pixel buffer.
106 uint8_t* GetBuffer() const;
109 * Get the size of the buffer in bytes
110 * @return The size of the buffer
112 uint32_t GetBufferSize() const;
115 * Return the buffer pointer and reset the internal buffer to zero.
116 * @return The buffer pointer and associated data.
118 DevelPixelData::PixelDataBuffer ReleaseBuffer();
121 * @copydoc PixelData::GetStride()
123 uint32_t GetStride() const;
126 * Class method to get the total currently allocated size of pixel buffers
128 static uint32_t GetTotalAllocatedSize()
130 #if defined(DEBUG_ENABLED)
131 return gPixelDataAllocationTotal;
139 * Undefined copy constructor.
141 PixelData(const PixelData& other);
144 * Undefined assignment operator.
146 PixelData& operator=(const PixelData& other);
149 uint8_t* mBuffer; ///< The raw pixel data
150 uint32_t mBufferSize; ///< Buffer size in bytes
151 uint32_t mWidth; ///< Buffer width in pixels
152 uint32_t mHeight; ///< Buffer height in pixels
153 uint32_t mStride; ///< Buffer stride in pixels, 0 means the buffer is tightly packed
154 Pixel::Format mPixelFormat; ///< Pixel format
155 Dali::PixelData::ReleaseFunction mReleaseFunction; ///< Function for releasing memory
157 #if defined(DEBUG_ENABLED)
158 static uint32_t gPixelDataAllocationTotal;
162 } // namespace Internal
165 * Helper methods for public API
167 inline Internal::PixelData& GetImplementation(Dali::PixelData& handle)
169 DALI_ASSERT_ALWAYS(handle && "handle is empty");
171 BaseObject& object = handle.GetBaseObject();
173 return static_cast<Internal::PixelData&>(object);
176 inline const Internal::PixelData& GetImplementation(const Dali::PixelData& handle)
178 DALI_ASSERT_ALWAYS(handle && "handle is empty");
180 const BaseObject& object = handle.GetBaseObject();
182 return static_cast<const Internal::PixelData&>(object);
187 #endif // __DALI_INTERNAL_PIXEL_DATA_H__