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.
21 /// The PixelBuffer object holds a pixel buffer.
22 /// The PixelBuffer keeps ownership of it's initial buffer however, the
23 /// user is free to modify the pixel data, either directly, or via image operations.
25 /// In order to upload the pixel data to texture memory, there are two
26 /// possibilities - either convert it back to a PixelData object, which
27 /// releases the PixelBuffer object, leaving the user with an empty handle
28 /// (ideal for one-time indirect image manipulation), or create a new
29 /// PixelData object from this object, leaving the buffer intact (ideal
30 /// for continuous manipulation)
32 public class PixelBuffer : BaseHandle
34 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
36 internal PixelBuffer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.PixelBuffer_SWIGUpcast(cPtr), cMemoryOwn)
38 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
41 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(PixelBuffer obj)
43 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
49 /// <since_tizen> 5 </since_tizen>
50 protected override void Dispose(DisposeTypes type)
57 if (type == DisposeTypes.Explicit)
60 //Release your own managed resources here.
61 //You should release all of your own disposable objects here.
65 //Release your own unmanaged resources here.
66 //You should not access any managed member here except static instance.
67 //because the execution order of Finalizes is non-deterministic.
68 if (swigCPtr.Handle != global::System.IntPtr.Zero)
73 NDalicPINVOKE.delete_PixelBuffer(swigCPtr);
75 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
82 /// Create a PixelBuffer with it's own data buffer.
84 /// <param name="width">The pixel buffer width</param>
85 /// <param name="height">The pixel buffer height</param>
86 /// <param name="pixelFormat">The pixel format</param>
87 public PixelBuffer(uint width, uint height, PixelFormat pixelFormat) : this(NDalicPINVOKE.PixelBuffer_New(width, height, (int)pixelFormat), true)
89 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
92 internal PixelBuffer(PixelBuffer handle) : this(NDalicPINVOKE.new_PixelBuffer__SWIG_1(PixelBuffer.getCPtr(handle)), true)
94 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
97 internal PixelBuffer Assign(PixelBuffer rhs)
99 PixelBuffer ret = new PixelBuffer(NDalicPINVOKE.PixelBuffer_Assign(swigCPtr, PixelBuffer.getCPtr(rhs)), false);
100 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
105 /// Convert to a pixel data and release the pixelBuffer's object.
106 /// This handle is left empty.
107 /// Any other handles that keep a reference to this object
108 /// will be left with no buffer, trying to access it will return NULL.
110 /// <param name="pixelBuffer">A pixel buffer</param>
111 /// <returns>A new PixelData which takes ownership of the PixelBuffer's buffer.</returns>
112 public static PixelData Convert(PixelBuffer pixelBuffer)
114 PixelData ret = new PixelData(NDalicPINVOKE.PixelBuffer_Convert(PixelBuffer.getCPtr(pixelBuffer)), true);
115 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
120 /// Copy the data from this object into a new PixelData object, which could be
121 /// used for uploading to a texture.
123 /// <returns>.</returns>
124 public PixelData CreatePixelData()
126 PixelData ret = new PixelData(NDalicPINVOKE.PixelBuffer_CreatePixelData(swigCPtr), true);
127 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
131 internal SWIGTYPE_p_unsigned_char GetBuffer()
133 global::System.IntPtr cPtr = NDalicPINVOKE.PixelBuffer_GetBuffer(swigCPtr);
134 SWIGTYPE_p_unsigned_char ret = (cPtr == global::System.IntPtr.Zero) ? null : new SWIGTYPE_p_unsigned_char(cPtr, false);
135 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
140 /// Gets the width of the buffer in pixels.
142 /// <returns>The width of the buffer in pixels.</returns>
143 public uint GetWidth()
145 uint ret = NDalicPINVOKE.PixelBuffer_GetWidth(swigCPtr);
146 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
151 /// Gets the height of the buffer in pixels.
153 /// <returns>The height of the buffer in pixels.</returns>
154 public uint GetHeight()
156 uint ret = NDalicPINVOKE.PixelBuffer_GetHeight(swigCPtr);
157 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
162 /// Gets the pixel format.
164 /// <returns>The pixel format.</returns>
165 public PixelFormat GetPixelFormat()
167 PixelFormat ret = (PixelFormat)NDalicPINVOKE.PixelBuffer_GetPixelFormat(swigCPtr);
168 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
173 /// Apply the mask to this pixel data, and return a new pixel data containing
174 /// the masked image. If this PixelBuffer doesn't have an alpha channel, then
175 /// the resultant PixelBuffer will be converted to a format that supports at
176 /// least the width of the color channels and the alpha channel from the mask.
178 /// If cropToMask is set to true, then the contentScale is applied first to
179 /// this buffer, and the target buffer is cropped to the size of the mask. If
180 /// it's set to false, then the mask is scaled to match this buffer's size
181 /// before the mask is applied.
183 /// <param name="mask">The mask to apply.</param>
184 /// <param name="contentScale">The scaling factor to apply to the content.</param>
185 /// <param name="cropToMask">Whether to crop the output to the mask size (true) or scale the mask to the content size (false).</param>
186 public void ApplyMask(PixelBuffer mask, float contentScale, bool cropToMask)
188 NDalicPINVOKE.PixelBuffer_ApplyMask__SWIG_0(swigCPtr, PixelBuffer.getCPtr(mask), contentScale, cropToMask);
189 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
193 /// Apply the mask to this pixel data, and return a new pixel data containing
194 /// the masked image. If this PixelBuffer doesn't have an alpha channel, then
195 /// the resultant PixelBuffer will be converted to a format that supports at
196 /// least the width of the color channels and the alpha channel from the mask.
198 /// If cropToMask is set to true, then the contentScale is applied first to
199 /// this buffer, and the target buffer is cropped to the size of the mask. If
200 /// it's set to false, then the mask is scaled to match this buffer's size
201 /// before the mask is applied.
203 /// <param name="mask">The mask to apply.</param>
204 /// <param name="contentScale">The scaling factor to apply to the content.</param>
205 /// <returns>.</returns>
206 public void ApplyMask(PixelBuffer mask, float contentScale)
208 NDalicPINVOKE.PixelBuffer_ApplyMask__SWIG_1(swigCPtr, PixelBuffer.getCPtr(mask), contentScale);
209 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
213 /// Apply the mask to this pixel data, and return a new pixel data containing
214 /// the masked image. If this PixelBuffer doesn't have an alpha channel, then
215 /// the resultant PixelBuffer will be converted to a format that supports at
216 /// least the width of the color channels and the alpha channel from the mask.
218 /// If cropToMask is set to true, then the contentScale is applied first to
219 /// this buffer, and the target buffer is cropped to the size of the mask. If
220 /// it's set to false, then the mask is scaled to match this buffer's size
221 /// before the mask is applied.
223 /// <param name="mask">The mask to apply.</param>
224 public void ApplyMask(PixelBuffer mask)
226 NDalicPINVOKE.PixelBuffer_ApplyMask__SWIG_2(swigCPtr, PixelBuffer.getCPtr(mask));
227 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
231 /// Apply a Gaussian blur to this pixel data with the given radius.
232 /// A bigger radius will yield a blurrier image. Only works for pixel data in RGBA format.
234 /// <param name="blurRadius">The radius for Gaussian blur. A value of 0 or negative value indicates no blur.</param>
235 public void ApplyGaussianBlur(float blurRadius)
237 NDalicPINVOKE.PixelBuffer_ApplyGaussianBlur(swigCPtr, blurRadius);
238 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
242 /// Crops this buffer to the given crop rectangle.
244 /// <param name="x">The top left corner's X.</param>
245 /// <param name="y">The top left corner's Y.</param>
246 /// <param name="width">The crop width.</param>
247 /// <param name="height">The crop height.</param>
248 public void Crop(ushort x, ushort y, ushort width, ushort height)
250 NDalicPINVOKE.PixelBuffer_Crop(swigCPtr, x, y, width, height);
251 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
255 /// Resizes the buffer to the given dimensions.
257 /// <param name="width">The new width.</param>
258 /// <param name="height">The new height.</param>
259 public void Resize(ushort width, ushort height)
261 NDalicPINVOKE.PixelBuffer_Resize(swigCPtr, width, height);
262 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
265 public PropertyMap GetMetadata()
267 var retval = new PropertyMap();
268 NDalicPINVOKE.PixelBuffer_GetMetadata(swigCPtr, PropertyMap.getCPtr(retval));
269 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
273 internal PixelBuffer(SWIGTYPE_p_unsigned_char pointer) : this(NDalicPINVOKE.new_PixelBuffer__SWIG_2(SWIGTYPE_p_unsigned_char.getCPtr(pointer)), true)
275 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();