[Multimedia.Util] Modified to throw NotSupportedException for NotSupported error...
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia.Util / ImageUtil / ColorSpaceTransform.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.Collections.Generic;
19 using static Interop.ImageUtil;
20 using static Interop.ImageUtil.Transform;
21
22 namespace Tizen.Multimedia.Util
23 {
24     /// <summary>
25     /// Changes the colorspace of an image.
26     /// </summary>
27     /// <seealso cref="ColorSpace"/>
28     /// <since_tizen> 4 </since_tizen>
29     public class ColorSpaceTransform : ImageTransform
30     {
31         private ImageColorSpace _imageColorSpace;
32
33         /// <summary>
34         /// Initializes a new instance of the <see cref="ColorSpaceTransform"/> class.
35         /// </summary>
36         /// <param name="colorSpace">The colorspace of output image.</param>
37         /// <exception cref="ArgumentException"><paramref name="colorSpace"/> is invalid.</exception>
38         /// <exception cref="NotSupportedException"><paramref name="colorSpace"/> is not supported.</exception>
39         /// <seealso cref="SupportedColorSpaces"/>
40         /// <since_tizen> 4 </since_tizen>
41         public ColorSpaceTransform(ColorSpace colorSpace)
42         {
43             ColorSpace = colorSpace;
44         }
45
46         /// <summary>
47         /// Gets or sets the colorspace of the result image.
48         /// </summary>
49         /// <exception cref="ArgumentException"><paramref name="value"/> is invalid.</exception>
50         /// <exception cref="NotSupportedException"><paramref name="value"/> is not supported.</exception>
51         /// <seealso cref="SupportedColorSpaces"/>
52         /// <since_tizen> 4 </since_tizen>
53         public ColorSpace ColorSpace
54         {
55             get { return _imageColorSpace.ToCommonColorSpace(); }
56             set
57             {
58                 ValidationUtil.ValidateEnum(typeof(ColorSpace), value, nameof(ColorSpace));
59
60                 _imageColorSpace = value.ToImageColorSpace();
61             }
62         }
63
64         internal override string GenerateNotSupportedErrorMessage(VideoMediaFormat format)
65             => $"Converting colorspace from '{format.MimeType}' to '{ColorSpace.ToString()}' is not supported.";
66
67         internal override void Configure(TransformHandle handle)
68         {
69             SetColorspace(handle, _imageColorSpace);
70         }
71
72
73         /// <summary>
74         /// Gets the supported colorspaces for <see cref="ColorSpaceTransform"/>.
75         /// </summary>
76         /// <since_tizen> 4 </since_tizen>
77         public static IEnumerable<ColorSpace> SupportedColorSpaces
78         {
79             get
80             {
81                 foreach (ImageColorSpace value in Enum.GetValues(typeof(ImageColorSpace)))
82                 {
83                     yield return value.ToCommonColorSpace();
84                 }
85             }
86         }
87     }
88 }