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/public-api/images/pixel-data.h>
24 #include <dali/public-api/object/base-object.h>
31 using PixelDataPtr = IntrusivePtr<PixelData>;
33 class PixelData : public BaseObject
37 * @brief Create a PixelData object.
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.
47 static PixelDataPtr New(uint8_t* buffer,
52 Pixel::Format pixelFormat,
53 Dali::PixelData::ReleaseFunction releaseFunction);
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.
66 PixelData(uint8_t* buffer,
71 Pixel::Format pixelFormat,
72 Dali::PixelData::ReleaseFunction releaseFunction);
78 * Release the pixel buffer if exists.
80 ~PixelData() override;
84 * Get the width of the buffer in pixels.
85 * @return The width of the buffer in pixels
87 uint32_t GetWidth() const;
90 * Get the height of the buffer in pixels
91 * @return The height of the buffer in pixels
93 uint32_t GetHeight() const;
96 * Get the pixel format
97 * @return The pixel format
99 Pixel::Format GetPixelFormat() const;
102 * Get the pixel buffer if it's present.
103 * @return The buffer if exists, or NULL if there is no pixel buffer.
105 uint8_t* GetBuffer() const;
108 * Get the size of the buffer in bytes
109 * @return The size of the buffer
111 uint32_t GetBufferSize() const;
114 * Return the buffer pointer and reset the internal buffer to zero.
115 * @return The buffer pointer and associated data.
117 DevelPixelData::PixelDataBuffer ReleaseBuffer();
120 * @copydoc PixelData::GetStride()
122 uint32_t GetStride() const;
126 * Undefined copy constructor.
128 PixelData(const PixelData& other);
131 * Undefined assignment operator.
133 PixelData& operator=(const PixelData& other);
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
145 } // namespace Internal
148 * Helper methods for public API
150 inline Internal::PixelData& GetImplementation(Dali::PixelData& handle)
152 DALI_ASSERT_ALWAYS(handle && "handle is empty");
154 BaseObject& object = handle.GetBaseObject();
156 return static_cast<Internal::PixelData&>(object);
159 inline const Internal::PixelData& GetImplementation(const Dali::PixelData& handle)
161 DALI_ASSERT_ALWAYS(handle && "handle is empty");
163 const BaseObject& object = handle.GetBaseObject();
165 return static_cast<const Internal::PixelData&>(object);
170 #endif // __DALI_INTERNAL_PIXEL_DATA_H__