Merge "Change PixelData to use the handle/body pattern" into devel/master
[platform/core/uifw/dali-core.git] / dali / devel-api / images / pixel-data.h
1 #ifndef __DALI_PIXEL_DATA_H__
2 #define __DALI_PIXEL_DATA_H__
3
4 /*
5  * Copyright (c) 2015 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 #include <dali/public-api/images/pixel.h>
22 #include <dali/public-api/object/base-handle.h>
23
24 namespace Dali
25 {
26
27 namespace Internal
28 {
29 class PixelData;
30 }
31
32 /**
33  * @brief The PixelData object holds a pixel buffer .
34  *
35  * The PixelData takes over the ownership of the pixel buffer.
36  * The buffer memory must NOT be released outside of this class, instead, the PixelData object will release it automatically when the reference count falls to zero.
37  */
38 class DALI_IMPORT_API PixelData : public BaseHandle
39 {
40 public:
41
42   enum ReleaseFunction
43   {
44     FREE,          ///< Use free function to release the pixel buffer
45     DELETE_ARRAY,  ///< Use delete[] operator to release the pixel buffer
46   };
47
48   /**
49    * @brief Create a PixelData object.
50    *
51    * @param [in] buffer           The raw pixel data.
52    * @param [in] width            Buffer width in pixels
53    * @param [in] height           Buffer height in pixels
54    * @param [in] pixelFormat      The pixel format
55    * @param [in] releaseFunction  The function used to release the memory.
56    */
57   static PixelData New( unsigned char* buffer,
58                         unsigned int width,
59                         unsigned int height,
60                         Pixel::Format pixelFormat,
61                         ReleaseFunction releaseFunction);
62
63   /**
64    * @brief Create an empty handle.
65    *
66    * Use PixelData::New() to create an initialized object.
67    */
68   PixelData();
69
70   /**
71    * Destructor
72    */
73   ~PixelData();
74
75   /**
76    * @brief This copy constructor is required for (smart) pointer semantics.
77    *
78    * @param [in] handle A reference to the copied handle
79    */
80   PixelData(const PixelData& handle);
81
82   /**
83    * @brief This assignment operator is required for (smart) pointer semantics.
84    *
85    * @param [in] rhs  A reference to the copied handle
86    * @return A reference to this
87    */
88   PixelData& operator=(const PixelData& rhs);
89
90   /**
91    * Get the width of the buffer in pixels.
92    * @return The width of the buffer in pixels
93    */
94   unsigned int GetWidth() const;
95
96   /**
97    * Get the height of the buffer in pixels
98    * @return The height of the buffer in pixels
99    */
100   unsigned int GetHeight() const;
101
102   /**
103    * Get the pixel format
104    * @return The pixel format
105    */
106   Pixel::Format GetPixelFormat() const;
107
108 public: // Not intended for application developers
109
110   explicit DALI_INTERNAL PixelData( Internal::PixelData* );
111 };
112
113
114 } //namespace Dali
115
116 #endif // __DALI_PIXEL_DATA_H__