Added Rotation and Flip enums for common use.
authorcoderhyme <jhyo.kim@samsung.com>
Tue, 30 May 2017 08:18:21 +0000 (17:18 +0900)
committercoderhyme <jhyo.kim@samsung.com>
Thu, 13 Jul 2017 05:31:48 +0000 (14:31 +0900)
Change-Id: I5ffee417a33960792d9e465e2243ea48688d98e8
Signed-off-by: coderhyme <jhyo.kim@samsung.com>
20 files changed:
src/Tizen.Multimedia.Camera/Camera/CameraDisplaySettings.cs
src/Tizen.Multimedia.Camera/Camera/CameraEnums.cs
src/Tizen.Multimedia.Camera/Camera/CameraFeatures.cs
src/Tizen.Multimedia.Camera/Camera/CameraSettings.cs
src/Tizen.Multimedia.Camera/Interop/Interop.CameraDisplay.cs
src/Tizen.Multimedia.Camera/Interop/Interop.CameraFeatures.cs
src/Tizen.Multimedia.Camera/Interop/Interop.CameraSettings.cs
src/Tizen.Multimedia.MediaPlayer/Interop/Interop.Display.cs
src/Tizen.Multimedia.MediaPlayer/Player/PlayerDisplaySettings.cs
src/Tizen.Multimedia.MediaPlayer/Player/PlayerEnums.cs
src/Tizen.Multimedia.Recorder/Interop/Interop.RecorderSettings.cs
src/Tizen.Multimedia.Recorder/Recorder/RecorderEnums.cs
src/Tizen.Multimedia.Recorder/Recorder/RecorderSettings.cs
src/Tizen.Multimedia.Util/ImageUtil/ImageRotation.cs
src/Tizen.Multimedia.Util/ImageUtil/ImageTransform.cs
src/Tizen.Multimedia.Util/ImageUtil/ImageTransformer.cs
src/Tizen.Multimedia.Util/Interop/Interop.ImageUtil.Transform.cs
src/Tizen.Multimedia/Common.Internal/ValdiationUtil.cs
src/Tizen.Multimedia/Common/Flips.cs [new file with mode: 0644]
src/Tizen.Multimedia/Common/Rotation.cs [new file with mode: 0644]

index 0ded01e..b5d3058 100755 (executable)
@@ -83,15 +83,13 @@ namespace Tizen.Multimedia
         /// The display rotation.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
-        /// <value>A <see cref="CameraRotation"/> that specifies the rotation of camera device.</value>
+        /// <value>A <see cref="Rotation"/> that specifies the rotation of camera device.</value>
         /// <exception cref="ObjectDisposedException" > The camera already has been disposed.</exception>
-        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
         /// <since_tizen> 3 </since_tizen>
         /// <value>A <see cref="CameraFlip"/> that specifies camera flip type.</value>
         /// <exception cref="ObjectDisposedException" > The camera already has been disposed.</exception>
-        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.");
             }
index 2e25a6e..65dce11 100755 (executable)
@@ -87,30 +87,6 @@ namespace Tizen.Multimedia
     }
 
     /// <summary>
-    /// Enumeration for the camera flip type.
-    /// </summary>
-    /// <since_tizen> 3 </since_tizen>
-    public enum CameraFlip
-    {
-        /// <summary>
-        /// No Flip.
-        /// </summary>
-        None,
-        /// <summary>
-        /// Horizontal flip.
-        /// </summary>
-        Horizontal,
-        /// <summary>
-        /// Vertical flip.
-        /// </summary>
-        Vertical,
-        /// <summary>
-        /// Horizontal and vertical flip.
-        /// </summary>
-        Both
-    }
-
-    /// <summary>
     /// Enumeration for the camera focus state.
     /// </summary>
     /// <since_tizen> 3 </since_tizen>
@@ -227,30 +203,6 @@ namespace Tizen.Multimedia
     }
 
     /// <summary>
-    /// Enumeration for the camera rotation type.
-    /// </summary>
-    /// <since_tizen> 3 </since_tizen>
-    public enum CameraRotation
-    {
-        /// <summary>
-        /// No rotation.
-        /// </summary>
-        None,
-        /// <summary>
-        /// 90 degree rotation.
-        /// </summary>
-        Rotation90,
-        /// <summary>
-        /// 180 degree rotation.
-        /// </summary>
-        Rotation180,
-        /// <summary>
-        /// 270 degree rotation.
-        /// </summary>
-        Rotation270
-    }
-
-    /// <summary>
     /// Enumeration for the camera state.
     /// </summary>
     /// <since_tizen> 3 </since_tizen>
index 2361a9f..db46792 100755 (executable)
@@ -43,8 +43,8 @@ namespace Tizen.Multimedia
         private List<CameraFlashMode> _flashModes;
         private List<CameraSceneMode> _sceneModes;
         private List<CameraEffectMode> _effectModes;
-        private List<CameraRotation> _streamRotations;
-        private List<CameraFlip> _streamFlips;
+        private List<Rotation> _streamRotations;
+        private List<Flips> _streamFlips;
         private List<CameraPtzType> _ptzTypes;
 
         private delegate CameraError GetRangeDelegate(IntPtr handle, out int min, out int max);
@@ -707,10 +707,10 @@ namespace Tizen.Multimedia
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
         /// <returns>
-        /// It returns a list containing all the supported <see cref="CameraRotation"/>.
+        /// An IEnumerable containing all the supported <see cref="Rotation"/>.
         /// </returns>
         /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
-        public IEnumerable<CameraRotation> SupportedStreamRotations
+        public IEnumerable<Rotation> SupportedStreamRotations
         {
             get
             {
@@ -718,9 +718,9 @@ namespace Tizen.Multimedia
                 {
                     try
                     {
-                        _streamRotations = new List<CameraRotation>();
+                        _streamRotations = new List<Rotation>();
 
-                        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 <see cref="CameraFlip"/>.
         /// </returns>
         /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
-        public IEnumerable<CameraFlip> SupportedStreamFlips
+        public IEnumerable<Flips> SupportedStreamFlips
         {
             get
             {
@@ -755,9 +755,9 @@ namespace Tizen.Multimedia
                 {
                     try
                     {
-                        _streamFlips = new List<CameraFlip>();
+                        _streamFlips = new List<Flips>();
 
-                        NativeFeatures.StreamFlipCallback callback = (CameraFlip streamFlip, IntPtr userData) =>
+                        NativeFeatures.StreamFlipCallback callback = (streamFlip, _) =>
                         {
                             _streamFlips.Add(streamFlip);
                             return true;
index d188ef5..71042b9 100755 (executable)
@@ -755,9 +755,9 @@ namespace Tizen.Multimedia
         /// The stream rotation.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
-        /// <value>A <see cref="CameraRotation"/> that specifies the rotation of camera device.</value>
+        /// <value>A <see cref="Rotation"/> that specifies the rotation of camera device.</value>
         /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
-        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
         /// <since_tizen> 3 </since_tizen>
         /// <value>A <see cref="CameraFlip"/> that specifies camera flip type.</value>
         /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
-        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.");
             }
index 6f88d4a..001aa42 100644 (file)
@@ -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);
index f2e34de..7ebf739 100644 (file)
@@ -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);
index 1ff1a83..bec8a0a 100755 (executable)
@@ -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);
index c8eea4b..4c53542 100644 (file)
@@ -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);
index e4581d3..9b25a5f 100644 (file)
@@ -103,7 +103,7 @@ namespace Tizen.Multimedia
             }
         }
 
-        private PlayerDisplayRotation _rotation = PlayerDisplayRotation.RotationNone;
+        private Rotation _rotation = Rotation.Rotate0;
 
         /// <summary>
         /// Gets or sets the rotation of the display.
@@ -119,7 +119,7 @@ namespace Tizen.Multimedia
         /// </exception>
         /// <exception cref="ObjectDisposedException">The player already has been disposed of.</exception>
         /// <exception cref="ArgumentException">The specified value to set is invalid.</exception>
-        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");
index 72be4b8..9ebdcf6 100644 (file)
@@ -113,35 +113,6 @@ namespace Tizen.Multimedia
         High,
     }
 
-
-    /// <summary>
-    /// Specifies display rotation modes for <see cref="Player"/>.
-    /// </summary>
-    /// <seealso cref="Display.Rotation"/>
-    public enum PlayerDisplayRotation
-    {
-        /// <summary>
-        /// Display is not rotated
-        /// </summary>
-        RotationNone,
-
-        /// <summary>
-        ///  Display is rotated 90 degrees
-        /// </summary>
-        Rotation90,
-
-        /// <summary>
-        /// Display is rotated 180 degrees
-        /// </summary>
-        Rotation180,
-
-        /// <summary>
-        /// Display is rotated 270 degrees
-        /// </summary>
-        Rotation270
-    }
-
-
     /// <summary>
     /// Specifies display modes for <see cref="Player"/>
     /// </summary>
index f0daf01..ce0521b 100644 (file)
@@ -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);
index 308d080..fa7e84c 100755 (executable)
@@ -106,7 +106,7 @@ namespace Tizen.Multimedia
     /// Enumeration for the recorder policy.
     /// </summary>
     /// <since_tizen> 3 </since_tizen>
-    public enum  RecorderPolicy
+    public enum RecorderPolicy
     {
         /// <summary>
         /// None.
@@ -143,30 +143,6 @@ namespace Tizen.Multimedia
     }
 
     /// <summary>
-    /// Enumeration for the recorder rotation type.
-    /// </summary>
-    /// <since_tizen> 3 </since_tizen>
-    public enum  RecorderOrientation
-    {
-        /// <summary>
-        /// No rotation.
-        /// </summary>
-        RotationNone,
-        /// <summary>
-        /// 90 Degree rotation.
-        /// </summary>
-        Rotation90,
-        /// <summary>
-        /// 180 Degree rotation.
-        /// </summary>
-        Rotation180,
-        /// <summary>
-        /// 270 Degree rotation.
-        /// </summary>
-        Rotation270
-    }
-
-    /// <summary>
     /// Enumeration for recorder states.
     /// </summary>
     /// <since_tizen> 3 </since_tizen>
index 344c6d5..9c92ad7 100755 (executable)
@@ -399,15 +399,13 @@ namespace Tizen.Multimedia
         /// The orientation in a video metadata tag.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
-        /// <value>A <see cref="RecorderOrientation"/> that specifies the type of orientation.</value>
+        /// <value>A <see cref="Rotation"/> that specifies the type of orientation.</value>
         /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
-        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;
index daff4e7..7750c88 100644 (file)
@@ -20,7 +20,7 @@ namespace Tizen.Multimedia.Util
     /// Specifies how an image is rotated or flipped.
     /// </summary>
     /// <seealso cref="RotateTransform"/>
-    public enum ImageRotation
+    internal enum ImageRotation
     {
         /// <summary>
         /// No rotation.
index e660e9e..b66a7a0 100644 (file)
@@ -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<MediaPacket> ApplyAsync(TransformHandle handle, MediaPacket source)
+        internal virtual Task<MediaPacket> 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<MediaPacket> ApplyAsync(TransformHandle handle, MediaPacket source)
+        internal override async Task<MediaPacket> 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
     /// <summary>
     /// Rotates or flips an image.
     /// </summary>
-    /// <seealso cref="ImageRotation"/>
+    /// <seealso cref="Rotation"/>
     public class RotateTransform : ImageTransform
     {
-        private ImageRotation _rotation;
+        private Rotation _rotation;
 
         /// <summary>
         /// Initialize a new instance of the <see cref="RotateTransform"/> class.
         /// </summary>
         /// <param name="rotation">The value how to rotate an image.</param>
         /// <exception cref="ArgumentException"><paramref name="rotation"/> is invalid.</exception>
-        public RotateTransform(ImageRotation rotation)
+        /// <exception cref="ArgumentOutOfRangeException"><paramref name="rotation"/> is <see cref="Rotation.Rotate90"/>.</exception>
+        public RotateTransform(Rotation rotation)
         {
             Rotation = rotation;
+
         }
 
         /// <summary>
         /// Gets or sets the value how to rotate an image.
         /// </summary>
         /// <exception cref="ArgumentException"><paramref name="value"/> is invalid.</exception>
-        public ImageRotation Rotation
+        /// <exception cref="ArgumentOutOfRangeException"><paramref name="value"/> is <see cref="Rotation.Rotate90"/>.</exception>
+        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;
+        }
+    }
+
+
+    /// <summary>
+    /// Rotates or flips an image.
+    /// </summary>
+    /// <seealso cref="Rotation"/>
+    public class FlipTransform : ImageTransform
+    {
+        private Flips _flip;
+
+        /// <summary>
+        /// Initialize a new instance of the <see cref="RotateTransform"/> class.
+        /// </summary>
+        /// <param name="flip">The value how to flip an image.</param>
+        /// <exception cref="ArgumentException"><paramref name="flip"/> is invalid.</exception>
+        /// <exception cref="ArgumentOutOfRangeException"><paramref name="flip"/> is <see cref="Flip.None"/>.</exception>
+        public FlipTransform(Flips flip)
+        {
+            Flip = flip;
+        }
+
+        /// <summary>
+        /// Gets or sets the value how to rotate an image.
+        /// </summary>
+        /// <exception cref="ArgumentException"><paramref name="value"/> is invalid.</exception>
+        /// <exception cref="ArgumentOutOfRangeException"><paramref name="value"/> is <see cref="Flip.None"/>.</exception>
+        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<MediaPacket> ApplyAsync(TransformHandle handle, MediaPacket source,
+            ImageRotation rotation)
+        {
+            SetRotation(handle, rotation);
+            return await RunAsync(handle, source);
+        }
+
+        internal override async Task<MediaPacket> 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);
+            }
         }
     }
 
index f90f235..c591ee7 100644 (file)
  */
 
 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
     /// </summary>
     public class ImageTransformer : IDisposable
     {
-        private TransformHandle _handle = null;
-
         /// <summary>
         /// Initialize a new instance of the <see cref="ImageTransformer"/> class.
         /// </summary>
         public ImageTransformer()
         {
-            Create(out _handle).ThrowIfFailed("Failed to create ImageTransformer");
-
-            Debug.Assert(_handle != null);
         }
 
         /// <summary>
@@ -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;
             }
         }
index 186b2c0..056266d 100644 (file)
@@ -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);
 
index 3e71d0b..b2b7bf6 100644 (file)
@@ -15,6 +15,7 @@
  */
 
 using System;
+using System.Globalization;
 
 namespace Tizen.Multimedia
 {
@@ -36,6 +37,14 @@ namespace Tizen.Multimedia
             }
         }
 
+        internal static void ValidateFlagsEnum<T>(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 (file)
index 0000000..977be45
--- /dev/null
@@ -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
+{
+    /// <summary>
+    /// Specifies the flip operation.
+    /// </summary>
+    [Flags]
+    public enum Flips
+    {
+        /// <summary>
+        /// No flip operation.
+        /// </summary>
+        None = 0,
+
+        /// <summary>
+        /// Flip horizontally.
+        /// </summary>
+        Horizontal = 1,
+
+        /// <summary>
+        /// Flip vertically.
+        /// </summary>
+        Vertical = 2,
+    }
+}
diff --git a/src/Tizen.Multimedia/Common/Rotation.cs b/src/Tizen.Multimedia/Common/Rotation.cs
new file mode 100644 (file)
index 0000000..78241b3
--- /dev/null
@@ -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
+{
+    /// <summary>
+    /// Specifies the directions of rotation.
+    /// </summary>
+    public enum Rotation
+    {
+        /// <summary>
+        /// No rotation.
+        /// </summary>
+        Rotate0,
+
+        /// <summary>
+        /// Rotate clockwise by 90 degrees.
+        /// </summary>
+        Rotate90,
+
+        /// <summary>
+        /// Rotate clockwise by 180 degrees.
+        /// </summary>
+        Rotate180,
+
+        /// <summary>
+        /// Rotate clockwise by 270 degrees.
+        /// </summary>
+        Rotate270
+    }
+}