Making DALi public API typesafe using guaranteed types; uint8_t, uint32_t
[platform/core/uifw/dali-core.git] / dali / public-api / images / pixel-data.h
1 #ifndef DALI_PIXEL_DATA_H
2 #define DALI_PIXEL_DATA_H
3
4 /*
5  * Copyright (c) 2018 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 // EXTERNAL INCLUDES
22 #include <cstdint> // uint8_t, uint32_t
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/images/pixel.h>
26 #include <dali/public-api/object/base-handle.h>
27
28 namespace Dali
29 {
30
31 namespace Internal
32 {
33 class PixelData;
34 }
35
36 /**
37  * @brief The PixelData object holds a pixel buffer .
38  * The PixelData takes over the ownership of the pixel buffer.
39  * 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.
40  *
41  * @SINCE_1_1.43
42  */
43 class DALI_CORE_API PixelData : public BaseHandle
44 {
45 public:
46
47   /**
48    * @brief Enumeration for Function to release the pixel buffer.
49    * @SINCE_1_1.43
50    */
51   enum ReleaseFunction
52   {
53     FREE,          ///< Use free function to release the pixel buffer     @SINCE_1_1.43
54     DELETE_ARRAY,  ///< Use delete[] operator to release the pixel buffer @SINCE_1_1.43
55   };
56
57   /**
58    * @brief Creates a PixelData object.
59    *
60    * @SINCE_1_1.43
61    * @param[in] buffer          The raw pixel data
62    * @param[in] bufferSize      The size of the buffer in bytes
63    * @param[in] width           Buffer width in pixels
64    * @param[in] height          Buffer height in pixels
65    * @param[in] pixelFormat     The pixel format
66    * @param[in] releaseFunction The function used to release the memory
67    * @return A handle to the PixelData
68    */
69   static PixelData New( uint8_t* buffer,
70                         uint32_t bufferSize,
71                         uint32_t width,
72                         uint32_t height,
73                         Pixel::Format pixelFormat,
74                         ReleaseFunction releaseFunction);
75
76   /**
77    * @brief Creates an empty handle.
78    * Use PixelData::New() to create an initialized object.
79    *
80    * @SINCE_1_1.43
81    */
82   PixelData();
83
84   /**
85    * @brief Destructor.
86    *
87    * @SINCE_1_1.43
88    */
89   ~PixelData();
90
91   /**
92    * @brief This copy constructor is required for (smart) pointer semantics.
93    *
94    * @SINCE_1_1.43
95    * @param[in] handle A reference to the copied handle
96    */
97   PixelData(const PixelData& handle);
98
99   /**
100    * @brief This assignment operator is required for (smart) pointer semantics.
101    *
102    * @SINCE_1_1.43
103    * @param[in] rhs A reference to the copied handle
104    * @return A reference to this object
105    */
106   PixelData& operator=(const PixelData& rhs);
107
108   /**
109    * @brief Gets the width of the buffer in pixels.
110    *
111    * @SINCE_1_1.43
112    * @return The width of the buffer in pixels
113    */
114   uint32_t GetWidth() const;
115
116   /**
117    * @brief Gets the height of the buffer in pixels.
118    *
119    * @SINCE_1_1.43
120    * @return The height of the buffer in pixels
121    */
122   uint32_t GetHeight() const;
123
124   /**
125    * @brief Gets the pixel format.
126    *
127    * @SINCE_1_1.43
128    * @return The pixel format
129    */
130   Pixel::Format GetPixelFormat() const;
131
132 public:
133
134   /**
135    * @brief The constructor.
136    * @note  Not intended for application developers.
137    * @SINCE_1_1.43
138    * @param[in] pointer A pointer to a newly allocated PixelData
139    */
140   explicit DALI_INTERNAL PixelData( Internal::PixelData* pointer );
141 };
142
143
144 } //namespace Dali
145
146 #endif // DALI_PIXEL_DATA_H