[NUI]Fix build warnings (#254)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / PixelBuffer.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 using System.ComponentModel;
18
19 namespace Tizen.NUI
20 {
21
22     /// <summary>
23     /// The PixelBuffer object holds a pixel buffer.
24     /// The PixelBuffer keeps ownership of it's initial buffer however, the
25     /// user is free to modify the pixel data, either directly, or via image operations.
26     ///
27     /// In order to upload the pixel data to texture memory, there are two
28     /// possibilities - either convert it back to a PixelData object, which
29     /// releases the PixelBuffer object, leaving the user with an empty handle
30     /// (ideal for one-time indirect image manipulation), or create a new
31     /// PixelData object from this object, leaving the buffer intact (ideal
32     /// for continuous manipulation)
33     /// </summary>
34     /// <since_tizen> 5 </since_tizen>
35     /// This will be released at Tizen.NET API Level 5, so currently this would be used as inhouse API.
36     [EditorBrowsable(EditorBrowsableState.Never)]
37     public class PixelBuffer : BaseHandle
38     {
39         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
40
41         internal PixelBuffer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.PixelBuffer_SWIGUpcast(cPtr), cMemoryOwn)
42         {
43             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
44         }
45
46         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(PixelBuffer obj)
47         {
48             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
49         }
50
51         /// <summary>
52         /// Dispose.
53         /// </summary>
54         /// <since_tizen> 5 </since_tizen>
55         protected override void Dispose(DisposeTypes type)
56         {
57             if (disposed)
58             {
59                 return;
60             }
61
62             if (type == DisposeTypes.Explicit)
63             {
64                 //Called by User
65                 //Release your own managed resources here.
66                 //You should release all of your own disposable objects here.
67
68             }
69
70             //Release your own unmanaged resources here.
71             //You should not access any managed member here except static instance.
72             //because the execution order of Finalizes is non-deterministic.
73             if (swigCPtr.Handle != global::System.IntPtr.Zero)
74             {
75                 if (swigCMemOwn)
76                 {
77                     swigCMemOwn = false;
78                     NDalicPINVOKE.delete_PixelBuffer(swigCPtr);
79                 }
80                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
81             }
82
83             base.Dispose(type);
84         }
85
86         /// <summary>
87         /// Create a PixelBuffer with it's own data buffer.
88         /// </summary>
89         /// <param name="width">The pixel buffer width</param>
90         /// <param name="height">The pixel buffer height</param>
91         /// <param name="pixelFormat">The pixel format</param>
92         /// <since_tizen> 5 </since_tizen>
93         /// This will be released at Tizen.NET API Level 5, so currently this would be used as inhouse API.
94         [EditorBrowsable(EditorBrowsableState.Never)]
95         public PixelBuffer(uint width, uint height, PixelFormat pixelFormat) : this(NDalicPINVOKE.PixelBuffer_New(width, height, (int)pixelFormat), true)
96         {
97             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
98         }
99
100         internal PixelBuffer(PixelBuffer handle) : this(NDalicPINVOKE.new_PixelBuffer__SWIG_1(PixelBuffer.getCPtr(handle)), true)
101         {
102             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
103         }
104
105         internal PixelBuffer Assign(PixelBuffer rhs)
106         {
107             PixelBuffer ret = new PixelBuffer(NDalicPINVOKE.PixelBuffer_Assign(swigCPtr, PixelBuffer.getCPtr(rhs)), false);
108             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
109             return ret;
110         }
111
112         /// <summary>
113         /// Convert to a pixel data and release the pixelBuffer's object.
114         /// This handle is left empty.
115         /// Any other handles that keep a reference to this object
116         /// will be left with no buffer, trying to access it will return NULL.
117         /// </summary>
118         /// <param name="pixelBuffer">A pixel buffer</param>
119         /// <returns>A new PixelData which takes ownership of the PixelBuffer's buffer.</returns>
120         /// <since_tizen> 5 </since_tizen>
121         /// This will be released at Tizen.NET API Level 5, so currently this would be used as inhouse API.
122         [EditorBrowsable(EditorBrowsableState.Never)]
123         public static PixelData Convert(PixelBuffer pixelBuffer)
124         {
125             PixelData ret = new PixelData(NDalicPINVOKE.PixelBuffer_Convert(PixelBuffer.getCPtr(pixelBuffer)), true);
126             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
127             return ret;
128         }
129
130         /// <summary>
131         /// Copy the data from this object into a new PixelData object, which could be
132         /// used for uploading to a texture.
133         /// </summary>
134         /// <returns>The pixel data.</returns>
135         /// <since_tizen> 5 </since_tizen>
136         /// This will be released at Tizen.NET API Level 5, so currently this would be used as inhouse API.
137         [EditorBrowsable(EditorBrowsableState.Never)]
138         public PixelData CreatePixelData()
139         {
140             PixelData ret = new PixelData(NDalicPINVOKE.PixelBuffer_CreatePixelData(swigCPtr), true);
141             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
142             return ret;
143         }
144
145         internal SWIGTYPE_p_unsigned_char GetBuffer()
146         {
147             global::System.IntPtr cPtr = NDalicPINVOKE.PixelBuffer_GetBuffer(swigCPtr);
148             SWIGTYPE_p_unsigned_char ret = (cPtr == global::System.IntPtr.Zero) ? null : new SWIGTYPE_p_unsigned_char(cPtr, false);
149             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
150             return ret;
151         }
152
153         /// <summary>
154         /// Gets the width of the buffer in pixels.
155         /// </summary>
156         /// <returns>The width of the buffer in pixels.</returns>
157         /// <since_tizen> 5 </since_tizen>
158         /// This will be released at Tizen.NET API Level 5, so currently this would be used as inhouse API.
159         [EditorBrowsable(EditorBrowsableState.Never)]
160         public uint GetWidth()
161         {
162             uint ret = NDalicPINVOKE.PixelBuffer_GetWidth(swigCPtr);
163             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
164             return ret;
165         }
166
167         /// <summary>
168         /// Gets the height of the buffer in pixels.
169         /// </summary>
170         /// <returns>The height of the buffer in pixels.</returns>
171         /// <since_tizen> 5 </since_tizen>
172         /// This will be released at Tizen.NET API Level 5, so currently this would be used as inhouse API.
173         [EditorBrowsable(EditorBrowsableState.Never)]
174         public uint GetHeight()
175         {
176             uint ret = NDalicPINVOKE.PixelBuffer_GetHeight(swigCPtr);
177             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
178             return ret;
179         }
180
181         /// <summary>
182         /// Gets the pixel format.
183         /// </summary>
184         /// <returns>The pixel format.</returns>
185         /// <since_tizen> 5 </since_tizen>
186         /// This will be released at Tizen.NET API Level 5, so currently this would be used as inhouse API.
187         [EditorBrowsable(EditorBrowsableState.Never)]
188         public PixelFormat GetPixelFormat()
189         {
190             PixelFormat ret = (PixelFormat)NDalicPINVOKE.PixelBuffer_GetPixelFormat(swigCPtr);
191             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
192             return ret;
193         }
194
195         /// <summary>
196         /// Apply the mask to this pixel data, and return a new pixel data containing
197         /// the masked image. If this PixelBuffer doesn't have an alpha channel, then
198         /// the resultant PixelBuffer will be converted to a format that supports at
199         /// least the width of the color channels and the alpha channel from the mask.
200         ///
201         /// If cropToMask is set to true, then the contentScale is applied first to
202         /// this buffer, and the target buffer is cropped to the size of the mask. If
203         /// it's set to false, then the mask is scaled to match this buffer's size
204         /// before the mask is applied.
205         /// </summary>
206         /// <param name="mask">The mask to apply.</param>
207         /// <param name="contentScale">The scaling factor to apply to the content.</param>
208         /// <param name="cropToMask">Whether to crop the output to the mask size (true) or scale the mask to the content size (false).</param>
209         /// <since_tizen> 5 </since_tizen>
210         /// This will be released at Tizen.NET API Level 5, so currently this would be used as inhouse API.
211         [EditorBrowsable(EditorBrowsableState.Never)]
212         public void ApplyMask(PixelBuffer mask, float contentScale, bool cropToMask)
213         {
214             NDalicPINVOKE.PixelBuffer_ApplyMask__SWIG_0(swigCPtr, PixelBuffer.getCPtr(mask), contentScale, cropToMask);
215             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
216         }
217
218         /// <summary>
219         /// Apply the mask to this pixel data, and return a new pixel data containing
220         /// the masked image. If this PixelBuffer doesn't have an alpha channel, then
221         /// the resultant PixelBuffer will be converted to a format that supports at
222         /// least the width of the color channels and the alpha channel from the mask.
223         ///
224         /// If cropToMask is set to true, then the contentScale is applied first to
225         /// this buffer, and the target buffer is cropped to the size of the mask. If
226         /// it's set to false, then the mask is scaled to match this buffer's size
227         /// before the mask is applied.
228         /// </summary>
229         /// <param name="mask">The mask to apply.</param>
230         /// <param name="contentScale">The scaling factor to apply to the content.</param>
231         /// <since_tizen> 5 </since_tizen>
232         /// This will be released at Tizen.NET API Level 5, so currently this would be used as inhouse API.
233         [EditorBrowsable(EditorBrowsableState.Never)]
234         public void ApplyMask(PixelBuffer mask, float contentScale)
235         {
236             NDalicPINVOKE.PixelBuffer_ApplyMask__SWIG_1(swigCPtr, PixelBuffer.getCPtr(mask), contentScale);
237             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
238         }
239
240         /// <summary>
241         /// Apply the mask to this pixel data, and return a new pixel data containing
242         /// the masked image. If this PixelBuffer doesn't have an alpha channel, then
243         /// the resultant PixelBuffer will be converted to a format that supports at
244         /// least the width of the color channels and the alpha channel from the mask.
245         ///
246         /// If cropToMask is set to true, then the contentScale is applied first to
247         /// this buffer, and the target buffer is cropped to the size of the mask. If
248         /// it's set to false, then the mask is scaled to match this buffer's size
249         /// before the mask is applied.
250         /// </summary>
251         /// <param name="mask">The mask to apply.</param>
252         /// <since_tizen> 5 </since_tizen>
253         /// This will be released at Tizen.NET API Level 5, so currently this would be used as inhouse API.
254         [EditorBrowsable(EditorBrowsableState.Never)]
255         public void ApplyMask(PixelBuffer mask)
256         {
257             NDalicPINVOKE.PixelBuffer_ApplyMask__SWIG_2(swigCPtr, PixelBuffer.getCPtr(mask));
258             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
259         }
260
261         /// <summary>
262         /// Apply a Gaussian blur to this pixel data with the given radius.
263         /// A bigger radius will yield a blurrier image. Only works for pixel data in RGBA format.
264         /// </summary>
265         /// <param name="blurRadius">The radius for Gaussian blur. A value of 0 or negative value indicates no blur.</param>
266         /// <since_tizen> 5 </since_tizen>
267         /// This will be released at Tizen.NET API Level 5, so currently this would be used as inhouse API.
268         [EditorBrowsable(EditorBrowsableState.Never)]
269         public void ApplyGaussianBlur(float blurRadius)
270         {
271             NDalicPINVOKE.PixelBuffer_ApplyGaussianBlur(swigCPtr, blurRadius);
272             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
273         }
274
275         /// <summary>
276         /// Crops this buffer to the given crop rectangle.
277         /// </summary>
278         /// <param name="x">The top left corner's X.</param>
279         /// <param name="y">The top left corner's Y.</param>
280         /// <param name="width">The crop width.</param>
281         /// <param name="height">The crop height.</param>
282         /// <since_tizen> 5 </since_tizen>
283         /// This will be released at Tizen.NET API Level 5, so currently this would be used as inhouse API.
284         [EditorBrowsable(EditorBrowsableState.Never)]
285         public void Crop(ushort x, ushort y, ushort width, ushort height)
286         {
287             NDalicPINVOKE.PixelBuffer_Crop(swigCPtr, x, y, width, height);
288             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
289         }
290
291         /// <summary>
292         /// Resizes the buffer to the given dimensions.
293         /// </summary>
294         /// <param name="width">The new width.</param>
295         /// <param name="height">The new height.</param>
296         /// <since_tizen> 5 </since_tizen>
297         /// This will be released at Tizen.NET API Level 5, so currently this would be used as inhouse API.
298         [EditorBrowsable(EditorBrowsableState.Never)]
299         public void Resize(ushort width, ushort height)
300         {
301             NDalicPINVOKE.PixelBuffer_Resize(swigCPtr, width, height);
302             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
303         }
304
305         internal PixelBuffer(SWIGTYPE_p_unsigned_char pointer) : this(NDalicPINVOKE.new_PixelBuffer__SWIG_2(SWIGTYPE_p_unsigned_char.getCPtr(pointer)), true)
306         {
307             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
308         }
309
310     }
311
312 }