[Multimedia.Util] Modified to throw NotSupportedException for NotSupported error...
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia.Util / ImageUtil / ResizeTransform.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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 static Interop.ImageUtil;
19 using static Interop.ImageUtil.Transform;
20
21 namespace Tizen.Multimedia.Util
22 {
23     /// <summary>
24     /// Resizes an image.
25     /// </summary>
26     /// <since_tizen> 4 </since_tizen>
27     public class ResizeTransform : ImageTransform
28     {
29         private Size _size;
30
31         /// <summary>
32         /// Initializes a new instance of the <see cref="ResizeTransform"/> class.
33         /// </summary>
34         /// <param name="size">The size that an image is resized to.</param>
35         /// <exception cref="ArgumentOutOfRangeException">
36         ///     The width of <paramref name="size"/> is less than or equal to zero.<br/>
37         ///     -or-<br/>
38         ///     The height of <paramref name="size"/> is less than or equal to zero.
39         /// </exception>
40         /// <since_tizen> 4 </since_tizen>
41         public ResizeTransform(Size size)
42         {
43             Size = size;
44         }
45
46         internal override string GenerateNotSupportedErrorMessage(VideoMediaFormat format)
47             => $"'{format.MimeType}' is not supported by ResizeTransform.";
48
49         /// <summary>
50         /// Gets or sets the size that an image is resized to.
51         /// </summary>
52         /// <exception cref="ArgumentOutOfRangeException">
53         ///     The width of <paramref name="value"/> is less than or equal to zero.<br/>
54         ///     -or-<br/>
55         ///     The height of <paramref name="value"/> is less than or equal to zero.
56         /// </exception>
57         /// <since_tizen> 4 </since_tizen>
58         public Size Size
59         {
60             get { return _size; }
61             set
62             {
63                 if (value.Width <= 0)
64                 {
65                     throw new ArgumentOutOfRangeException(nameof(Size), value,
66                         "Width of the size can't be less than or equal to zero.");
67                 }
68
69                 if (value.Height <= 0)
70                 {
71                     throw new ArgumentOutOfRangeException(nameof(Size), value,
72                         "Height of the size can't be less than or equal to zero.");
73                 }
74
75                 _size = value;
76             }
77         }
78
79         internal override void Configure(TransformHandle handle)
80         {
81             SetResolution(handle, (uint)Size.Width, (uint)Size.Height);
82         }
83     }
84 }