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;
42 /// Create a PixelBuffer with its own data buffer.
44 /// <param name="width">The pixel buffer width.</param>
45 /// <param name="height">The pixel buffer height.</param>
46 /// <param name="pixelFormat">The pixel format.</param>
47 /// <since_tizen> 5 </since_tizen>
48 /// This will be released at Tizen.NET API Level 5. Therefore, currently this would be used as an in-house API.
49 [EditorBrowsable(EditorBrowsableState.Never)]
50 public PixelBuffer(uint width, uint height, PixelFormat pixelFormat) : this(Interop.PixelBuffer.PixelBuffer_New(width, height, (int)pixelFormat), true)
52 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
55 internal PixelBuffer(PixelBuffer handle) : this(Interop.PixelBuffer.new_PixelBuffer__SWIG_1(PixelBuffer.getCPtr(handle)), true)
57 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
60 internal PixelBuffer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.PixelBuffer.PixelBuffer_SWIGUpcast(cPtr), cMemoryOwn)
62 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
66 /// Convert to a pixel data and release the object of the pixelBuffer.
67 /// This handle is left empty.
68 /// Any other handles that keep a reference to this object
69 /// will be left with no buffer. Trying to access it will return NULL.
71 /// <param name="pixelBuffer">A pixel buffer.</param>
72 /// <returns>A new PixelData that takes ownership of the buffer of the pixelBuffer.</returns>
73 /// <since_tizen> 5 </since_tizen>
74 /// This will be released at Tizen.NET API Level 5. Therefore, currently this would be used as an in-house API.
75 [EditorBrowsable(EditorBrowsableState.Never)]
76 public static PixelData Convert(PixelBuffer pixelBuffer)
78 PixelData ret = new PixelData(Interop.PixelBuffer.PixelBuffer_Convert(PixelBuffer.getCPtr(pixelBuffer)), true);
79 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
84 /// Copy the data from this object into a new PixelData object, which could be
85 /// used for uploading to a texture.
87 /// <returns>The pixel data.</returns>
88 /// <since_tizen> 5 </since_tizen>
89 /// This will be released at Tizen.NET API Level 5. Therefore, currently this would be used as an in-house API.
90 [EditorBrowsable(EditorBrowsableState.Never)]
91 public PixelData CreatePixelData()
93 PixelData ret = new PixelData(Interop.PixelBuffer.PixelBuffer_CreatePixelData(swigCPtr), true);
94 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
99 /// Gets the width of the buffer in pixels.
101 /// <returns>The width of the buffer in pixels.</returns>
102 /// <since_tizen> 5 </since_tizen>
103 /// This will be released at Tizen.NET API Level 5. Therefore, currently this would be used as an in-house API.
104 [EditorBrowsable(EditorBrowsableState.Never)]
105 public uint GetWidth()
107 uint ret = Interop.PixelBuffer.PixelBuffer_GetWidth(swigCPtr);
108 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
113 /// Gets the height of the buffer in pixels.
115 /// <returns>The height of the buffer in pixels.</returns>
116 /// <since_tizen> 5 </since_tizen>
117 /// This will be released at Tizen.NET API Level 5. Therefore, currently this would be used as an in-house API.
118 [EditorBrowsable(EditorBrowsableState.Never)]
119 public uint GetHeight()
121 uint ret = Interop.PixelBuffer.PixelBuffer_GetHeight(swigCPtr);
122 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
127 /// Gets the pixel format.
129 /// <returns>The pixel format.</returns>
130 /// <since_tizen> 5 </since_tizen>
131 /// This will be released at Tizen.NET API Level 5. Therefore, currently this would be used as an in-house API.
132 [EditorBrowsable(EditorBrowsableState.Never)]
133 public PixelFormat GetPixelFormat()
135 PixelFormat ret = (PixelFormat)Interop.PixelBuffer.PixelBuffer_GetPixelFormat(swigCPtr);
136 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
141 /// Apply the mask to this pixel data and return a new pixel data that contains
142 /// the masked image. If this PixelBuffer does not have an alpha channel, then
143 /// the resultant PixelBuffer will be converted to a format that supports at
144 /// least the width of the color channels and the alpha channel from the mask.
146 /// If cropToMask is set to <c>true</c>, then the contentScale is applied first to
147 /// this buffer, and the target buffer is cropped to the size of the mask. If
148 /// it is set to <c>false</c>, then the mask is scaled to match the size of this buffer
149 /// before the mask is applied.
151 /// <param name="mask">The mask to apply.</param>
152 /// <param name="contentScale">The scaling factor to apply to the content.</param>
153 /// <param name="cropToMask">Whether to crop the output to the mask size (true) or scale the mask to the content size (false).</param>
154 /// <since_tizen> 5 </since_tizen>
155 /// This will be released at Tizen.NET API Level 5. Therefore, currently this would be used as an in-house API.
156 [EditorBrowsable(EditorBrowsableState.Never)]
157 public void ApplyMask(PixelBuffer mask, float contentScale, bool cropToMask)
159 Interop.PixelBuffer.PixelBuffer_ApplyMask__SWIG_0(swigCPtr, PixelBuffer.getCPtr(mask), contentScale, cropToMask);
160 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
164 /// Apply the mask to this pixel data and return a new pixel data containing
165 /// the masked image. If this PixelBuffer does not have an alpha channel, then
166 /// the resultant PixelBuffer will be converted to a format that supports at
167 /// least the width of the color channels and the alpha channel from the mask.
169 /// If cropToMask is set to <c>true</c>, then the contentScale is applied first to
170 /// this buffer, and the target buffer is cropped to the size of the mask. If
171 /// it is set to <c>false</c>, then the mask is scaled to match the size of this buffer
172 /// before the mask is applied.
174 /// <param name="mask">The mask to apply.</param>
175 /// <param name="contentScale">The scaling factor to apply to the content.</param>
176 /// <since_tizen> 5 </since_tizen>
177 /// This will be released at Tizen.NET API Level 5. Therefore, currently this would be used as an in-house API.
178 [EditorBrowsable(EditorBrowsableState.Never)]
179 public void ApplyMask(PixelBuffer mask, float contentScale)
181 Interop.PixelBuffer.PixelBuffer_ApplyMask__SWIG_1(swigCPtr, PixelBuffer.getCPtr(mask), contentScale);
182 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
186 /// Apply the mask to this pixel data and return a new pixel data containing
187 /// the masked image. If this PixelBuffer does not have an alpha channel, then
188 /// the resultant PixelBuffer will be converted to a format that supports at
189 /// least the width of the color channels and the alpha channel from the mask.
191 /// If cropToMask is set to <c>true</c>, then the contentScale is applied first to
192 /// this buffer, and the target buffer is cropped to the size of the mask. If
193 /// it is set to <c>false</c>, then the mask is scaled to match the size of this buffer
194 /// before the mask is applied.
196 /// <param name="mask">The mask to apply.</param>
197 /// <since_tizen> 5 </since_tizen>
198 /// This will be released at Tizen.NET API Level 5. Therefore, currently this would be used as an in-house API.
199 [EditorBrowsable(EditorBrowsableState.Never)]
200 public void ApplyMask(PixelBuffer mask)
202 Interop.PixelBuffer.PixelBuffer_ApplyMask__SWIG_2(swigCPtr, PixelBuffer.getCPtr(mask));
203 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
207 /// Apply a Gaussian blur to this pixel data with the given radius.
208 /// A bigger radius will yield a blurrier image. Only works for pixel data in RGBA format.
210 /// <param name="blurRadius">The radius for Gaussian blur. A value of 0 or negative value indicates no blur.</param>
211 /// <since_tizen> 5 </since_tizen>
212 /// This will be released at Tizen.NET API Level 5. Therefore, currently this would be used as an in-house API.
213 [EditorBrowsable(EditorBrowsableState.Never)]
214 public void ApplyGaussianBlur(float blurRadius)
216 Interop.PixelBuffer.PixelBuffer_ApplyGaussianBlur(swigCPtr, blurRadius);
217 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
221 /// Crops this buffer to the given crop rectangle.
223 /// <param name="x">The top left corner's X.</param>
224 /// <param name="y">The top left corner's Y.</param>
225 /// <param name="width">The crop width.</param>
226 /// <param name="height">The crop height.</param>
227 /// <since_tizen> 5 </since_tizen>
228 /// This will be released at Tizen.NET API Level 5. Therefore, currently this would be used as an in-house API.
229 [EditorBrowsable(EditorBrowsableState.Never)]
230 public void Crop(ushort x, ushort y, ushort width, ushort height)
232 Interop.PixelBuffer.PixelBuffer_Crop(swigCPtr, x, y, width, height);
233 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
237 /// Resizes the buffer to the given dimensions.
239 /// <param name="width">The new width.</param>
240 /// <param name="height">The new height.</param>
241 /// <since_tizen> 5 </since_tizen>
242 /// This will be released at Tizen.NET API Level 5. Therefore, currently this would be used as an in-house API.
243 [EditorBrowsable(EditorBrowsableState.Never)]
244 public void Resize(ushort width, ushort height)
246 Interop.PixelBuffer.PixelBuffer_Resize(swigCPtr, width, height);
247 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
251 /// Rotate the buffer by the given angle.
253 /// <param name="angle">The angle in degrees.</param>
254 /// <since_tizen> 8 </since_tizen>
255 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
256 [EditorBrowsable(EditorBrowsableState.Never)]
257 public bool Rotate(Degree angle)
259 bool ret = Interop.PixelBuffer.PixelBuffer_Rotate(swigCPtr, Degree.getCPtr(angle));
260 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
265 /// Gets the pixel buffer
267 /// <since_tizen> 8 </since_tizen>
268 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
269 [EditorBrowsable(EditorBrowsableState.Never)]
270 public global::System.IntPtr GetBuffer()
272 global::System.IntPtr ret = Interop.PixelBuffer.PixelBuffer_GetBuffer(swigCPtr);
273 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
277 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(PixelBuffer obj)
279 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
282 internal PixelBuffer Assign(PixelBuffer rhs)
284 PixelBuffer ret = new PixelBuffer(Interop.PixelBuffer.PixelBuffer_Assign(swigCPtr, PixelBuffer.getCPtr(rhs)), false);
285 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
292 /// <since_tizen> 5 </since_tizen>
293 protected override void Dispose(DisposeTypes type)
300 //Release your own unmanaged resources here.
301 //You should not access any managed member here except static instance.
302 //Because the execution order of Finalizes is non-deterministic.
303 if (swigCPtr.Handle != global::System.IntPtr.Zero)
308 Interop.PixelBuffer.delete_PixelBuffer(swigCPtr);
310 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);