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