2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using System.Threading.Tasks;
19 using static Interop.ImageUtil;
20 using static Interop.ImageUtil.Transform;
22 namespace Tizen.Multimedia.Util
27 /// <seealso cref="Rotation"/>
28 /// <since_tizen> 4 </since_tizen>
29 public class FlipTransform : ImageTransform
34 /// Initializes a new instance of the <see cref="FlipTransform"/> class.
36 /// <param name="flip">The value how to flip an image.</param>
37 /// <exception cref="ArgumentException"><paramref name="flip"/> is invalid.</exception>
38 /// <exception cref="ArgumentOutOfRangeException"><paramref name="flip"/> is <see cref="Flips.None"/>.</exception>
39 /// <since_tizen> 4 </since_tizen>
40 public FlipTransform(Flips flip)
46 /// Gets or sets the value how to flip an image.
48 /// <exception cref="ArgumentException"><paramref name="value"/> is invalid.</exception>
49 /// <exception cref="ArgumentOutOfRangeException"><paramref name="value"/> is <see cref="Flips.None"/>.</exception>
50 /// <since_tizen> 4 </since_tizen>
56 ValidationUtil.ValidateFlagsEnum(value, Flips.Horizontal | Flips.Vertical, nameof(Flips));
58 if (value == Flips.None)
60 throw new ArgumentOutOfRangeException(nameof(value), "Flip can't be None.");
67 internal override string GenerateNotSupportedErrorMessage(VideoMediaFormat format)
68 => $"'{format.MimeType}' is not supported by FlipTransform.";
70 internal override void Configure(TransformHandle handle)
75 private async Task<MediaPacket> ApplyAsync(TransformHandle handle, MediaPacket source,
76 ImageRotation rotation)
78 SetRotation(handle, rotation);
79 return await RunAsync(handle, source);
82 internal override async Task<MediaPacket> ApplyAsync(MediaPacket source)
84 using (TransformHandle handle = CreateHandle())
86 if (Flip.HasFlag(Flips.Vertical | Flips.Horizontal))
88 var flipped = await ApplyAsync(handle, source, ImageRotation.FlipHorizontal);
91 return await ApplyAsync(handle, flipped, ImageRotation.FlipVertical);
99 return await ApplyAsync(handle, source, Flip.HasFlag(Flips.Horizontal) ?
100 ImageRotation.FlipHorizontal : ImageRotation.FlipVertical);