[dali_1.1.43] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / internal / event / images / pixel-data-impl.h
1 #ifndef DALI_INTERNAL_PIXEL_DATA_H
2 #define DALI_INTERNAL_PIXEL_DATA_H
3
4 /*
5  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/images/pixel-data.h>
23 #include <dali/public-api/object/base-object.h>
24
25 namespace Dali
26 {
27
28 namespace Internal
29 {
30
31 class PixelData;
32 typedef IntrusivePtr<PixelData> PixelDataPtr;
33
34 class PixelData : public BaseObject
35 {
36 public:
37
38   /**
39    * @brief Create a PixelData object.
40    *
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.
47    */
48   static PixelDataPtr New( unsigned char* buffer,
49                            unsigned int bufferSize,
50                            unsigned int width,
51                            unsigned int height,
52                            Pixel::Format pixelFormat,
53                            Dali::PixelData::ReleaseFunction releaseFunction);
54
55   /**
56    * @brief Constructor.
57    *
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.
64    */
65   PixelData( unsigned char* buffer,
66              unsigned int bufferSize,
67              unsigned int width,
68              unsigned int height,
69              Pixel::Format pixelFormat,
70              Dali::PixelData::ReleaseFunction releaseFunction );
71
72 protected:
73
74   /**
75    * @brief Destructor.
76    *
77    * Release the pixel buffer if exists.
78    */
79   ~PixelData();
80
81 public:
82
83   /**
84    * Get the width of the buffer in pixels.
85    * @return The width of the buffer in pixels
86    */
87   unsigned int GetWidth() const;
88
89   /**
90    * Get the height of the buffer in pixels
91    * @return The height of the buffer in pixels
92    */
93   unsigned int GetHeight() const;
94
95   /**
96    * Get the pixel format
97    * @return The pixel format
98    */
99   Pixel::Format GetPixelFormat() const;
100
101   /**
102    * Get the pixel buffer if it's present.
103    * @return The buffer if exists, or NULL if there is no pixel buffer.
104    */
105   unsigned char* GetBuffer() const;
106
107   /**
108    * Get the size of the buffer in bytes
109    * @return The size of the buffer
110    */
111   unsigned int GetBufferSize() const;
112
113 private:
114
115   /*
116    * Undefined copy constructor.
117    */
118   PixelData(const PixelData& other);
119
120   /*
121    * Undefined assignment operator.
122    */
123   PixelData& operator = (const PixelData& other);
124
125 private:
126
127   unsigned char* mBuffer;           ///< The raw pixel data
128   unsigned int   mBufferSize;       ///< Buffer sized in bytes
129   unsigned int   mWidth;            ///< Buffer width in pixels
130   unsigned int   mHeight;           ///< Buffer height in pixels
131   Pixel::Format  mPixelFormat;      ///< Pixel format
132   Dali::PixelData::ReleaseFunction mReleaseFunction;  ///< Function for releasing memory
133 };
134
135 } // namespace Internal
136
137 /**
138  * Helper methods for public API
139  */
140 inline Internal::PixelData& GetImplementation( Dali::PixelData& handle )
141 {
142   DALI_ASSERT_ALWAYS( handle && "handle is empty" );
143
144   BaseObject& object = handle.GetBaseObject();
145
146   return static_cast<Internal::PixelData&>( object );
147 }
148
149 inline const Internal::PixelData& GetImplementation( const Dali::PixelData& handle )
150 {
151   DALI_ASSERT_ALWAYS( handle && "handle is empty" );
152
153   const BaseObject& object = handle.GetBaseObject();
154
155   return static_cast<const Internal::PixelData&>( object );
156 }
157
158 } // namespace Dali
159
160 #endif // __DALI_INTERNAL_PIXEL_DATA_H__