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