e445d095504a0dc5320baa4bb492615cefab728d
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia.Util / ImageUtil / ImageTransformGroup.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.Threading.Tasks;
18 using static Interop.ImageUtil;
19
20 namespace Tizen.Multimedia.Util
21 {
22     // TODO need to improve performance
23     /// <summary>
24     /// Represents a <see cref="ImageTransform"/> that is a composite of the transforms.
25     /// </summary>
26     /// <since_tizen> 4 </since_tizen>
27     public class ImageTransformGroup : ImageTransform
28     {
29         /// <summary>
30         /// Gets or sets the <see cref="ImageTransformCollection"/>.
31         /// </summary>
32         /// <since_tizen> 4 </since_tizen>
33         public ImageTransformCollection Children { get; set; }
34
35         /// <summary>
36         /// Initializes a new instance of the ImageTransformGroup class.
37         /// </summary>
38         /// <since_tizen> 4 </since_tizen>
39         public ImageTransformGroup()
40         {
41             Children = new ImageTransformCollection();
42         }
43
44         internal override void Configure(TransformHandle handle)
45         {
46             // intended blank
47         }
48
49         internal override async Task<MediaPacket> ApplyAsync(MediaPacket source)
50         {
51             if (Children.Count == 0)
52             {
53                 return source;
54             }
55
56             var items = Children;
57
58             MediaPacket curPacket = await items[0].ApplyAsync(source);
59
60             for (int i = 1; i < items.Count; ++i)
61             {
62                 var oldPacket = curPacket;
63                 try
64                 {
65                     curPacket = await items[i].ApplyAsync(curPacket);
66                 }
67                 finally
68                 {
69                     oldPacket.Dispose();
70                 }
71             }
72
73             return curPacket;
74         }
75
76         internal override string GenerateNotSupportedErrorMessage(VideoMediaFormat format)
77         {
78             return null;
79         }
80     }
81 }