[NUI] Fix build warning[CA1064]
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / ImageLoading.cs
1 /*
2  * Copyright(c) 2017 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17 using System;
18 using System.ComponentModel;
19
20 namespace Tizen.NUI
21 {
22
23     /// <summary>
24     /// Loading an image.
25     /// </summary>
26     /// <since_tizen> 5 </since_tizen>
27     /// This will be released at Tizen.NET API Level 5. Therefore, currently this would be used as an in-house API.
28     [EditorBrowsable(EditorBrowsableState.Never)]
29     public static class ImageLoading
30     {
31         /// <summary>
32         /// Load an image synchronously from local file.
33         /// </summary>
34         /// <param name="url">The URL of the image file to load.</param>
35         /// <param name="size">The width and height to fit the loaded image to, 0.0 means whole image.</param>
36         /// <param name="fittingMode">The method used to fit the shape of the image before loading to the shape defined by the size parameter.</param>
37         /// <param name="samplingMode">The filtering method used when sampling pixels from the input image while fitting it to desired size.</param>
38         /// <param name="orientationCorrection">Reorient the image to respect any orientation metadata in its header.</param>
39         /// <returns>Handle to the loaded PixelBuffer object or an empty handle in case loading failed.</returns>
40         /// <exception cref="ArgumentNullException"> Thrown when size is null. </exception>
41         /// <since_tizen> 5 </since_tizen>
42         /// This will be released at Tizen.NET API Level 5. Therefore, currently this would be used as an in-house API.
43         [EditorBrowsable(EditorBrowsableState.Never)]
44         public static PixelBuffer LoadImageFromFile(string url, Size2D size, FittingModeType fittingMode, SamplingModeType samplingMode, bool orientationCorrection)
45         {
46             if (null == size)
47             {
48                 throw new ArgumentNullException(nameof(size));
49             }
50             var uSize = new Uint16Pair((uint)size.Width, (uint)size.Height);
51             PixelBuffer ret = new PixelBuffer(Interop.ImageLoading.LoadImageFromFile(url, Uint16Pair.getCPtr(uSize), (int)fittingMode, (int)samplingMode, orientationCorrection), true);
52             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
53             return ret;
54         }
55
56         /// <summary>
57         /// Load an image synchronously from local file.
58         /// </summary>
59         /// <param name="url">The URL of the image file to load.</param>
60         /// <param name="size">The width and height to fit the loaded image to, 0.0 means whole image.</param>
61         /// <param name="fittingMode">The method used to fit the shape of the image before loading to the shape defined by the size parameter.</param>
62         /// <param name="samplingMode">The filtering method used when sampling pixels from the input image while fitting it to desired size.</param>
63         /// <returns>Handle to the loaded PixelBuffer object or an empty handle in case loading failed.</returns>
64         /// <exception cref="ArgumentNullException"> Thrown when size is null. </exception>
65         /// <since_tizen> 5 </since_tizen>
66         /// This will be released at Tizen.NET API Level 5, so currently this would be used as inhouse API.
67         [EditorBrowsable(EditorBrowsableState.Never)]
68         public static PixelBuffer LoadImageFromFile(string url, Size2D size, FittingModeType fittingMode, SamplingModeType samplingMode)
69         {
70             if (null == size)
71             {
72                 throw new ArgumentNullException(nameof(size));
73             }
74             var uSize = new Uint16Pair((uint)size.Width, (uint)size.Height);
75             PixelBuffer ret = new PixelBuffer(Interop.ImageLoading.LoadImageFromFile(url, Uint16Pair.getCPtr(uSize), (int)fittingMode, (int)samplingMode), true);
76             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
77             return ret;
78         }
79
80         /// <summary>
81         /// Load an image synchronously from local file.
82         /// </summary>
83         /// <param name="url">The URL of the image file to load.</param>
84         /// <param name="size">The width and height to fit the loaded image to, 0.0 means whole image.</param>
85         /// <param name="fittingMode">The method used to fit the shape of the image before loading to the shape defined by the size parameter.</param>
86         /// <returns>Handle to the loaded PixelBuffer object or an empty handle in case loading failed.</returns>
87         /// <exception cref="ArgumentNullException"> Thrown when size is null. </exception>
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 static PixelBuffer LoadImageFromFile(string url, Size2D size, FittingModeType fittingMode)
92         {
93             if (null == size)
94             {
95                 throw new ArgumentNullException(nameof(size));
96             }
97             var uSize = new Uint16Pair((uint)size.Width, (uint)size.Height);
98             PixelBuffer ret = new PixelBuffer(Interop.ImageLoading.LoadImageFromFile(url, Uint16Pair.getCPtr(uSize), (int)fittingMode), true);
99             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
100             return ret;
101         }
102
103         /// <summary>
104         /// Load an image synchronously from local file.
105         /// </summary>
106         /// <param name="url">The URL of the image file to load.</param>
107         /// <param name="size">The width and height to fit the loaded image to, 0.0 means whole image.</param>
108         /// <returns>Handle to the loaded PixelBuffer object or an empty handle in case loading failed.</returns>
109         /// <exception cref="ArgumentNullException"> Thrown when size is null. </exception>
110         /// <since_tizen> 5 </since_tizen>
111         /// This will be released at Tizen.NET API Level 5. Therefore, currently this would be used as an in-house API.
112         [EditorBrowsable(EditorBrowsableState.Never)]
113         public static PixelBuffer LoadImageFromFile(string url, Size2D size)
114         {
115             if (null == size)
116             {
117                 throw new ArgumentNullException(nameof(size));
118             }
119             var uSize = new Uint16Pair((uint)size.Width, (uint)size.Height);
120             PixelBuffer ret = new PixelBuffer(Interop.ImageLoading.LoadImageFromFile(url, Uint16Pair.getCPtr(uSize)), true);
121             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
122             return ret;
123         }
124
125         /// <summary>
126         /// Load an image synchronously from local file.
127         /// </summary>
128         /// <param name="url">The URL of the image file to load.</param>
129         /// <returns>Handle to the loaded PixelBuffer object or an empty handle in case loading failed.</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 static PixelBuffer LoadImageFromFile(string url)
134         {
135             PixelBuffer ret = new PixelBuffer(Interop.ImageLoading.LoadImageFromFile(url), true);
136             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
137             return ret;
138         }
139
140         /// <summary>
141         /// Determine the size of an image that LoadImageFromFile will provide when given the same image loading parameters.
142         /// </summary>
143         /// <param name="filename">The name of the image.</param>
144         /// <param name="size">The requested size for the image.</param>
145         /// <param name="fittingMode">The method to use to map the source image to the desired dimensions.</param>
146         /// <param name="samplingMode">The image filter to use if the image needs to be downsampled to the requested size.</param>
147         /// <param name="orientationCorrection">Whether to use image metadata to rotate or flip the image, for example, from portrait to landscape.</param>
148         /// <returns>Dimensions that image will have if it is loaded with given parameters.</returns>
149         /// <exception cref="ArgumentNullException"> Thrown when size is null. </exception>
150         /// <since_tizen> 5 </since_tizen>
151         /// This will be released at Tizen.NET API Level 5. Therefore, currently this would be used as an in-house API.
152         [EditorBrowsable(EditorBrowsableState.Never)]
153         public static Size2D GetClosestImageSize(string filename, Size2D size, FittingModeType fittingMode, SamplingModeType samplingMode, bool orientationCorrection)
154         {
155             if (null == size)
156             {
157                 throw new ArgumentNullException(nameof(size));
158             }
159             var uSize = new Uint16Pair((uint)size.Width, (uint)size.Height);
160             var val = new Uint16Pair(Interop.ImageLoading.GetClosestImageSize(filename, Uint16Pair.getCPtr(uSize), (int)fittingMode, (int)samplingMode, orientationCorrection), true);
161             Size2D ret = new Size2D(val.GetWidth(), val.GetHeight());
162             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
163             return ret;
164         }
165
166         /// <summary>
167         /// Determine the size of an image that LoadImageFromFile will provide when given the same image loading parameters.
168         /// </summary>
169         /// <param name="filename">The name of the image.</param>
170         /// <param name="size">The requested size for the image</param>
171         /// <param name="fittingMode">The method to use to map the source image to the desired dimensions.</param>
172         /// <param name="samplingMode">The image filter to use if the image needs to be downsampled to the requested size.</param>
173         /// <returns>Dimensions that image will have if it is loaded with given parameters.</returns>
174         /// <exception cref="ArgumentNullException"> Thrown when size is null. </exception>
175         /// <since_tizen> 5 </since_tizen>
176         /// This will be released at Tizen.NET API Level 5. Therefore, currently this would be used as an in-house API.
177         [EditorBrowsable(EditorBrowsableState.Never)]
178         public static Size2D GetClosestImageSize(string filename, Size2D size, FittingModeType fittingMode, SamplingModeType samplingMode)
179         {
180             if (null == size)
181             {
182                 throw new ArgumentNullException(nameof(size));
183             }
184             var uSize = new Uint16Pair((uint)size.Width, (uint)size.Height);
185             var val = new Uint16Pair(Interop.ImageLoading.GetClosestImageSize(filename, Uint16Pair.getCPtr(uSize), (int)fittingMode, (int)samplingMode), true);
186             Size2D ret = new Size2D(val.GetWidth(), val.GetHeight());
187             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
188             return ret;
189         }
190
191         /// <summary>
192         /// Determine the size of an image that LoadImageFromFile will provide when given the same image loading parameters.
193         /// </summary>
194         /// <param name="filename">The name of the image.</param>
195         /// <param name="size">The requested size for the image</param>
196         /// <param name="fittingMode">The method to use to map the source image to the desired dimensions.</param>
197         /// <returns>Dimensions that image will have if it is loaded with given parameters.</returns>
198         /// <exception cref="ArgumentNullException"> Thrown when size is null. </exception>
199         /// <since_tizen> 5 </since_tizen>
200         /// This will be released at Tizen.NET API Level 5. Therefore, currently this would be used as an in-house API.
201         [EditorBrowsable(EditorBrowsableState.Never)]
202         public static Size2D GetClosestImageSize(string filename, Size2D size, FittingModeType fittingMode)
203         {
204             if (null == size)
205             {
206                 throw new ArgumentNullException(nameof(size));
207             }
208             var uSize = new Uint16Pair((uint)size.Width, (uint)size.Height);
209             var val = new Uint16Pair(Interop.ImageLoading.GetClosestImageSize(filename, Uint16Pair.getCPtr(uSize), (int)fittingMode), true);
210             Size2D ret = new Size2D(val.GetWidth(), val.GetHeight());
211             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
212             return ret;
213         }
214
215         /// <summary>
216         /// Determine the size of an image that LoadImageFromFile will provide when given the same image loading parameters.
217         /// </summary>
218         /// <param name="filename">The name of the image.</param>
219         /// <param name="size">The requested size for the image</param>
220         /// <returns>Dimensions that image will have if it is loaded with given parameters.</returns>
221         /// <exception cref="ArgumentNullException"> Thrown when size is null. </exception>
222         /// <since_tizen> 5 </since_tizen>
223         /// This will be released at Tizen.NET API Level 5. Therefore, currently this would be used as an in-house API.
224         [EditorBrowsable(EditorBrowsableState.Never)]
225         public static Size2D GetClosestImageSize(string filename, Size2D size)
226         {
227             if (null == size)
228             {
229                 throw new ArgumentNullException(nameof(size));
230             }
231             var uSize = new Uint16Pair((uint)size.Width, (uint)size.Height);
232             var val = new Uint16Pair(Interop.ImageLoading.GetClosestImageSize(filename, Uint16Pair.getCPtr(uSize)), true);
233             Size2D ret = new Size2D(val.GetWidth(), val.GetHeight());
234             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
235             return ret;
236         }
237
238         /// <summary>
239         /// Determine the size of an image that LoadImageFromFile will provide when given the same image loading parameters.
240         /// </summary>
241         /// <param name="filename">The name of the image.</param>
242         /// <returns>Dimensions that image will have if it is loaded with given parameters.</returns>
243         /// <since_tizen> 5 </since_tizen>
244         /// This will be released at Tizen.NET API Level 5. Therefore, currently this would be used as an in-house API.
245         [EditorBrowsable(EditorBrowsableState.Never)]
246         public static Size2D GetClosestImageSize(string filename)
247         {
248             var val = new Uint16Pair(Interop.ImageLoading.GetClosestImageSize(filename), true);
249             Size2D ret = new Size2D(val.GetWidth(), val.GetHeight());
250             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
251             return ret;
252         }
253
254         /// <summary>
255         /// Get the size of an original image
256         /// </summary>
257         /// <param name="filename">The name of the image.</param>
258         /// <returns>Dimension of the original image.</returns>
259         /// <since_tizen> 5 </since_tizen>
260         /// This will be released at Tizen.NET API Level 5. Therefore, currently this would be used as an in-house API.
261         [EditorBrowsable(EditorBrowsableState.Never)]
262         public static Size2D GetOriginalImageSize(string filename)
263         {
264             var val = new Uint16Pair(Interop.ImageLoading.GetOriginalImageSize(filename), true);
265             Size2D ret = new Size2D(val.GetWidth(), val.GetHeight());
266             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
267             return ret;
268         }
269
270         /// <summary>
271         /// Load an image synchronously from a remote resource.
272         /// </summary>
273         /// <param name="url">The URL of the image file to load.</param>
274         /// <param name="size">The width and height to fit the loaded image to, 0.0 means whole image.</param>
275         /// <param name="fittingMode">The method used to fit the shape of the image before loading to the shape defined by the size parameter.</param>
276         /// <param name="samplingMode">The filtering method used when sampling pixels from the input image while fitting it to desired size.</param>
277         /// <param name="orientationCorrection">Reorient the image to respect any orientation metadata in its header.</param>
278         /// <returns>Handle to the loaded PixelBuffer object or an empty handle in case downloading or decoding failed.</returns>
279         /// <exception cref="ArgumentNullException"> Thrown when size is null. </exception>
280         /// <since_tizen> 5 </since_tizen>
281         /// This will be released at Tizen.NET API Level 5. Therefore, currently this would be used as an in-house API.
282         [EditorBrowsable(EditorBrowsableState.Never)]
283         public static PixelBuffer DownloadImageSynchronously(string url, Size2D size, FittingModeType fittingMode, SamplingModeType samplingMode, bool orientationCorrection)
284         {
285             if (null == size)
286             {
287                 throw new ArgumentNullException(nameof(size));
288             }
289             var uSize = new Uint16Pair((uint)size.Width, (uint)size.Height);
290             PixelBuffer ret = new PixelBuffer(Interop.ImageLoading.DownloadImageSynchronously(url, Uint16Pair.getCPtr(uSize), (int)fittingMode, (int)samplingMode, orientationCorrection), true);
291             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
292             return ret;
293         }
294
295         /// <summary>
296         /// Load an image synchronously from a remote resource.
297         /// </summary>
298         /// <param name="url">The URL of the image file to load.</param>
299         /// <param name="size">The width and height to fit the loaded image to, 0.0 means whole image.</param>
300         /// <param name="fittingMode">The method used to fit the shape of the image before loading to the shape defined by the size parameter.</param>
301         /// <param name="samplingMode">The filtering method used when sampling pixels from the input image while fitting it to desired size.</param>
302         /// <returns>Handle to the loaded PixelBuffer object or an empty handle in case downloading or decoding failed.</returns>
303         /// <exception cref="ArgumentNullException"> Thrown when size is null. </exception>
304         /// <since_tizen> 5 </since_tizen>
305         /// This will be released at Tizen.NET API Level 5. Therefore, currently this would be used as an in-house API.
306         [EditorBrowsable(EditorBrowsableState.Never)]
307         public static PixelBuffer DownloadImageSynchronously(string url, Size2D size, FittingModeType fittingMode, SamplingModeType samplingMode)
308         {
309             if (null == size)
310             {
311                 throw new ArgumentNullException(nameof(size));
312             }
313             var uSize = new Uint16Pair((uint)size.Width, (uint)size.Height);
314             PixelBuffer ret = new PixelBuffer(Interop.ImageLoading.DownloadImageSynchronously(url, Uint16Pair.getCPtr(uSize), (int)fittingMode, (int)samplingMode), true);
315             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
316             return ret;
317         }
318
319         /// <summary>
320         /// Load an image synchronously from a remote resource.
321         /// </summary>
322         /// <param name="url">The URL of the image file to load.</param>
323         /// <param name="size">The width and height to fit the loaded image to, 0.0 means whole image.</param>
324         /// <param name="fittingMode">The method used to fit the shape of the image before loading to the shape defined by the size parameter.</param>
325         /// <returns>Handle to the loaded PixelBuffer object or an empty handle in case downloading or decoding failed.</returns>
326         /// <exception cref="ArgumentNullException"> Thrown when size is null. </exception>
327         /// <since_tizen> 5 </since_tizen>
328         /// This will be released at Tizen.NET API Level 5. Therefore, currently this would be used as an in-house API.
329         [EditorBrowsable(EditorBrowsableState.Never)]
330         public static PixelBuffer DownloadImageSynchronously(string url, Size2D size, FittingModeType fittingMode)
331         {
332             if (null == size)
333             {
334                 throw new ArgumentNullException(nameof(size));
335             }
336             var uSize = new Uint16Pair((uint)size.Width, (uint)size.Height);
337             PixelBuffer ret = new PixelBuffer(Interop.ImageLoading.DownloadImageSynchronously(url, Uint16Pair.getCPtr(uSize), (int)fittingMode), true);
338             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
339             return ret;
340         }
341
342         /// <summary>
343         /// Load an image synchronously from a remote resource.
344         /// </summary>
345         /// <param name="url">The URL of the image file to load.</param>
346         /// <param name="size">The width and height to fit the loaded image to, 0.0 means whole image.</param>
347         /// <returns>Handle to the loaded PixelBuffer object or an empty handle in case downloading or decoding failed.</returns>
348         /// <exception cref="ArgumentNullException"> Thrown when size is null. </exception>
349         /// <since_tizen> 5 </since_tizen>
350         /// This will be released at Tizen.NET API Level 5. Therefore, currently this would be used as an in-house API.
351         [EditorBrowsable(EditorBrowsableState.Never)]
352         public static PixelBuffer DownloadImageSynchronously(string url, Size2D size)
353         {
354             if (null == size)
355             {
356                 throw new ArgumentNullException(nameof(size));
357             }
358             var uSize = new Uint16Pair((uint)size.Width, (uint)size.Height);
359             PixelBuffer ret = new PixelBuffer(Interop.ImageLoading.DownloadImageSynchronously(url, Uint16Pair.getCPtr(uSize)), true);
360             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
361             return ret;
362         }
363
364         /// <summary>
365         /// Load an image synchronously from a remote resource.
366         /// </summary>
367         /// <param name="url">The URL of the image file to load.</param>
368         /// <returns>Handle to the loaded PixelBuffer object or an empty handle in case downloading or decoding failed.</returns>
369         /// <since_tizen> 5 </since_tizen>
370         /// This will be released at Tizen.NET API Level 5. Therefore, currently this would be used as an in-house API.
371         [EditorBrowsable(EditorBrowsableState.Never)]
372         public static PixelBuffer DownloadImageSynchronously(string url)
373         {
374             PixelBuffer ret = new PixelBuffer(Interop.ImageLoading.DownloadImageSynchronously(url), true);
375             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
376             return ret;
377         }
378
379     }
380 }