1 #ifndef DALI_INTERNAL_ADAPTOR_PIXEL_BUFFER_H
2 #define DALI_INTERNAL_ADAPTOR_PIXEL_BUFFER_H
5 * Copyright (c) 2017 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 <pixel-buffer.h>
23 #include <dali/public-api/images/pixel-data.h>
24 #include <dali/public-api/object/base-object.h>
36 typedef IntrusivePtr<PixelBuffer> PixelBufferPtr;
38 class PixelBuffer : public BaseObject
43 * @brief Create a PixelBuffer object with a pre-allocated buffer.
44 * The PixelBuffer object owns this buffer, which may be retrieved
45 * and modified using GetBuffer().
47 * @param [in] width Buffer width in pixels
48 * @param [in] height Buffer height in pixels
49 * @param [in] pixelFormat The pixel format
51 static PixelBufferPtr New( unsigned int width,
53 Pixel::Format pixelFormat );
56 * @brief Create a PixelBuffer object. For internal use only.
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] pixelFormat The pixel format
63 * @param [in] releaseFunction The function used to release the memory.
65 static PixelBufferPtr New( unsigned char* buffer,
66 unsigned int bufferSize,
69 Pixel::Format pixelFormat );
72 * Convert a pixelBuffer object into a PixelData object.
73 * The new object takes ownership of the buffer data, and the
74 * mBuffer pointer is reset to NULL.
75 * @param[in] pixelBuffer The buffer to convert
76 * @return the pixelData
78 static Dali::PixelData Convert( PixelBuffer& pixelBuffer );
83 * @param [in] buffer The raw pixel data.
84 * @param [in] bufferSize The size of the buffer in bytes
85 * @param [in] width Buffer width in pixels
86 * @param [in] height Buffer height in pixels
87 * @param [in] pixelFormat The pixel format
89 PixelBuffer( unsigned char* buffer,
90 unsigned int bufferSize,
93 Pixel::Format pixelFormat );
100 * Release the pixel buffer if exists.
107 * Get the width of the buffer in pixels.
108 * @return The width of the buffer in pixels
110 unsigned int GetWidth() const;
113 * Get the height of the buffer in pixels
114 * @return The height of the buffer in pixels
116 unsigned int GetHeight() const;
119 * Get the pixel format
120 * @return The pixel format
122 Pixel::Format GetPixelFormat() const;
125 * Get the pixel buffer if it's present.
126 * @return The buffer if exists, or NULL if there is no pixel buffer.
128 unsigned char* GetBuffer() const;
131 * Get the size of the buffer in bytes
132 * @return The size of the buffer
134 unsigned int GetBufferSize() const;
137 * Copy the buffer into a new PixelData
139 Dali::PixelData CreatePixelData() const;
142 * Apply the mask to the current buffer. This method may update the
143 * internal object - e.g. the new buffer may have a different pixel
144 * format - as an alpha channel may be added.
145 * @param[in] mask The mask to apply to this pixel buffer
147 void ApplyMask( const PixelBuffer& mask );
151 * Undefined copy constructor.
153 PixelBuffer(const PixelBuffer& other);
156 * Undefined assignment operator.
158 PixelBuffer& operator= (const PixelBuffer& other);
163 void ReleaseBuffer();
167 unsigned char* mBuffer; ///< The raw pixel data
168 unsigned int mBufferSize; ///< Buffer sized in bytes
169 unsigned int mWidth; ///< Buffer width in pixels
170 unsigned int mHeight; ///< Buffer height in pixels
171 Pixel::Format mPixelFormat; ///< Pixel format
174 } // namespace Adaptor
176 } // namespace Internal
179 * Helper methods for public API
181 inline Internal::Adaptor::PixelBuffer& GetImplementation( Devel::PixelBuffer& handle )
183 DALI_ASSERT_ALWAYS( handle && "handle is empty" );
185 BaseObject& object = handle.GetBaseObject();
187 return static_cast<Internal::Adaptor::PixelBuffer&>( object );
190 inline const Internal::Adaptor::PixelBuffer& GetImplementation( const Devel::PixelBuffer& handle )
192 DALI_ASSERT_ALWAYS( handle && "handle is empty" );
194 const BaseObject& object = handle.GetBaseObject();
196 return static_cast<const Internal::Adaptor::PixelBuffer&>( object );
201 #endif // __DALI_INTERNAL_ADAPTOR_PIXEL_BUFFER_H__