Release 4.0.0-preview1-00301
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / PixelData.cs
1 /*
2  * Copyright(c) 2017 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 namespace Tizen.NUI
19 {
20     /// <summary>
21     ///  The PixelData object holds a pixel buffer.<br />
22     ///  The PixelData takes over the ownership of the pixel buffer.<br />
23     ///  The buffer memory must NOT be released outside of this class, instead,
24     ///  the PixelData object will release it automatically when the reference count falls to zero.
25     /// </summary>
26     public class PixelData : BaseHandle
27     {
28         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
29
30         internal PixelData(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.PixelData_SWIGUpcast(cPtr), cMemoryOwn)
31         {
32             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
33         }
34
35         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(PixelData obj)
36         {
37             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
38         }
39
40         /// <summary>
41         /// Dispose.
42         /// </summary>
43         /// <since_tizen> 3 </since_tizen>
44         protected override void Dispose(DisposeTypes type)
45         {
46             if (disposed)
47             {
48                 return;
49             }
50
51             if (type == DisposeTypes.Explicit)
52             {
53                 //Called by User
54                 //Release your own managed resources here.
55                 //You should release all of your own disposable objects here.
56
57             }
58
59             //Release your own unmanaged resources here.
60             //You should not access any managed member here except static instance.
61             //because the execution order of Finalizes is non-deterministic.
62
63
64             if (swigCPtr.Handle != global::System.IntPtr.Zero)
65             {
66                 if (swigCMemOwn)
67                 {
68                     swigCMemOwn = false;
69                     NDalicPINVOKE.delete_PixelData(swigCPtr);
70                 }
71                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
72             }
73
74             base.Dispose(type);
75         }
76
77         /// <summary>
78         /// Creates a PixelData object.
79         /// </summary>
80         /// <param name="buffer">The raw pixel data.</param>
81         /// <param name="bufferSize">The size of the buffer in bytes.</param>
82         /// <param name="width">Buffer width in pixels.</param>
83         /// <param name="height">Buffer height in pixels.</param>
84         /// <param name="pixelFormat">The pixel format.</param>
85         /// <param name="releaseFunction">The function used to release the memory.</param>
86         /// <since_tizen> 3 </since_tizen>
87         public PixelData(byte[] buffer, uint bufferSize, uint width, uint height, PixelFormat pixelFormat, PixelData.ReleaseFunction releaseFunction) : this(NDalicPINVOKE.PixelData_New(buffer, bufferSize, width, height, (int)pixelFormat, (int)releaseFunction), true)
88         {
89             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
90
91         }
92
93         /// <summary>
94         /// Gets the width of the buffer in pixels.
95         /// </summary>
96         /// <returns>The width of the buffer in pixels.</returns>
97         /// <since_tizen> 3 </since_tizen>
98         public uint GetWidth()
99         {
100             uint ret = NDalicPINVOKE.PixelData_GetWidth(swigCPtr);
101             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
102             return ret;
103         }
104
105         /// <summary>
106         /// Gets the height of the buffer in pixels.
107         /// </summary>
108         /// <returns>The height of the buffer in pixels.</returns>
109         /// <since_tizen> 3 </since_tizen>
110         public uint GetHeight()
111         {
112             uint ret = NDalicPINVOKE.PixelData_GetHeight(swigCPtr);
113             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
114             return ret;
115         }
116
117         /// <summary>
118         /// Gets the pixel format.
119         /// </summary>
120         /// <returns>The pixel format.</returns>
121         /// <since_tizen> 3 </since_tizen>
122         public PixelFormat GetPixelFormat()
123         {
124             PixelFormat ret = (PixelFormat)NDalicPINVOKE.PixelData_GetPixelFormat(swigCPtr);
125             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
126             return ret;
127         }
128
129         /// <summary>
130         /// Enumeration for Function to release the pixel buffer.
131         /// </summary>
132         /// <since_tizen> 3 </since_tizen>
133         public enum ReleaseFunction
134         {
135             /// <summary>
136             /// Use free function to release the pixel buffer.
137             /// </summary>
138             FREE,
139
140             /// <summary>
141             /// Use delete[] operator to release the pixel buffer.
142             /// </summary>
143             DELETE_ARRAY
144         }
145
146     }
147
148 }