[Multimedia.Util] Modified to throw NotSupportedException for NotSupported error...
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia.Util / ImageUtil / RotateTransform.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 System.Diagnostics;
19 using static Interop.ImageUtil;
20 using static Interop.ImageUtil.Transform;
21
22 namespace Tizen.Multimedia.Util
23 {
24     /// <summary>
25     /// Rotates an image.
26     /// </summary>
27     /// <seealso cref="Rotation"/>
28     /// <since_tizen> 4 </since_tizen>
29     public class RotateTransform : ImageTransform
30     {
31         private Rotation _rotation;
32
33         /// <summary>
34         /// Initializes a new instance of the <see cref="RotateTransform"/> class.
35         /// </summary>
36         /// <param name="rotation">The value how to rotate an image.</param>
37         /// <exception cref="ArgumentException"><paramref name="rotation"/> is invalid.</exception>
38         /// <exception cref="ArgumentOutOfRangeException"><paramref name="rotation"/> is <see cref="Rotation.Rotate90"/>.</exception>
39         /// <since_tizen> 4 </since_tizen>
40         public RotateTransform(Rotation rotation)
41         {
42             Rotation = rotation;
43         }
44
45         /// <summary>
46         /// Gets or sets the value how to rotate an image.
47         /// </summary>
48         /// <exception cref="ArgumentException"><paramref name="value"/> is invalid.</exception>
49         /// <exception cref="ArgumentOutOfRangeException"><paramref name="value"/> is <see cref="Rotation.Rotate90"/>.</exception>
50         /// <since_tizen> 4 </since_tizen>
51         public Rotation Rotation
52         {
53             get { return _rotation; }
54             set
55             {
56                 ValidationUtil.ValidateEnum(typeof(Rotation), value, nameof(Rotation));
57
58                 if (value == Rotation.Rotate0)
59                 {
60                     throw new ArgumentOutOfRangeException(nameof(value), "Rotation can't be Rotate0.");
61                 }
62
63                 _rotation = value;
64             }
65         }
66
67         internal override string GenerateNotSupportedErrorMessage(VideoMediaFormat format)
68             => $"'{format.MimeType}' is not supported by RotateTransform.";
69
70         internal override void Configure(TransformHandle handle)
71         {
72             SetRotation(handle, GetImageRotation());
73         }
74
75         private ImageRotation GetImageRotation()
76         {
77             switch (Rotation)
78             {
79                 case Rotation.Rotate90: return ImageRotation.Rotate90;
80                 case Rotation.Rotate180: return ImageRotation.Rotate180;
81                 case Rotation.Rotate270: return ImageRotation.Rotate270;
82             }
83
84             Debug.Fail("Rotation is invalid value!");
85             return ImageRotation.Rotate0;
86         }
87     }
88 }