1 #ifndef DALI_PIXEL_BUFFER_H
2 #define DALI_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.
21 #include <dali/public-api/images/pixel.h>
22 #include <dali/public-api/images/pixel-data.h>
23 #include <dali/public-api/object/base-handle.h>
36 // Use namespace to separate from PixelBuffer typedef in buffer-image.h
41 * @brief The PixelBuffer object holds a pixel buffer.
43 * The PixelBuffer keeps ownership of it's initial buffer however, the
44 * user is free to modify the pixel data, either directly, or via
47 * In order to upload the pixel data to texture memory, there are two
48 * possibilities - either convert it back to a PixelData object, which
49 * releases the PixelBuffer object, leaving the user with an empty handle
50 * (ideal for one-time indirect image manipulation), or create a new
51 * PixelData object from this object, leaving the buffer intact (ideal
52 * for continuous manipulation)
56 class DALI_IMPORT_API PixelBuffer : public BaseHandle
61 * Create a PixelBuffer with it's own data buffer.
63 static PixelBuffer New( unsigned int width,
65 Dali::Pixel::Format pixelFormat );
68 * @brief Creates an empty handle.
69 * Use PixelBuffer::New() to create an initialized object.
83 * @brief This copy constructor is required for (smart) pointer semantics.
86 * @param[in] handle A reference to the copied handle
88 PixelBuffer(const PixelBuffer& handle);
91 * @brief This assignment operator is required for (smart) pointer semantics.
94 * @param[in] rhs A reference to the copied handle
95 * @return A reference to this object
97 PixelBuffer& operator=(const PixelBuffer& rhs);
100 * Convert to a pixel data and release the pixelBuffer's object.
101 * This handle is left empty.
103 * @warning Any other handles that keep a reference to this object
104 * will be left with no buffer, trying to access it will return NULL.
107 * @param[in,out] pixelBuffer
108 * @return a new PixelData which takes ownership of the PixelBuffer's buffer.
110 static PixelData Convert( PixelBuffer& pixelBuffer );
113 * Copy the data from this object into a new PixelData object, which could be
114 * used for uploading to a texture.
115 * @return a new PixelData object containing a copy of this pixel buffer's data.
117 Dali::PixelData CreatePixelData() const;
120 * @brief Gets the pixel buffer. This is a pointer to the internal
123 * @warning If there is no pixel buffer (e.g. this object has been
124 * converted to a PixelData), this method will return NULL.
127 * @return The pixel buffer, or NULL.
129 unsigned char* GetBuffer();
132 * @brief Gets the width of the buffer in pixels.
135 * @return The width of the buffer in pixels
137 unsigned int GetWidth() const;
140 * @brief Gets the height of the buffer in pixels.
143 * @return The height of the buffer in pixels
145 unsigned int GetHeight() const;
148 * @brief Gets the pixel format.
151 * @return The pixel format
153 Pixel::Format GetPixelFormat() const;
156 * Apply the mask to this pixel data, and return a new pixel data containing
157 * the masked image. If this PixelBuffer doesn't have an alpha channel, then
158 * the resultant PixelBuffer will be converted to a format that supports at
159 * least the width of the color channels and the alpha channel from the mask.
161 * If cropToMask is set to true, then the contentScale is applied first to
162 * this buffer, and the target buffer is cropped to the size of the mask. If
163 * it's set to false, then the mask is scaled to match this buffer's size
164 * before the mask is applied.
166 * @param[in] mask The mask to apply.
167 * @param[in] contentScale The scaling factor to apply to the content
168 * @param[in] cropToMask Whether to crop the output to the mask size (true)
169 * or scale the mask to the content size (false)
171 void ApplyMask( PixelBuffer mask, float contentScale=1.0f, bool cropToMask=false );
176 * @brief The constructor.
177 * @note Not intended for application developers.
179 * @param[in] pointer A pointer to a newly allocated PixelBuffer
181 explicit DALI_INTERNAL PixelBuffer( Internal::Adaptor::PixelBuffer* pointer );
187 #endif // DALI_PIXEL_BUFFER_H