[NUI] Add Extents type Padding in View
[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 using System;
19 using System.ComponentModel;
20
21 namespace Tizen.NUI
22 {
23     /// <summary>
24     ///  The PixelData object holds a pixel buffer.<br />
25     ///  The PixelData takes over the ownership of the pixel buffer.<br />
26     ///  The buffer memory must NOT be released outside of this class, instead,
27     ///  the PixelData object will release it automatically when the reference count falls to zero.
28     /// </summary>
29     /// Please DO NOT use! This will be deprecated!
30     /// PixelData class requires externally allocated pixel memory buffer and this buffer loses its ownershop by native DALi.
31     /// And this would make some problem, because dotnet runtime would change the address of memory allocated.
32     /// So this is required to be removed.
33     /// currently no use. will be added later
34     /// <since_tizen> 3 </since_tizen>
35     [EditorBrowsable(EditorBrowsableState.Never)]
36     public class PixelData : BaseHandle
37     {
38         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
39
40         internal PixelData(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.PixelData_SWIGUpcast(cPtr), cMemoryOwn)
41         {
42             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
43         }
44
45         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(PixelData obj)
46         {
47             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
48         }
49
50         /// <summary>
51         /// Dispose.
52         /// </summary>
53         /// <since_tizen> 3 </since_tizen>
54         protected override void Dispose(DisposeTypes type)
55         {
56             if (disposed)
57             {
58                 return;
59             }
60
61             if (type == DisposeTypes.Explicit)
62             {
63                 //Called by User
64                 //Release your own managed resources here.
65                 //You should release all of your own disposable objects here.
66
67             }
68
69             //Release your own unmanaged resources here.
70             //You should not access any managed member here except static instance.
71             //because the execution order of Finalizes is non-deterministic.
72
73
74             if (swigCPtr.Handle != global::System.IntPtr.Zero)
75             {
76                 if (swigCMemOwn)
77                 {
78                     swigCMemOwn = false;
79                     NDalicPINVOKE.delete_PixelData(swigCPtr);
80                 }
81                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
82             }
83
84             base.Dispose(type);
85         }
86
87         /// <summary>
88         /// Creates a PixelData object.
89         /// </summary>
90         /// <param name="buffer">The raw pixel data.</param>
91         /// <param name="bufferSize">The size of the buffer in bytes.</param>
92         /// <param name="width">Buffer width in pixels.</param>
93         /// <param name="height">Buffer height in pixels.</param>
94         /// <param name="pixelFormat">The pixel format.</param>
95         /// <param name="releaseFunction">The function used to release the memory.</param>
96         /// <since_tizen> 3 </since_tizen>
97         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)
98         {
99             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
100
101         }
102
103         /// <summary>
104         /// Gets the width of the buffer in pixels.
105         /// </summary>
106         /// <returns>The width of the buffer in pixels.</returns>
107         /// <since_tizen> 3 </since_tizen>
108         public uint GetWidth()
109         {
110             uint ret = NDalicPINVOKE.PixelData_GetWidth(swigCPtr);
111             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
112             return ret;
113         }
114
115         /// <summary>
116         /// Gets the height of the buffer in pixels.
117         /// </summary>
118         /// <returns>The height of the buffer in pixels.</returns>
119         /// <since_tizen> 3 </since_tizen>
120         public uint GetHeight()
121         {
122             uint ret = NDalicPINVOKE.PixelData_GetHeight(swigCPtr);
123             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
124             return ret;
125         }
126
127         /// <summary>
128         /// Gets the pixel format.
129         /// </summary>
130         /// <returns>The pixel format.</returns>
131         /// <since_tizen> 3 </since_tizen>
132         public PixelFormat GetPixelFormat()
133         {
134             PixelFormat ret = (PixelFormat)NDalicPINVOKE.PixelData_GetPixelFormat(swigCPtr);
135             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
136             return ret;
137         }
138
139         /// <summary>
140         /// Enumeration for Function to release the pixel buffer.
141         /// </summary>
142         /// <since_tizen> 3 </since_tizen>
143         public enum ReleaseFunction
144         {
145             /// <summary>
146             /// Use free function to release the pixel buffer.
147             /// </summary>
148             FREE,
149
150             /// <summary>
151             /// Use delete[] operator to release the pixel buffer.
152             /// </summary>
153             DELETE_ARRAY
154         }
155
156     }
157
158 }