1 #ifndef DALI_INTERNAL_PIXEL_DATA_H
2 #define DALI_INTERNAL_PIXEL_DATA_H
5 * Copyright (c) 2016 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/public-api/images/pixel-data.h>
23 #include <dali/public-api/object/base-object.h>
32 typedef IntrusivePtr<PixelData> PixelDataPtr;
34 class PixelData : public BaseObject
39 * @brief Create a PixelData object.
41 * @param [in] buffer The raw pixel data.
42 * @param [in] bufferSize The size of the buffer in bytes
43 * @param [in] width Buffer width in pixels
44 * @param [in] height Buffer height in pixels
45 * @param [in] pixelFormat The pixel format
46 * @param [in] releaseFunction The function used to release the memory.
48 static PixelDataPtr New( unsigned char* buffer,
49 unsigned int bufferSize,
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] pixelFormat The pixel format
63 * @param [in] releaseFunction The function used to release the memory.
65 PixelData( unsigned char* buffer,
66 unsigned int bufferSize,
69 Pixel::Format pixelFormat,
70 Dali::PixelData::ReleaseFunction releaseFunction );
77 * Release the pixel buffer if exists.
84 * Get the width of the buffer in pixels.
85 * @return The width of the buffer in pixels
87 unsigned int GetWidth() const;
90 * Get the height of the buffer in pixels
91 * @return The height of the buffer in pixels
93 unsigned int 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 unsigned char* GetBuffer() const;
108 * Get the size of the buffer in bytes
109 * @return The size of the buffer
111 unsigned int GetBufferSize() const;
114 * Apply the mask to this data
115 * @param[in] mask The mask to apply
117 void ApplyMask( const PixelData& mask );
123 void ReleaseBuffer();
126 * Apply the mask to this data's alpha channel
127 * @param[in] mask The mask to apply
129 void ApplyMaskToAlphaChannel( const PixelData& mask );
132 * Convert to RGBA8888 and apply the mask's alpha channel
133 * to this data's alpha channel
134 * @param[in] mask The mask to apply
136 void AddAlphaChannel( const PixelData& mask );
139 * Apply the mask to this data's color channels (e.g. to apply vignette)
140 * @param[in] mask The mask to apply
142 void ApplyMaskToColorChannels( const PixelData& mask );
145 * Read a weighted sample from a pixel (of unknown size)
146 * @param[in] x The x coordinate to sample from
147 * @param[in] y The y coordinate to sample from
149 float ReadWeightedSample( float x, float y ) const;
152 * Undefined copy constructor.
154 PixelData(const PixelData& other);
157 * Undefined assignment operator.
159 PixelData& operator= (const PixelData& other);
163 unsigned char* mBuffer; ///< The raw pixel data
164 unsigned int mBufferSize; ///< Buffer sized in bytes
165 unsigned int mWidth; ///< Buffer width in pixels
166 unsigned int mHeight; ///< Buffer height in pixels
167 Pixel::Format mPixelFormat; ///< Pixel format
168 Dali::PixelData::ReleaseFunction mReleaseFunction; ///< Function for releasing memory
171 } // namespace Internal
174 * Helper methods for public API
176 inline Internal::PixelData& GetImplementation( Dali::PixelData& handle )
178 DALI_ASSERT_ALWAYS( handle && "handle is empty" );
180 BaseObject& object = handle.GetBaseObject();
182 return static_cast<Internal::PixelData&>( object );
185 inline const Internal::PixelData& GetImplementation( const Dali::PixelData& handle )
187 DALI_ASSERT_ALWAYS( handle && "handle is empty" );
189 const BaseObject& object = handle.GetBaseObject();
191 return static_cast<const Internal::PixelData&>( object );
196 #endif // __DALI_INTERNAL_PIXEL_DATA_H__