/* * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using System; using System.Threading.Tasks; using static Interop; using NativeTransform = Interop.ImageUtil.Transform; namespace Tizen.Multimedia.Util { /// /// Flips an image. /// /// /// 4 public class FlipTransform : ImageTransform { private Flips _flip; /// /// Initializes a new instance of the class. /// /// The value how to flip an image. /// is invalid. /// is . /// 4 public FlipTransform(Flips flip) { Flip = flip; } /// /// Gets or sets the value how to flip an image. /// /// is invalid. /// is . /// 4 public Flips Flip { get { return _flip; } set { ValidationUtil.ValidateFlagsEnum(value, Flips.Horizontal | Flips.Vertical, nameof(Flips)); if (value == Flips.None) { throw new ArgumentOutOfRangeException(nameof(value), "Flip can't be None."); } _flip = value; } } internal override string GenerateNotSupportedErrorMessage(VideoMediaFormat format) => $"'{format.MimeType}' is not supported by FlipTransform."; internal override void Configure(TransformHandle handle) { // intended blank } private async Task ApplyAsync(TransformHandle handle, MediaPacket source, ImageRotation rotation) { NativeTransform.SetRotation(handle, rotation); return await RunAsync(handle, source); } internal override async Task ApplyAsync(MediaPacket source) { using (TransformHandle handle = CreateHandle()) { if (Flip.HasFlag(Flips.Vertical | Flips.Horizontal)) { var flipped = await ApplyAsync(handle, source, ImageRotation.FlipHorizontal); try { return await ApplyAsync(handle, flipped, ImageRotation.FlipVertical); } finally { flipped.Dispose(); } } return await ApplyAsync(handle, source, Flip.HasFlag(Flips.Horizontal) ? ImageRotation.FlipHorizontal : ImageRotation.FlipVertical); } } } }