Merge "New DepthTestMode API in Renderer" 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/ref-object.h>
23
24 namespace Dali
25 {
26
27 class PixelData;
28 typedef IntrusivePtr<PixelData> PixelDataPtr;
29
30 /**
31  * @brief Reference counted pixel data .
32  *
33  * The PixelData takes over the ownership of the pixel buffer.
34  * 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.
35  */
36 class DALI_IMPORT_API PixelData : public RefObject
37 {
38 public:
39
40   enum ReleaseFunction
41   {
42     FREE,          ///< Use free function to release the pixel buffer
43     DELETE_ARRAY,  ///< Use delete[] operator to release the pixel buffer
44   };
45
46   /**
47    * @brief Create a PixelData object.
48    *
49    * @param [in] buffer           The raw pixel data.
50    * @param [in] width            Buffer width in pixels
51    * @param [in] height           Buffer height in pixels
52    * @param [in] pixelFormat      The pixel format
53    * @param [in] releaseFunction  The function used to release the memory.
54    */
55   static PixelDataPtr New( unsigned char* buffer,
56                            unsigned int width,
57                            unsigned int height,
58                            Pixel::Format pixelFormat,
59                            ReleaseFunction releaseFunction);
60
61   /**
62    * Get the width of the buffer in pixels.
63    * @return The width of the buffer in pixels
64    */
65   unsigned int GetWidth() const;
66
67   /**
68    * Get the height of the buffer in pixels
69    * @return The height of the buffer in pixels
70    */
71   unsigned int GetHeight() const;
72
73   /**
74    * Get the pixel format
75    * @return The pixel format
76    */
77   Pixel::Format GetPixelFormat() const;
78
79   /**
80    * Get the pixel buffer if it's present.
81    * @return The buffer if exits, or NULL if there is no pixel buffer.
82    */
83   unsigned char* GetBuffer() const;
84
85 public:
86
87   /**
88    * @brief Constructor.
89    *
90    * @param [in] buffer           The raw pixel data.
91    * @param [in] width            Buffer width in pixels
92    * @param [in] height           Buffer height in pixels
93    * @param [in] pixelFormat      The pixel format
94    * @param [in] releaseFunction  The function used to release the memory.
95    */
96   PixelData( unsigned char* buffer,
97              unsigned int width,
98              unsigned int height,
99              Pixel::Format pixelFormat,
100              ReleaseFunction releaseFunction );
101
102   /**
103    * @brief Destructor.
104    *
105    * Release the pixel buffer if exists.
106    */
107   ~PixelData();
108
109
110 private:
111
112   /*
113    * Undefined copy constructor.
114    */
115   PixelData(const PixelData& other);
116
117   /*
118    * Undefined assignment operator.
119    */
120   PixelData& operator = (const PixelData& other);
121
122 private:
123
124   unsigned char* mBuffer;           ///< The raw pixel data.
125   unsigned int   mWidth;            ///< Buffer width in pixels.
126   unsigned int   mHeight;           ///< Buffer height in pixels.
127   Pixel::Format  mPixelFormat;      ///< Pixel format
128   ReleaseFunction mReleaseFunction;  ///< Function for releasing memory
129 };
130
131
132 } //namespace Dali
133
134 #endif // __DALI_PIXEL_DATA_H__