From 965ae561e89ad5b0c46a8365011e390acef8fd41 Mon Sep 17 00:00:00 2001 From: coderhyme Date: Tue, 30 May 2017 17:18:21 +0900 Subject: [PATCH] Added Rotation and Flip enums for common use. Change-Id: I5ffee417a33960792d9e465e2243ea48688d98e8 Signed-off-by: coderhyme --- .../Camera/CameraDisplaySettings.cs | 20 ++- src/Tizen.Multimedia.Camera/Camera/CameraEnums.cs | 48 -------- .../Camera/CameraFeatures.cs | 18 +-- .../Camera/CameraSettings.cs | 12 +- .../Interop/Interop.CameraDisplay.cs | 8 +- .../Interop/Interop.CameraFeatures.cs | 4 +- .../Interop/Interop.CameraSettings.cs | 8 +- .../Interop/Interop.Display.cs | 2 +- .../Player/PlayerDisplaySettings.cs | 6 +- .../Player/PlayerEnums.cs | 29 ----- .../Interop/Interop.RecorderSettings.cs | 4 +- .../Recorder/RecorderEnums.cs | 26 +--- .../Recorder/RecorderSettings.cs | 8 +- .../ImageUtil/ImageRotation.cs | 2 +- .../ImageUtil/ImageTransform.cs | 134 ++++++++++++++++++--- .../ImageUtil/ImageTransformer.cs | 15 +-- .../Interop/Interop.ImageUtil.Transform.cs | 3 - .../Common.Internal/ValdiationUtil.cs | 9 ++ src/Tizen.Multimedia/Common/Flips.cs | 42 +++++++ src/Tizen.Multimedia/Common/Rotation.cs | 44 +++++++ 20 files changed, 262 insertions(+), 180 deletions(-) create mode 100644 src/Tizen.Multimedia/Common/Flips.cs create mode 100644 src/Tizen.Multimedia/Common/Rotation.cs diff --git a/src/Tizen.Multimedia.Camera/Camera/CameraDisplaySettings.cs b/src/Tizen.Multimedia.Camera/Camera/CameraDisplaySettings.cs index 0ded01e..b5d3058 100755 --- a/src/Tizen.Multimedia.Camera/Camera/CameraDisplaySettings.cs +++ b/src/Tizen.Multimedia.Camera/Camera/CameraDisplaySettings.cs @@ -83,15 +83,13 @@ namespace Tizen.Multimedia /// The display rotation. /// /// 3 - /// A that specifies the rotation of camera device. + /// A that specifies the rotation of camera device. /// The camera already has been disposed. - public CameraRotation Rotation + public Rotation Rotation { get { - CameraRotation val = CameraRotation.None; - - CameraErrorFactory.ThrowIfError(Native.GetRotation(_camera.GetHandle(), out val), + CameraErrorFactory.ThrowIfError(Native.GetRotation(_camera.GetHandle(), out var val), "Failed to get display rotation"); return val; @@ -99,7 +97,8 @@ namespace Tizen.Multimedia set { - ValidationUtil.ValidateEnum(typeof(CameraRotation), value); + ValidationUtil.ValidateEnum(typeof(Rotation), value); + CameraErrorFactory.ThrowIfError(Native.SetRotation(_camera.GetHandle(), value), "Failed to set display rotation."); } @@ -111,13 +110,11 @@ namespace Tizen.Multimedia /// 3 /// A that specifies camera flip type. /// The camera already has been disposed. - public CameraFlip Flip + public Flips Flip { get { - CameraFlip val = CameraFlip.None; - - CameraErrorFactory.ThrowIfError(Native.GetFlip(_camera.GetHandle(), out val), + CameraErrorFactory.ThrowIfError(Native.GetFlip(_camera.GetHandle(), out var val), "Failed to get display flip"); return val; @@ -125,7 +122,8 @@ namespace Tizen.Multimedia set { - ValidationUtil.ValidateEnum(typeof(CameraFlip), value); + ValidationUtil.ValidateFlagsEnum(value, Flips.Horizontal | Flips.Vertical, nameof(Flips)); + CameraErrorFactory.ThrowIfError(Native.SetFlip(_camera.GetHandle(), value), "Failed to set display flip."); } diff --git a/src/Tizen.Multimedia.Camera/Camera/CameraEnums.cs b/src/Tizen.Multimedia.Camera/Camera/CameraEnums.cs index 2e25a6e..65dce11 100755 --- a/src/Tizen.Multimedia.Camera/Camera/CameraEnums.cs +++ b/src/Tizen.Multimedia.Camera/Camera/CameraEnums.cs @@ -87,30 +87,6 @@ namespace Tizen.Multimedia } /// - /// Enumeration for the camera flip type. - /// - /// 3 - public enum CameraFlip - { - /// - /// No Flip. - /// - None, - /// - /// Horizontal flip. - /// - Horizontal, - /// - /// Vertical flip. - /// - Vertical, - /// - /// Horizontal and vertical flip. - /// - Both - } - - /// /// Enumeration for the camera focus state. /// /// 3 @@ -227,30 +203,6 @@ namespace Tizen.Multimedia } /// - /// Enumeration for the camera rotation type. - /// - /// 3 - public enum CameraRotation - { - /// - /// No rotation. - /// - None, - /// - /// 90 degree rotation. - /// - Rotation90, - /// - /// 180 degree rotation. - /// - Rotation180, - /// - /// 270 degree rotation. - /// - Rotation270 - } - - /// /// Enumeration for the camera state. /// /// 3 diff --git a/src/Tizen.Multimedia.Camera/Camera/CameraFeatures.cs b/src/Tizen.Multimedia.Camera/Camera/CameraFeatures.cs index 2361a9f..db46792 100755 --- a/src/Tizen.Multimedia.Camera/Camera/CameraFeatures.cs +++ b/src/Tizen.Multimedia.Camera/Camera/CameraFeatures.cs @@ -43,8 +43,8 @@ namespace Tizen.Multimedia private List _flashModes; private List _sceneModes; private List _effectModes; - private List _streamRotations; - private List _streamFlips; + private List _streamRotations; + private List _streamFlips; private List _ptzTypes; private delegate CameraError GetRangeDelegate(IntPtr handle, out int min, out int max); @@ -707,10 +707,10 @@ namespace Tizen.Multimedia /// /// 3 /// - /// It returns a list containing all the supported . + /// An IEnumerable containing all the supported . /// /// The camera already has been disposed. - public IEnumerable SupportedStreamRotations + public IEnumerable SupportedStreamRotations { get { @@ -718,9 +718,9 @@ namespace Tizen.Multimedia { try { - _streamRotations = new List(); + _streamRotations = new List(); - NativeFeatures.StreamRotationCallback callback = (CameraRotation streamRotation, IntPtr userData) => + NativeFeatures.StreamRotationCallback callback = (streamRotation, _) => { _streamRotations.Add(streamRotation); return true; @@ -747,7 +747,7 @@ namespace Tizen.Multimedia /// It returns a list containing all the supported . /// /// The camera already has been disposed. - public IEnumerable SupportedStreamFlips + public IEnumerable SupportedStreamFlips { get { @@ -755,9 +755,9 @@ namespace Tizen.Multimedia { try { - _streamFlips = new List(); + _streamFlips = new List(); - NativeFeatures.StreamFlipCallback callback = (CameraFlip streamFlip, IntPtr userData) => + NativeFeatures.StreamFlipCallback callback = (streamFlip, _) => { _streamFlips.Add(streamFlip); return true; diff --git a/src/Tizen.Multimedia.Camera/Camera/CameraSettings.cs b/src/Tizen.Multimedia.Camera/Camera/CameraSettings.cs index d188ef5..71042b9 100755 --- a/src/Tizen.Multimedia.Camera/Camera/CameraSettings.cs +++ b/src/Tizen.Multimedia.Camera/Camera/CameraSettings.cs @@ -755,9 +755,9 @@ namespace Tizen.Multimedia /// The stream rotation. /// /// 3 - /// A that specifies the rotation of camera device. + /// A that specifies the rotation of camera device. /// The camera already has been disposed. - public CameraRotation StreamRotation + public Rotation StreamRotation { get { @@ -769,7 +769,8 @@ namespace Tizen.Multimedia set { - ValidationUtil.ValidateEnum(typeof(CameraRotation), value); + ValidationUtil.ValidateEnum(typeof(Rotation), value); + CameraErrorFactory.ThrowIfError(Native.SetStreamRotation(_camera.GetHandle(), value), "Failed to set camera stream rotation."); } @@ -781,7 +782,7 @@ namespace Tizen.Multimedia /// 3 /// A that specifies camera flip type. /// The camera already has been disposed. - public CameraFlip StreamFlip + public Flips StreamFlip { get { @@ -793,7 +794,8 @@ namespace Tizen.Multimedia set { - ValidationUtil.ValidateEnum(typeof(CameraFlip), value); + ValidationUtil.ValidateFlagsEnum(value, Flips.Horizontal | Flips.Vertical, nameof(Flips)); + CameraErrorFactory.ThrowIfError(Native.SetFlip(_camera.GetHandle(), value), "Failed to set camera flip."); } diff --git a/src/Tizen.Multimedia.Camera/Interop/Interop.CameraDisplay.cs b/src/Tizen.Multimedia.Camera/Interop/Interop.CameraDisplay.cs index 6f88d4a..001aa42 100644 --- a/src/Tizen.Multimedia.Camera/Interop/Interop.CameraDisplay.cs +++ b/src/Tizen.Multimedia.Camera/Interop/Interop.CameraDisplay.cs @@ -35,16 +35,16 @@ internal static partial class Interop internal static extern CameraError SetVisible(IntPtr handle, bool visible); [DllImport(Libraries.Camera, EntryPoint = "camera_get_display_rotation")] - internal static extern CameraError GetRotation(IntPtr handle, out CameraRotation rotation); + internal static extern CameraError GetRotation(IntPtr handle, out Rotation rotation); [DllImport(Libraries.Camera, EntryPoint = "camera_set_display_rotation")] - internal static extern CameraError SetRotation(IntPtr handle, CameraRotation rotation); + internal static extern CameraError SetRotation(IntPtr handle, Rotation rotation); [DllImport(Libraries.Camera, EntryPoint = "camera_get_display_flip")] - internal static extern CameraError GetFlip(IntPtr handle, out CameraFlip flip); + internal static extern CameraError GetFlip(IntPtr handle, out Flips flip); [DllImport(Libraries.Camera, EntryPoint = "camera_set_display_flip")] - internal static extern CameraError SetFlip(IntPtr handle, CameraFlip flip); + internal static extern CameraError SetFlip(IntPtr handle, Flips flip); [DllImport(Libraries.Camera, EntryPoint = "camera_attr_get_display_roi_area")] internal static extern CameraError GetRoiArea(IntPtr handle, out int x, out int y, out int width, out int height); diff --git a/src/Tizen.Multimedia.Camera/Interop/Interop.CameraFeatures.cs b/src/Tizen.Multimedia.Camera/Interop/Interop.CameraFeatures.cs index f2e34de..7ebf739 100644 --- a/src/Tizen.Multimedia.Camera/Interop/Interop.CameraFeatures.cs +++ b/src/Tizen.Multimedia.Camera/Interop/Interop.CameraFeatures.cs @@ -65,10 +65,10 @@ internal static partial class Interop internal delegate bool FlashModeCallback(CameraFlashMode mode, IntPtr userData); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate bool StreamRotationCallback(CameraRotation rotation, IntPtr userData); + internal delegate bool StreamRotationCallback(Rotation rotation, IntPtr userData); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate bool StreamFlipCallback(CameraFlip flip, IntPtr userData); + internal delegate bool StreamFlipCallback(Flips flip, IntPtr userData); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] internal delegate bool PtzTypeCallback(CameraPtzType type, IntPtr userData); diff --git a/src/Tizen.Multimedia.Camera/Interop/Interop.CameraSettings.cs b/src/Tizen.Multimedia.Camera/Interop/Interop.CameraSettings.cs index 1ff1a83..bec8a0a 100755 --- a/src/Tizen.Multimedia.Camera/Interop/Interop.CameraSettings.cs +++ b/src/Tizen.Multimedia.Camera/Interop/Interop.CameraSettings.cs @@ -173,16 +173,16 @@ internal static partial class Interop internal static extern CameraError GetLensOrientation(IntPtr handle, out int angle); [DllImport(Libraries.Camera, EntryPoint = "camera_attr_set_stream_rotation")] - internal static extern CameraError SetStreamRotation(IntPtr handle, CameraRotation mode); + internal static extern CameraError SetStreamRotation(IntPtr handle, Rotation mode); [DllImport(Libraries.Camera, EntryPoint = "camera_attr_get_stream_rotation")] - internal static extern CameraError GetStreamRotation(IntPtr handle, out CameraRotation mode); + internal static extern CameraError GetStreamRotation(IntPtr handle, out Rotation mode); [DllImport(Libraries.Camera, EntryPoint = "camera_attr_set_stream_flip")] - internal static extern CameraError SetFlip(IntPtr handle, CameraFlip flip); + internal static extern CameraError SetFlip(IntPtr handle, Flips flip); [DllImport(Libraries.Camera, EntryPoint = "camera_attr_get_stream_flip")] - internal static extern CameraError GetFlip(IntPtr handle, out CameraFlip flip); + internal static extern CameraError GetFlip(IntPtr handle, out Flips flip); [DllImport(Libraries.Camera, EntryPoint = "camera_attr_set_hdr_mode")] internal static extern CameraError SetHdrMode(IntPtr handle, CameraHdrMode hdr); diff --git a/src/Tizen.Multimedia.MediaPlayer/Interop/Interop.Display.cs b/src/Tizen.Multimedia.MediaPlayer/Interop/Interop.Display.cs index c8eea4b..4c53542 100644 --- a/src/Tizen.Multimedia.MediaPlayer/Interop/Interop.Display.cs +++ b/src/Tizen.Multimedia.MediaPlayer/Interop/Interop.Display.cs @@ -36,7 +36,7 @@ internal static partial class Interop internal static extern PlayerErrorCode IsVisible(IntPtr player, out bool visible); [DllImport(Libraries.Player, EntryPoint = "player_set_display_rotation")] - internal static extern PlayerErrorCode SetRotation(IntPtr player, PlayerDisplayRotation rotation); + internal static extern PlayerErrorCode SetRotation(IntPtr player, Rotation rotation); [DllImport(Libraries.Player, EntryPoint = "player_get_display_rotation")] internal static extern PlayerErrorCode GetRotation(IntPtr player, out int rotation); diff --git a/src/Tizen.Multimedia.MediaPlayer/Player/PlayerDisplaySettings.cs b/src/Tizen.Multimedia.MediaPlayer/Player/PlayerDisplaySettings.cs index e4581d3..9b25a5f 100644 --- a/src/Tizen.Multimedia.MediaPlayer/Player/PlayerDisplaySettings.cs +++ b/src/Tizen.Multimedia.MediaPlayer/Player/PlayerDisplaySettings.cs @@ -103,7 +103,7 @@ namespace Tizen.Multimedia } } - private PlayerDisplayRotation _rotation = PlayerDisplayRotation.RotationNone; + private Rotation _rotation = Rotation.Rotate0; /// /// Gets or sets the rotation of the display. @@ -119,7 +119,7 @@ namespace Tizen.Multimedia /// /// The player already has been disposed of. /// The specified value to set is invalid. - public PlayerDisplayRotation Rotation + public Rotation Rotation { get { @@ -132,7 +132,7 @@ namespace Tizen.Multimedia return; } - ValidationUtil.ValidateEnum(typeof(PlayerDisplayRotation), value); + ValidationUtil.ValidateEnum(typeof(Rotation), value); Native.SetRotation(Player.Handle, value). ThrowIfFailed("Failed to set the rotation state of the display"); diff --git a/src/Tizen.Multimedia.MediaPlayer/Player/PlayerEnums.cs b/src/Tizen.Multimedia.MediaPlayer/Player/PlayerEnums.cs index 72be4b8..9ebdcf6 100644 --- a/src/Tizen.Multimedia.MediaPlayer/Player/PlayerEnums.cs +++ b/src/Tizen.Multimedia.MediaPlayer/Player/PlayerEnums.cs @@ -113,35 +113,6 @@ namespace Tizen.Multimedia High, } - - /// - /// Specifies display rotation modes for . - /// - /// - public enum PlayerDisplayRotation - { - /// - /// Display is not rotated - /// - RotationNone, - - /// - /// Display is rotated 90 degrees - /// - Rotation90, - - /// - /// Display is rotated 180 degrees - /// - Rotation180, - - /// - /// Display is rotated 270 degrees - /// - Rotation270 - } - - /// /// Specifies display modes for /// diff --git a/src/Tizen.Multimedia.Recorder/Interop/Interop.RecorderSettings.cs b/src/Tizen.Multimedia.Recorder/Interop/Interop.RecorderSettings.cs index f0daf01..ce0521b 100644 --- a/src/Tizen.Multimedia.Recorder/Interop/Interop.RecorderSettings.cs +++ b/src/Tizen.Multimedia.Recorder/Interop/Interop.RecorderSettings.cs @@ -105,10 +105,10 @@ internal static partial class Interop internal static extern RecorderError SetMotionRate(IntPtr handle, double motionRate); [DllImport(Libraries.Recorder, EntryPoint = "recorder_attr_get_orientation_tag")] - internal static extern RecorderError GetOrientationTag(IntPtr handle, out RecorderOrientation orientation); + internal static extern RecorderError GetOrientationTag(IntPtr handle, out Rotation orientation); [DllImport(Libraries.Recorder, EntryPoint = "recorder_attr_set_orientation_tag")] - internal static extern RecorderError SetOrientationTag(IntPtr handle, RecorderOrientation orientation); + internal static extern RecorderError SetOrientationTag(IntPtr handle, Rotation orientation); [DllImport(Libraries.Recorder, EntryPoint = "recorder_get_video_resolution")] internal static extern RecorderError GetVideoResolution(IntPtr handle, out int width, out int height); diff --git a/src/Tizen.Multimedia.Recorder/Recorder/RecorderEnums.cs b/src/Tizen.Multimedia.Recorder/Recorder/RecorderEnums.cs index 308d080..fa7e84c 100755 --- a/src/Tizen.Multimedia.Recorder/Recorder/RecorderEnums.cs +++ b/src/Tizen.Multimedia.Recorder/Recorder/RecorderEnums.cs @@ -106,7 +106,7 @@ namespace Tizen.Multimedia /// Enumeration for the recorder policy. /// /// 3 - public enum RecorderPolicy + public enum RecorderPolicy { /// /// None. @@ -143,30 +143,6 @@ namespace Tizen.Multimedia } /// - /// Enumeration for the recorder rotation type. - /// - /// 3 - public enum RecorderOrientation - { - /// - /// No rotation. - /// - RotationNone, - /// - /// 90 Degree rotation. - /// - Rotation90, - /// - /// 180 Degree rotation. - /// - Rotation180, - /// - /// 270 Degree rotation. - /// - Rotation270 - } - - /// /// Enumeration for recorder states. /// /// 3 diff --git a/src/Tizen.Multimedia.Recorder/Recorder/RecorderSettings.cs b/src/Tizen.Multimedia.Recorder/Recorder/RecorderSettings.cs index 344c6d5..9c92ad7 100755 --- a/src/Tizen.Multimedia.Recorder/Recorder/RecorderSettings.cs +++ b/src/Tizen.Multimedia.Recorder/Recorder/RecorderSettings.cs @@ -399,15 +399,13 @@ namespace Tizen.Multimedia /// The orientation in a video metadata tag. /// /// 3 - /// A that specifies the type of orientation. + /// A that specifies the type of orientation. /// The camera already has been disposed. - public RecorderOrientation OrientationTag + public Rotation OrientationTag { get { - RecorderOrientation val = 0; - - RecorderErrorFactory.ThrowIfError(Native.GetOrientationTag(_recorder.GetHandle(), out val), + RecorderErrorFactory.ThrowIfError(Native.GetOrientationTag(_recorder.GetHandle(), out var val), "Failed to get recorder orientation."); return val; diff --git a/src/Tizen.Multimedia.Util/ImageUtil/ImageRotation.cs b/src/Tizen.Multimedia.Util/ImageUtil/ImageRotation.cs index daff4e7..7750c88 100644 --- a/src/Tizen.Multimedia.Util/ImageUtil/ImageRotation.cs +++ b/src/Tizen.Multimedia.Util/ImageUtil/ImageRotation.cs @@ -20,7 +20,7 @@ namespace Tizen.Multimedia.Util /// Specifies how an image is rotated or flipped. /// /// - public enum ImageRotation + internal enum ImageRotation { /// /// No rotation. diff --git a/src/Tizen.Multimedia.Util/ImageUtil/ImageTransform.cs b/src/Tizen.Multimedia.Util/ImageUtil/ImageTransform.cs index e660e9e..b66a7a0 100644 --- a/src/Tizen.Multimedia.Util/ImageUtil/ImageTransform.cs +++ b/src/Tizen.Multimedia.Util/ImageUtil/ImageTransform.cs @@ -17,6 +17,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Diagnostics; using System.Runtime.InteropServices; using System.Threading.Tasks; using static Interop.ImageUtil; @@ -60,13 +61,23 @@ namespace Tizen.Multimedia.Util } } + internal static TransformHandle CreateHandle() + { + Create(out var handle).ThrowIfFailed("Failed to run ImageTransformer"); + Debug.Assert(handle != null); + return handle; + } + internal abstract void Configure(TransformHandle handle); - internal virtual Task ApplyAsync(TransformHandle handle, MediaPacket source) + internal virtual Task ApplyAsync(MediaPacket source) { - Configure(handle); + using (TransformHandle handle = CreateHandle()) + { + Configure(handle); - return RunAsync(handle, source); + return RunAsync(handle, source); + } } } @@ -225,7 +236,7 @@ namespace Tizen.Multimedia.Util // intended blank } - internal override async Task ApplyAsync(TransformHandle handle, MediaPacket source) + internal override async Task ApplyAsync(MediaPacket source) { if (Children.Count == 0) { @@ -234,16 +245,14 @@ namespace Tizen.Multimedia.Util var items = Children; - MediaPacket curPacket = await items[0].ApplyAsync(handle, source); + MediaPacket curPacket = await items[0].ApplyAsync(source); for (int i = 1; i < items.Count; ++i) { - var item = items[i]; - var oldPacket = curPacket; try { - curPacket = await item.ApplyAsync(handle, curPacket); + curPacket = await items[i].ApplyAsync(curPacket); } finally { @@ -258,31 +267,39 @@ namespace Tizen.Multimedia.Util /// /// Rotates or flips an image. /// - /// + /// public class RotateTransform : ImageTransform { - private ImageRotation _rotation; + private Rotation _rotation; /// /// Initialize a new instance of the class. /// /// The value how to rotate an image. /// is invalid. - public RotateTransform(ImageRotation rotation) + /// is . + public RotateTransform(Rotation rotation) { Rotation = rotation; + } /// /// Gets or sets the value how to rotate an image. /// /// is invalid. - public ImageRotation Rotation + /// is . + public Rotation Rotation { get { return _rotation; } set { - ValidationUtil.ValidateEnum(typeof(ImageRotation), value, nameof(Rotation)); + ValidationUtil.ValidateEnum(typeof(Rotation), value, nameof(Rotation)); + + if (value == Rotation.Rotate0) + { + throw new ArgumentOutOfRangeException(nameof(value), "Rotation can't be Rotate0."); + } _rotation = value; } @@ -290,7 +307,96 @@ namespace Tizen.Multimedia.Util internal override void Configure(TransformHandle handle) { - SetRotation(handle, Rotation); + SetRotation(handle, GetImageRotation()); + } + + private ImageRotation GetImageRotation() + { + switch (Rotation) + { + case Rotation.Rotate90: return ImageRotation.Rotate90; + case Rotation.Rotate180: return ImageRotation.Rotate180; + case Rotation.Rotate270: return ImageRotation.Rotate270; + } + + Debug.Fail("Rotation is invalid value!"); + return ImageRotation.Rotate0; + } + } + + + /// + /// Rotates or flips an image. + /// + /// + public class FlipTransform : ImageTransform + { + private Flips _flip; + + /// + /// Initialize a new instance of the class. + /// + /// The value how to flip an image. + /// is invalid. + /// is . + public FlipTransform(Flips flip) + { + Flip = flip; + } + + /// + /// Gets or sets the value how to rotate an image. + /// + /// is invalid. + /// is . + 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 void Configure(TransformHandle handle) + { + // intended blank + } + + private async Task ApplyAsync(TransformHandle handle, MediaPacket source, + ImageRotation rotation) + { + 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); + } } } diff --git a/src/Tizen.Multimedia.Util/ImageUtil/ImageTransformer.cs b/src/Tizen.Multimedia.Util/ImageUtil/ImageTransformer.cs index f90f235..c591ee7 100644 --- a/src/Tizen.Multimedia.Util/ImageUtil/ImageTransformer.cs +++ b/src/Tizen.Multimedia.Util/ImageUtil/ImageTransformer.cs @@ -15,10 +15,7 @@ */ using System; -using System.Diagnostics; using System.Threading.Tasks; -using static Interop.ImageUtil; -using static Interop.ImageUtil.Transform; namespace Tizen.Multimedia.Util { @@ -27,16 +24,11 @@ namespace Tizen.Multimedia.Util /// public class ImageTransformer : IDisposable { - private TransformHandle _handle = null; - /// /// Initialize a new instance of the class. /// public ImageTransformer() { - Create(out _handle).ThrowIfFailed("Failed to create ImageTransformer"); - - Debug.Assert(_handle != null); } /// @@ -69,7 +61,7 @@ namespace Tizen.Multimedia.Util throw new ArgumentNullException(nameof(item)); } - return item.ApplyAsync(_handle, source); + return item.ApplyAsync(source); } #region IDisposable Support @@ -79,11 +71,6 @@ namespace Tizen.Multimedia.Util { if (!_disposed) { - if (_handle != null) - { - _handle.Dispose(); - } - _disposed = true; } } diff --git a/src/Tizen.Multimedia.Util/Interop/Interop.ImageUtil.Transform.cs b/src/Tizen.Multimedia.Util/Interop/Interop.ImageUtil.Transform.cs index 186b2c0..056266d 100644 --- a/src/Tizen.Multimedia.Util/Interop/Interop.ImageUtil.Transform.cs +++ b/src/Tizen.Multimedia.Util/Interop/Interop.ImageUtil.Transform.cs @@ -48,9 +48,6 @@ internal static partial class Interop [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_transform_set_hardware_acceleration")] internal static extern ImageUtilError SetHardwareAcceleration(TransformHandle handle, bool mode); - [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_transform_get_rotation")] - internal static extern ImageUtilError GetRotation(TransformHandle handle, out ImageRotation rotation); - [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_transform_set_rotation")] internal static extern ImageUtilError SetRotation(TransformHandle handle, ImageRotation rotation); diff --git a/src/Tizen.Multimedia/Common.Internal/ValdiationUtil.cs b/src/Tizen.Multimedia/Common.Internal/ValdiationUtil.cs index 3e71d0b..b2b7bf6 100644 --- a/src/Tizen.Multimedia/Common.Internal/ValdiationUtil.cs +++ b/src/Tizen.Multimedia/Common.Internal/ValdiationUtil.cs @@ -15,6 +15,7 @@ */ using System; +using System.Globalization; namespace Tizen.Multimedia { @@ -36,6 +37,14 @@ namespace Tizen.Multimedia } } + internal static void ValidateFlagsEnum(T value, T allMasks, string paramName) where T : IConvertible + { + if (((~allMasks.ToInt32(CultureInfo.InvariantCulture)) & value.ToInt32(CultureInfo.InvariantCulture)) != 0) + { + throw new ArgumentException($"Invalid { typeof(T).Name } value : { value }", paramName); + } + } + internal static void ValidateFeatureSupported(string featureKey) { if (Features.IsSupported(featureKey) == false) diff --git a/src/Tizen.Multimedia/Common/Flips.cs b/src/Tizen.Multimedia/Common/Flips.cs new file mode 100644 index 0000000..977be45 --- /dev/null +++ b/src/Tizen.Multimedia/Common/Flips.cs @@ -0,0 +1,42 @@ +/* + * 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; + +namespace Tizen.Multimedia +{ + /// + /// Specifies the flip operation. + /// + [Flags] + public enum Flips + { + /// + /// No flip operation. + /// + None = 0, + + /// + /// Flip horizontally. + /// + Horizontal = 1, + + /// + /// Flip vertically. + /// + Vertical = 2, + } +} diff --git a/src/Tizen.Multimedia/Common/Rotation.cs b/src/Tizen.Multimedia/Common/Rotation.cs new file mode 100644 index 0000000..78241b3 --- /dev/null +++ b/src/Tizen.Multimedia/Common/Rotation.cs @@ -0,0 +1,44 @@ +/* + * 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. + */ + +namespace Tizen.Multimedia +{ + /// + /// Specifies the directions of rotation. + /// + public enum Rotation + { + /// + /// No rotation. + /// + Rotate0, + + /// + /// Rotate clockwise by 90 degrees. + /// + Rotate90, + + /// + /// Rotate clockwise by 180 degrees. + /// + Rotate180, + + /// + /// Rotate clockwise by 270 degrees. + /// + Rotate270 + } +} -- 2.7.4