Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia.Util / ImageUtil / ImageTransformer.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.Threading.Tasks;
19
20 namespace Tizen.Multimedia.Util
21 {
22     /// <summary>
23     /// Provides the ability to transform an image.
24     /// </summary>
25     public class ImageTransformer : IDisposable
26     {
27         /// <summary>
28         /// Initialize a new instance of the <see cref="ImageTransformer"/> class.
29         /// </summary>
30         public ImageTransformer()
31         {
32         }
33
34         /// <summary>
35         /// Transforms an image with <see cref="ImageTransform"/>.
36         /// </summary>
37         /// <param name="source"><see cref="MediaPacket"/> to transform. The <see cref="MediaPacket.Format"/> of this <paramref name="source"/> must be <see cref="VideoMediaFormat"/>.</param>
38         /// <param name="item"><see cref="ImageTransform"/> to apply.</param>
39         /// <returns>A task that represents the asynchronous transforming operation.</returns>
40         /// <exception cref="ArgumentNullException">
41         ///     <paramref name="source"/> is null.\n
42         ///     - or -\n
43         ///     <paramref name="item"/> is null.
44         /// </exception>
45         /// <exception cref="ObjectDisposedException">The <see cref="ImageTransformer"/> has already been disposed of.</exception>
46         /// <exception cref="InvalidOperationException">Failed to apply <see cref="ImageTransform"/>.</exception>
47         public Task<MediaPacket> TransformAsync(MediaPacket source, ImageTransform item)
48         {
49             if (_disposed)
50             {
51                 throw new ObjectDisposedException(nameof(ImageTransformer));
52             }
53
54             if (source == null)
55             {
56                 throw new ArgumentNullException(nameof(source));
57             }
58
59             if (item == null)
60             {
61                 throw new ArgumentNullException(nameof(item));
62             }
63
64             return item.ApplyAsync(source);
65         }
66
67         #region IDisposable Support
68         private bool _disposed = false;
69
70         /// <summary>
71         /// Releases the unmanaged resources used by the ImageTransformer.
72         /// </summary>
73         /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
74         protected virtual void Dispose(bool disposing)
75         {
76             if (!_disposed)
77             {
78                 _disposed = true;
79             }
80         }
81
82         /// <summary>
83         /// Releases all resources used by the ImageTransformer.
84         /// </summary>
85         public void Dispose()
86         {
87             Dispose(true);
88         }
89         #endregion
90     }
91 }