[NUI] remove "_" and refactoring naming to pascal case.
[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 its 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 the 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. Therefore, currently this would be used as an in-house API.
36     [EditorBrowsable(EditorBrowsableState.Never)]
37     public class PixelBuffer : BaseHandle
38     {
39
40         /// <summary>
41         /// Create a PixelBuffer with its own data buffer.
42         /// </summary>
43         /// <param name="width">The pixel buffer width.</param>
44         /// <param name="height">The pixel buffer height.</param>
45         /// <param name="pixelFormat">The pixel format.</param>
46         /// <since_tizen> 5 </since_tizen>
47         /// This will be released at Tizen.NET API Level 5. Therefore, currently this would be used as an in-house API.
48         [EditorBrowsable(EditorBrowsableState.Never)]
49         public PixelBuffer(uint width, uint height, PixelFormat pixelFormat) : this(Interop.PixelBuffer.New(width, height, (int)pixelFormat), true)
50         {
51             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
52         }
53
54         internal PixelBuffer(PixelBuffer handle) : this(Interop.PixelBuffer.NewPixelBuffer(PixelBuffer.getCPtr(handle)), true)
55         {
56             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
57         }
58
59         internal PixelBuffer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.PixelBuffer.Upcast(cPtr), cMemoryOwn)
60         {
61         }
62
63         /// <summary>
64         /// Convert to a pixel data and release the object of the pixelBuffer.
65         /// This handle is left empty.
66         /// Any other handles that keep a reference to this object
67         /// will be left with no buffer. Trying to access it will return NULL.
68         /// </summary>
69         /// <param name="pixelBuffer">A pixel buffer.</param>
70         /// <returns>A new PixelData that takes ownership of the buffer of the pixelBuffer.</returns>
71         /// <since_tizen> 5 </since_tizen>
72         /// This will be released at Tizen.NET API Level 5. Therefore, currently this would be used as an in-house API.
73         [EditorBrowsable(EditorBrowsableState.Never)]
74         public static PixelData Convert(PixelBuffer pixelBuffer)
75         {
76             PixelData ret = new PixelData(Interop.PixelBuffer.Convert(PixelBuffer.getCPtr(pixelBuffer)), true);
77             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
78             return ret;
79         }
80
81         /// <summary>
82         /// Copy the data from this object into a new PixelData object, which could be
83         /// used for uploading to a texture.
84         /// </summary>
85         /// <returns>The pixel data.</returns>
86         /// <since_tizen> 5 </since_tizen>
87         /// This will be released at Tizen.NET API Level 5. Therefore, currently this would be used as an in-house API.
88         [EditorBrowsable(EditorBrowsableState.Never)]
89         public PixelData CreatePixelData()
90         {
91             PixelData ret = new PixelData(Interop.PixelBuffer.CreatePixelData(swigCPtr), true);
92             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
93             return ret;
94         }
95
96         /// <summary>
97         /// Gets the width of the buffer in pixels.
98         /// </summary>
99         /// <returns>The width of the buffer in pixels.</returns>
100         /// <since_tizen> 5 </since_tizen>
101         /// This will be released at Tizen.NET API Level 5. Therefore, currently this would be used as an in-house API.
102         [EditorBrowsable(EditorBrowsableState.Never)]
103         public uint GetWidth()
104         {
105             uint ret = Interop.PixelBuffer.GetWidth(swigCPtr);
106             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
107             return ret;
108         }
109
110         /// <summary>
111         /// Gets the height of the buffer in pixels.
112         /// </summary>
113         /// <returns>The height of the buffer in pixels.</returns>
114         /// <since_tizen> 5 </since_tizen>
115         /// This will be released at Tizen.NET API Level 5. Therefore, currently this would be used as an in-house API.
116         [EditorBrowsable(EditorBrowsableState.Never)]
117         public uint GetHeight()
118         {
119             uint ret = Interop.PixelBuffer.GetHeight(swigCPtr);
120             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
121             return ret;
122         }
123
124         /// <summary>
125         /// Gets the pixel format.
126         /// </summary>
127         /// <returns>The pixel format.</returns>
128         /// <since_tizen> 5 </since_tizen>
129         /// This will be released at Tizen.NET API Level 5. Therefore, currently this would be used as an in-house API.
130         [EditorBrowsable(EditorBrowsableState.Never)]
131         public PixelFormat GetPixelFormat()
132         {
133             PixelFormat ret = (PixelFormat)Interop.PixelBuffer.GetPixelFormat(swigCPtr);
134             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
135             return ret;
136         }
137
138         /// <summary>
139         /// Apply the mask to this pixel data and return a new pixel data that contains
140         /// the masked image. If this PixelBuffer does not have an alpha channel, then
141         /// the resultant PixelBuffer will be converted to a format that supports at
142         /// least the width of the color channels and the alpha channel from the mask.
143         ///
144         /// If cropToMask is set to <c>true</c>, then the contentScale is applied first to
145         /// this buffer, and the target buffer is cropped to the size of the mask. If
146         /// it is set to <c>false</c>, then the mask is scaled to match the size of this buffer
147         /// before the mask is applied.
148         /// </summary>
149         /// <param name="mask">The mask to apply.</param>
150         /// <param name="contentScale">The scaling factor to apply to the content.</param>
151         /// <param name="cropToMask">Whether to crop the output to the mask size (true) or scale the mask to the content size (false).</param>
152         /// <since_tizen> 5 </since_tizen>
153         /// This will be released at Tizen.NET API Level 5. Therefore, currently this would be used as an in-house API.
154         [EditorBrowsable(EditorBrowsableState.Never)]
155         public void ApplyMask(PixelBuffer mask, float contentScale, bool cropToMask)
156         {
157             Interop.PixelBuffer.ApplyMask(swigCPtr, PixelBuffer.getCPtr(mask), contentScale, cropToMask);
158             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
159         }
160
161         /// <summary>
162         /// Apply the mask to this pixel data and return a new pixel data containing
163         /// the masked image. If this PixelBuffer does not have an alpha channel, then
164         /// the resultant PixelBuffer will be converted to a format that supports at
165         /// least the width of the color channels and the alpha channel from the mask.
166         ///
167         /// If cropToMask is set to <c>true</c>, then the contentScale is applied first to
168         /// this buffer, and the target buffer is cropped to the size of the mask. If
169         /// it is set to <c>false</c>, then the mask is scaled to match the size of this buffer
170         /// before the mask is applied.
171         /// </summary>
172         /// <param name="mask">The mask to apply.</param>
173         /// <param name="contentScale">The scaling factor to apply to the content.</param>
174         /// <since_tizen> 5 </since_tizen>
175         /// This will be released at Tizen.NET API Level 5. Therefore, currently this would be used as an in-house API.
176         [EditorBrowsable(EditorBrowsableState.Never)]
177         public void ApplyMask(PixelBuffer mask, float contentScale)
178         {
179             Interop.PixelBuffer.ApplyMask(swigCPtr, PixelBuffer.getCPtr(mask), contentScale);
180             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
181         }
182
183         /// <summary>
184         /// Apply the mask to this pixel data and return a new pixel data containing
185         /// the masked image. If this PixelBuffer does not have an alpha channel, then
186         /// the resultant PixelBuffer will be converted to a format that supports at
187         /// least the width of the color channels and the alpha channel from the mask.
188         ///
189         /// If cropToMask is set to <c>true</c>, then the contentScale is applied first to
190         /// this buffer, and the target buffer is cropped to the size of the mask. If
191         /// it is set to <c>false</c>, then the mask is scaled to match the size of this buffer
192         /// before the mask is applied.
193         /// </summary>
194         /// <param name="mask">The mask to apply.</param>
195         /// <since_tizen> 5 </since_tizen>
196         /// This will be released at Tizen.NET API Level 5. Therefore, currently this would be used as an in-house API.
197         [EditorBrowsable(EditorBrowsableState.Never)]
198         public void ApplyMask(PixelBuffer mask)
199         {
200             Interop.PixelBuffer.ApplyMask(swigCPtr, PixelBuffer.getCPtr(mask));
201             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
202         }
203
204         /// <summary>
205         /// Apply a Gaussian blur to this pixel data with the given radius.
206         /// A bigger radius will yield a blurrier image. Only works for pixel data in RGBA format.
207         /// </summary>
208         /// <param name="blurRadius">The radius for Gaussian blur. A value of 0 or negative value indicates no blur.</param>
209         /// <since_tizen> 5 </since_tizen>
210         /// This will be released at Tizen.NET API Level 5. Therefore, currently this would be used as an in-house API.
211         [EditorBrowsable(EditorBrowsableState.Never)]
212         public void ApplyGaussianBlur(float blurRadius)
213         {
214             Interop.PixelBuffer.ApplyGaussianBlur(swigCPtr, blurRadius);
215             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
216         }
217
218         /// <summary>
219         /// Crops this buffer to the given crop rectangle.
220         /// </summary>
221         /// <param name="x">The top left corner's X.</param>
222         /// <param name="y">The top left corner's Y.</param>
223         /// <param name="width">The crop width.</param>
224         /// <param name="height">The crop height.</param>
225         /// <since_tizen> 5 </since_tizen>
226         /// This will be released at Tizen.NET API Level 5. Therefore, currently this would be used as an in-house API.
227         [EditorBrowsable(EditorBrowsableState.Never)]
228         public void Crop(ushort x, ushort y, ushort width, ushort height)
229         {
230             Interop.PixelBuffer.Crop(swigCPtr, x, y, width, height);
231             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
232         }
233
234         /// <summary>
235         /// Resizes the buffer to the given dimensions.
236         /// </summary>
237         /// <param name="width">The new width.</param>
238         /// <param name="height">The new height.</param>
239         /// <since_tizen> 5 </since_tizen>
240         /// This will be released at Tizen.NET API Level 5. Therefore, currently this would be used as an in-house API.
241         [EditorBrowsable(EditorBrowsableState.Never)]
242         public void Resize(ushort width, ushort height)
243         {
244             Interop.PixelBuffer.Resize(swigCPtr, width, height);
245             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
246         }
247
248         /// <summary>
249         /// Rotate the buffer by the given angle.
250         /// </summary>
251         /// <param name="angle">The angle in degrees.</param>
252         /// <since_tizen> 8 </since_tizen>
253         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
254         [EditorBrowsable(EditorBrowsableState.Never)]
255         public bool Rotate(Degree angle)
256         {
257             bool ret = Interop.PixelBuffer.Rotate(swigCPtr, Degree.getCPtr(angle));
258             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
259             return ret;
260         }
261
262         /// <summary>
263         ///  Gets the pixel buffer
264         /// </summary>
265         /// <since_tizen> 8 </since_tizen>
266         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
267         [EditorBrowsable(EditorBrowsableState.Never)]
268         public global::System.IntPtr GetBuffer()
269         {
270             global::System.IntPtr ret = Interop.PixelBuffer.GetBuffer(swigCPtr);
271             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
272             return ret;
273         }
274
275         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(PixelBuffer obj)
276         {
277             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
278         }
279
280         internal PixelBuffer Assign(PixelBuffer rhs)
281         {
282             PixelBuffer ret = new PixelBuffer(Interop.PixelBuffer.Assign(swigCPtr, PixelBuffer.getCPtr(rhs)), false);
283             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
284             return ret;
285         }
286
287
288
289         /// This will not be public opened.
290         [EditorBrowsable(EditorBrowsableState.Never)]
291         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
292         {
293             Interop.PixelBuffer.DeletePixelBuffer(swigCPtr);
294         }
295     }
296 }