1 /** Copyright (c) 2017 Samsung Electronics Co., Ltd.
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
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 using System.ComponentModel;
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.
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)
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
38 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
40 internal PixelBuffer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.PixelBuffer_SWIGUpcast(cPtr), cMemoryOwn)
42 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
45 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(PixelBuffer obj)
47 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
53 /// <since_tizen> 5 </since_tizen>
54 protected override void Dispose(DisposeTypes type)
61 if (type == DisposeTypes.Explicit)
64 //Release your own managed resources here.
65 //You should release all of your own disposable objects here.
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)
77 NDalicPINVOKE.delete_PixelBuffer(swigCPtr);
79 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
86 /// Create a PixelBuffer with it's own data buffer.
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)
96 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
99 internal PixelBuffer(PixelBuffer handle) : this(NDalicPINVOKE.new_PixelBuffer__SWIG_1(PixelBuffer.getCPtr(handle)), true)
101 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
104 internal PixelBuffer Assign(PixelBuffer rhs)
106 PixelBuffer ret = new PixelBuffer(NDalicPINVOKE.PixelBuffer_Assign(swigCPtr, PixelBuffer.getCPtr(rhs)), false);
107 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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.
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)
124 PixelData ret = new PixelData(NDalicPINVOKE.PixelBuffer_Convert(PixelBuffer.getCPtr(pixelBuffer)), true);
125 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
130 /// Copy the data from this object into a new PixelData object, which could be
131 /// used for uploading to a texture.
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()
139 PixelData ret = new PixelData(NDalicPINVOKE.PixelBuffer_CreatePixelData(swigCPtr), true);
140 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
144 internal SWIGTYPE_p_unsigned_char GetBuffer()
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();
153 /// Gets the width of the buffer in pixels.
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()
161 uint ret = NDalicPINVOKE.PixelBuffer_GetWidth(swigCPtr);
162 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
167 /// Gets the height of the buffer in pixels.
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()
175 uint ret = NDalicPINVOKE.PixelBuffer_GetHeight(swigCPtr);
176 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
181 /// Gets the pixel format.
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()
189 PixelFormat ret = (PixelFormat)NDalicPINVOKE.PixelBuffer_GetPixelFormat(swigCPtr);
190 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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.
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.
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)
213 NDalicPINVOKE.PixelBuffer_ApplyMask__SWIG_0(swigCPtr, PixelBuffer.getCPtr(mask), contentScale, cropToMask);
214 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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.
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.
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)
235 NDalicPINVOKE.PixelBuffer_ApplyMask__SWIG_1(swigCPtr, PixelBuffer.getCPtr(mask), contentScale);
236 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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.
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.
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)
256 NDalicPINVOKE.PixelBuffer_ApplyMask__SWIG_2(swigCPtr, PixelBuffer.getCPtr(mask));
257 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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.
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)
270 NDalicPINVOKE.PixelBuffer_ApplyGaussianBlur(swigCPtr, blurRadius);
271 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
275 /// Crops this buffer to the given crop rectangle.
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)
286 NDalicPINVOKE.PixelBuffer_Crop(swigCPtr, x, y, width, height);
287 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
291 /// Resizes the buffer to the given dimensions.
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)
300 NDalicPINVOKE.PixelBuffer_Resize(swigCPtr, width, height);
301 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
304 internal PixelBuffer(SWIGTYPE_p_unsigned_char pointer) : this(NDalicPINVOKE.new_PixelBuffer__SWIG_2(SWIGTYPE_p_unsigned_char.getCPtr(pointer)), true)
306 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();