2 * Copyright(c) 2017 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 using System.ComponentModel;
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.
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).
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
39 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
41 internal PixelBuffer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.PixelBuffer_SWIGUpcast(cPtr), cMemoryOwn)
43 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
46 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(PixelBuffer obj)
48 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
54 /// <since_tizen> 5 </since_tizen>
55 protected override void Dispose(DisposeTypes type)
62 if (type == DisposeTypes.Explicit)
65 //Release your own managed resources here.
66 //You should release all of your own disposable objects here.
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)
78 NDalicPINVOKE.delete_PixelBuffer(swigCPtr);
80 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
87 /// Create a PixelBuffer with its own data buffer.
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. Therefore, currently this would be used as an in-house API.
94 [EditorBrowsable(EditorBrowsableState.Never)]
95 public PixelBuffer(uint width, uint height, PixelFormat pixelFormat) : this(NDalicPINVOKE.PixelBuffer_New(width, height, (int)pixelFormat), true)
97 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
100 internal PixelBuffer(PixelBuffer handle) : this(NDalicPINVOKE.new_PixelBuffer__SWIG_1(PixelBuffer.getCPtr(handle)), true)
102 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
105 internal PixelBuffer Assign(PixelBuffer rhs)
107 PixelBuffer ret = new PixelBuffer(NDalicPINVOKE.PixelBuffer_Assign(swigCPtr, PixelBuffer.getCPtr(rhs)), false);
108 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
113 /// Convert to a pixel data and release the object of the pixelBuffer.
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.
118 /// <param name="pixelBuffer">A pixel buffer.</param>
119 /// <returns>A new PixelData that takes ownership of the buffer of the pixelBuffer.</returns>
120 /// <since_tizen> 5 </since_tizen>
121 /// This will be released at Tizen.NET API Level 5. Therefore, currently this would be used as an in-house API.
122 [EditorBrowsable(EditorBrowsableState.Never)]
123 public static PixelData Convert(PixelBuffer pixelBuffer)
125 PixelData ret = new PixelData(NDalicPINVOKE.PixelBuffer_Convert(PixelBuffer.getCPtr(pixelBuffer)), true);
126 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
131 /// Copy the data from this object into a new PixelData object, which could be
132 /// used for uploading to a texture.
134 /// <returns>The pixel data.</returns>
135 /// <since_tizen> 5 </since_tizen>
136 /// This will be released at Tizen.NET API Level 5. Therefore, currently this would be used as an in-house API.
137 [EditorBrowsable(EditorBrowsableState.Never)]
138 public PixelData CreatePixelData()
140 PixelData ret = new PixelData(NDalicPINVOKE.PixelBuffer_CreatePixelData(swigCPtr), true);
141 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
145 internal SWIGTYPE_p_unsigned_char GetBuffer()
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();
154 /// Gets the width of the buffer in pixels.
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. Therefore, currently this would be used as an in-house API.
159 [EditorBrowsable(EditorBrowsableState.Never)]
160 public uint GetWidth()
162 uint ret = NDalicPINVOKE.PixelBuffer_GetWidth(swigCPtr);
163 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
168 /// Gets the height of the buffer in pixels.
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. Therefore, currently this would be used as an in-house API.
173 [EditorBrowsable(EditorBrowsableState.Never)]
174 public uint GetHeight()
176 uint ret = NDalicPINVOKE.PixelBuffer_GetHeight(swigCPtr);
177 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
182 /// Gets the pixel format.
184 /// <returns>The pixel format.</returns>
185 /// <since_tizen> 5 </since_tizen>
186 /// This will be released at Tizen.NET API Level 5. Therefore, currently this would be used as an in-house API.
187 [EditorBrowsable(EditorBrowsableState.Never)]
188 public PixelFormat GetPixelFormat()
190 PixelFormat ret = (PixelFormat)NDalicPINVOKE.PixelBuffer_GetPixelFormat(swigCPtr);
191 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
196 /// Apply the mask to this pixel data and return a new pixel data that contains
197 /// the masked image. If this PixelBuffer does not 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.
201 /// If cropToMask is set to <c>true</c>, 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 is set to <c>false</c>, then the mask is scaled to match the size of this buffer
204 /// before the mask is applied.
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. Therefore, currently this would be used as an in-house API.
211 [EditorBrowsable(EditorBrowsableState.Never)]
212 public void ApplyMask(PixelBuffer mask, float contentScale, bool cropToMask)
214 NDalicPINVOKE.PixelBuffer_ApplyMask__SWIG_0(swigCPtr, PixelBuffer.getCPtr(mask), contentScale, cropToMask);
215 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
219 /// Apply the mask to this pixel data and return a new pixel data containing
220 /// the masked image. If this PixelBuffer does not 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.
224 /// If cropToMask is set to <c>true</c>, 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 is set to <c>false</c>, then the mask is scaled to match the size of this buffer
227 /// before the mask is applied.
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. Therefore, currently this would be used as an in-house API.
233 [EditorBrowsable(EditorBrowsableState.Never)]
234 public void ApplyMask(PixelBuffer mask, float contentScale)
236 NDalicPINVOKE.PixelBuffer_ApplyMask__SWIG_1(swigCPtr, PixelBuffer.getCPtr(mask), contentScale);
237 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
241 /// Apply the mask to this pixel data and return a new pixel data containing
242 /// the masked image. If this PixelBuffer does not 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.
246 /// If cropToMask is set to <c>true</c>, 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 is set to <c>false</c>, then the mask is scaled to match the size of this buffer
249 /// before the mask is applied.
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. Therefore, currently this would be used as an in-house API.
254 [EditorBrowsable(EditorBrowsableState.Never)]
255 public void ApplyMask(PixelBuffer mask)
257 NDalicPINVOKE.PixelBuffer_ApplyMask__SWIG_2(swigCPtr, PixelBuffer.getCPtr(mask));
258 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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.
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. Therefore, currently this would be used as an in-house API.
268 [EditorBrowsable(EditorBrowsableState.Never)]
269 public void ApplyGaussianBlur(float blurRadius)
271 NDalicPINVOKE.PixelBuffer_ApplyGaussianBlur(swigCPtr, blurRadius);
272 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
276 /// Crops this buffer to the given crop rectangle.
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. Therefore, currently this would be used as an in-house API.
284 [EditorBrowsable(EditorBrowsableState.Never)]
285 public void Crop(ushort x, ushort y, ushort width, ushort height)
287 NDalicPINVOKE.PixelBuffer_Crop(swigCPtr, x, y, width, height);
288 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
292 /// Resizes the buffer to the given dimensions.
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. Therefore, currently this would be used as an in-house API.
298 [EditorBrowsable(EditorBrowsableState.Never)]
299 public void Resize(ushort width, ushort height)
301 NDalicPINVOKE.PixelBuffer_Resize(swigCPtr, width, height);
302 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();