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
41 /// Create a PixelBuffer with its own data buffer.
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)
51 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
54 internal PixelBuffer(PixelBuffer handle) : this(Interop.PixelBuffer.NewPixelBuffer(PixelBuffer.getCPtr(handle)), true)
56 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
59 internal PixelBuffer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.PixelBuffer.Upcast(cPtr), cMemoryOwn)
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.
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)
76 PixelData ret = new PixelData(Interop.PixelBuffer.Convert(PixelBuffer.getCPtr(pixelBuffer)), true);
77 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
82 /// Copy the data from this object into a new PixelData object, which could be
83 /// used for uploading to a texture.
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()
91 PixelData ret = new PixelData(Interop.PixelBuffer.CreatePixelData(swigCPtr), true);
92 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
97 /// Gets the width of the buffer in pixels.
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()
105 uint ret = Interop.PixelBuffer.GetWidth(swigCPtr);
106 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
111 /// Gets the height of the buffer in pixels.
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()
119 uint ret = Interop.PixelBuffer.GetHeight(swigCPtr);
120 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
125 /// Gets the pixel format.
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()
133 PixelFormat ret = (PixelFormat)Interop.PixelBuffer.GetPixelFormat(swigCPtr);
134 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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.
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.
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)
157 Interop.PixelBuffer.ApplyMask(swigCPtr, PixelBuffer.getCPtr(mask), contentScale, cropToMask);
158 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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.
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.
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)
179 Interop.PixelBuffer.ApplyMask(swigCPtr, PixelBuffer.getCPtr(mask), contentScale);
180 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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.
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.
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)
200 Interop.PixelBuffer.ApplyMask(swigCPtr, PixelBuffer.getCPtr(mask));
201 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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.
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)
214 Interop.PixelBuffer.ApplyGaussianBlur(swigCPtr, blurRadius);
215 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
219 /// Crops this buffer to the given crop rectangle.
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)
230 Interop.PixelBuffer.Crop(swigCPtr, x, y, width, height);
231 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
235 /// Resizes the buffer to the given dimensions.
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)
244 Interop.PixelBuffer.Resize(swigCPtr, width, height);
245 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
249 /// Rotate the buffer by the given angle.
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)
257 bool ret = Interop.PixelBuffer.Rotate(swigCPtr, Degree.getCPtr(angle));
258 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
263 /// Gets the pixel buffer
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()
270 global::System.IntPtr ret = Interop.PixelBuffer.GetBuffer(swigCPtr);
271 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
275 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(PixelBuffer obj)
277 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
280 internal PixelBuffer Assign(PixelBuffer rhs)
282 PixelBuffer ret = new PixelBuffer(Interop.PixelBuffer.Assign(swigCPtr, PixelBuffer.getCPtr(rhs)), false);
283 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
289 /// This will not be public opened.
290 [EditorBrowsable(EditorBrowsableState.Never)]
291 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
293 Interop.PixelBuffer.DeletePixelBuffer(swigCPtr);