[Vision] Modify vision colorsapce to multimedia common colorspace
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia.Vision / MediaVision / MediaVisionSource.cs
index 3bb4c2f..9c53f9c 100755 (executable)
 
 using System;
 using System.Diagnostics;
+using System.Linq;
+using System.Collections.Generic;
 using InteropSource = Interop.MediaVision.MediaSource;
 
-namespace Tizen.Multimedia
+namespace Tizen.Multimedia.Vision
 {
     /// <summary>
     /// Represents the media vision source to keep information on image or video frame data as raw buffer.
@@ -41,7 +43,7 @@ namespace Tizen.Multimedia
             {
                 fillAction(_handle);
             }
-            catch(Exception)
+            catch (Exception)
             {
                 InteropSource.Destroy(_handle);
                 _disposed = true;
@@ -75,7 +77,7 @@ namespace Tizen.Multimedia
         {
         }
 
-        private static void FillBuffer(IntPtr handle, byte[] buffer, uint width, uint height, Colorspace colorspace)
+        private static void FillBuffer(IntPtr handle, byte[] buffer, uint width, uint height, ColorSpace colorSpace)
         {
             Debug.Assert(handle != IntPtr.Zero);
 
@@ -89,34 +91,33 @@ namespace Tizen.Multimedia
                 throw new ArgumentException("Buffer.Length is zero.", nameof(buffer));
             }
 
-            if (colorspace == Colorspace.Invalid)
-            {
-                throw new ArgumentException($"color space must not be {Colorspace.Invalid}.", nameof(colorspace));
-            }
-
-            ValidationUtil.ValidateEnum(typeof(Colorspace), colorspace, nameof(colorspace));
+            ValidationUtil.ValidateEnum(typeof(ColorSpace), colorSpace, nameof(colorSpace));
 
-            InteropSource.FillBuffer(handle, buffer, buffer.Length, width, height, colorspace).
+            InteropSource.FillBuffer(handle, buffer, buffer.Length, width, height, colorSpace.ToVisionColorSpace()).
                 Validate("Failed to fill buffer");
         }
 
         /// <summary>
-        /// Initializes a new instance of the <see cref="MediaVisionSource"/> class based on the buffer and <see cref="Colorspace"/>.
+        /// Initializes a new instance of the <see cref="MediaVisionSource"/> class based on the buffer and <see cref="ColorSpace"/>.
         /// </summary>
         /// <param name="buffer">The buffer of image data.</param>
         /// <param name="width">The width of image.</param>
         /// <param name="height">The height of image.</param>
-        /// <param name="colorspace">The image <see cref="Colorspace"/>.</param>
-        /// <exception cref="NotSupportedException">The feature is not supported.</exception>
+        /// <param name="colorSpace">The image <see cref="ColorSpace"/>.</param>
+        /// <exception cref="NotSupportedException">
+        ///     The feature is not supported.\n
+        ///     -or-\n
+        ///     <paramref name="colorSpace"/> is not supported.
+        /// </exception>
         /// <exception cref="ArgumentNullException"><paramref name="buffer"/> is null.</exception>
         /// <exception cref="ArgumentException">
         ///     <paramref name="buffer"/> has no element.(The length is zero.)\n
         ///     -or-\n
-        ///     <paramref name="colorspace"/> is invalid.
+        ///     <paramref name="colorSpace"/> is invalid.
         /// </exception>
         /// <since_tizen> 3</since_tizen>
-        public MediaVisionSource(byte[] buffer, uint width, uint height, Colorspace colorspace)
-            : this(handle => FillBuffer(handle, buffer, width, height, colorspace))
+        public MediaVisionSource(byte[] buffer, uint width, uint height, ColorSpace colorSpace)
+            : this(handle => FillBuffer(handle, buffer, width, height, colorSpace))
         {
         }
 
@@ -151,6 +152,15 @@ namespace Tizen.Multimedia
         }
 
         /// <summary>
+        /// Gets MediaVision's supported ColorSpace state.
+        /// true if supported, otherwise false.
+        /// </summary>
+        public static bool IsSupportedColorSpace(ColorSpace colorSpace)
+        {
+            return SupportedColorSpaces.Contains(colorSpace);
+        }
+
+        /// <summary>
         /// Gets height of the media source.
         /// </summary>
         /// <exception cref="ObjectDisposedException">The <see cref="MediaVisionSource"/> has already been disposed of.</exception>
@@ -183,18 +193,33 @@ namespace Tizen.Multimedia
         }
 
         /// <summary>
-        /// Gets <see cref="Colorspace"/> of the media source.
+        /// Gets <see cref="ColorSpace"/> of the media source.
         /// </summary>
         /// <exception cref="ObjectDisposedException">The <see cref="MediaVisionSource"/> has already been disposed of.</exception>
         /// <since_tizen> 3</since_tizen>
-        public Colorspace Colorspace
+        public ColorSpace Colorspace
         {
             get
             {
-                Colorspace colorspace = Colorspace.Invalid;
-                var ret = InteropSource.GetColorspace(Handle, out colorspace);
+                VisionColorSpace visionColorSpace;
+
+                var ret = InteropSource.GetColorspace(Handle, out visionColorSpace);
                 MultimediaDebug.AssertNoError(ret);
-                return colorspace;
+                return visionColorSpace.ToCommonColorSpace();
+            }
+        }
+
+        /// <summary>
+        /// Gets the supported colorspaces for <see cref="MediaVisionSource"/>.
+        /// </summary>
+        public static IEnumerable<ColorSpace> SupportedColorSpaces
+        {
+            get
+            {
+                foreach (VisionColorSpace value in Enum.GetValues(typeof(VisionColorSpace)))
+                {
+                    yield return value.ToCommonColorSpace();
+                }
             }
         }
 
@@ -204,6 +229,12 @@ namespace Tizen.Multimedia
             GC.SuppressFinalize(this);
         }
 
+        /// <summary>
+        /// Releases the resources used by the <see cref="MediaVisionSource"/> object.
+        /// </summary>
+        /// <param name="disposing">
+        /// true to release both managed and unmanaged resources; false to release only unmanaged resources.
+        /// </param>
         protected virtual void Dispose(bool disposing)
         {
             if (_disposed)