-Change public Colorspace of MediaVision to internal and its classname.
Remove Invalid enumeration in Colorspace of MediaVision
Instead, use ColorSpace of Multimedia Common.
-Add SupportedColorSpaces attribute
-Add IsSupportedColorSpace() method
Change-Id: Ieccdb48753dad11518d3386ddcc23f3fab7ce5dd
Signed-off-by: Tae-Young Chung <ty83.chung@samsung.com>
[DllImport(Libraries.MediaVision, EntryPoint = "mv_source_fill_by_buffer")]
internal static extern MediaVisionError FillBuffer(IntPtr source, byte[] buffer,
- int bufferSize, uint imageWidth, uint imageHeight, Colorspace colorspace);
+ int bufferSize, uint imageWidth, uint imageHeight, VisionColorSpace colorspace);
[DllImport(Libraries.MediaVision, EntryPoint = "mv_source_clear")]
internal static extern int Clear(IntPtr /* mv_source_h */ source);
internal static extern int GetWidth(IntPtr source, out uint imageWidth);
[DllImport(Libraries.MediaVision, EntryPoint = "mv_source_get_colorspace")]
- internal static extern int GetColorspace(IntPtr /* mv_source_h */ source, out Colorspace colorspace);
+ internal static extern int GetColorspace(IntPtr /* mv_source_h */ source, out VisionColorSpace colorspace);
}
/// <summary>
+++ /dev/null
-/*
- * 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.Vision
-{
- /// <summary>
- /// Specifies colorspaces for MediaVision.
- /// </summary>
- /// <since_tizen> 3</since_tizen>
- public enum Colorspace
- {
- /// <summary>
- /// The colorspace type is invalid.
- /// </summary>
- /// <since_tizen> 3</since_tizen>
- Invalid,
- /// <summary>
- /// The colorspace type is Y800.
- /// </summary>
- /// <since_tizen> 3</since_tizen>
- Y800,
- /// <summary>
- /// The colorspace type is I420.
- /// </summary>
- /// <since_tizen> 3</since_tizen>
- I420,
- /// <summary>
- /// The colorspace type is NV12.
- /// </summary>
- /// <since_tizen> 3</since_tizen>
- NV12,
- /// <summary>
- /// The colorspace type is YV12.
- /// </summary>
- /// <since_tizen> 3</since_tizen>
- YV12,
- /// <summary>
- /// The colorspace type is NV21.
- /// </summary>
- /// <since_tizen> 3</since_tizen>
- NV21,
- /// <summary>
- /// The colorspace type is YUYV.
- /// </summary>
- /// <since_tizen> 3</since_tizen>
- Yuyv,
- /// <summary>
- /// The colorspace type is UYVY.
- /// </summary>
- /// <since_tizen> 3</since_tizen>
- Uyvy,
- /// <summary>
- /// The colorspace type is 422P.
- /// </summary>
- /// <since_tizen> 3</since_tizen>
- Yuv422P,
- /// <summary>
- /// The colorspace type is RGB565.
- /// </summary>
- /// <since_tizen> 3</since_tizen>
- Rgb565,
- /// <summary>
- /// The colorspace type is RGB888.
- /// </summary>
- /// <since_tizen> 3</since_tizen>
- Rgb888,
- /// <summary>
- /// The colorspace type is RGBA.
- /// </summary>
- /// <since_tizen> 3</since_tizen>
- Rgba
- }
-}
using System;
using System.Diagnostics;
+using System.Linq;
+using System.Collections.Generic;
using InteropSource = Interop.MediaVision.MediaSource;
namespace Tizen.Multimedia.Vision
{
}
- 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);
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))
{
}
}
/// <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>
}
/// <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>
- /// Releases all resources used by the <see cref="MediaVisionSource"/> object.
+ /// 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();
+ }
+ }
+ }
+
public void Dispose()
{
Dispose(true);
--- /dev/null
+/*
+ * 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.Diagnostics;
+
+namespace Tizen.Multimedia.Vision
+{
+ /// <summary>
+ /// Specifies colorspaces for MediaVision.
+ /// </summary>
+ internal enum VisionColorSpace
+ {
+ /// <summary>
+ /// The colorspace type is Y800.
+ /// </summary>
+ Y800 = 1,
+ /// <summary>
+ /// The colorspace type is I420.
+ /// </summary>
+ I420,
+ /// <summary>
+ /// The colorspace type is NV12.
+ /// </summary>
+ NV12,
+ /// <summary>
+ /// The colorspace type is YV12.
+ /// </summary>
+ YV12,
+ /// <summary>
+ /// The colorspace type is NV21.
+ /// </summary>
+ NV21,
+ /// <summary>
+ /// The colorspace type is YUYV.
+ /// </summary>
+ Yuyv,
+ /// <summary>
+ /// The colorspace type is UYVY.
+ /// </summary>
+ Uyvy,
+ /// <summary>
+ /// The colorspace type is 422P.
+ /// </summary>
+ Yuv422P,
+ /// <summary>
+ /// The colorspace type is RGB565.
+ /// </summary>
+ Rgb565,
+ /// <summary>
+ /// The colorspace type is RGB888.
+ /// </summary>
+ Rgb888,
+ /// <summary>
+ /// The colorspace type is RGBA.
+ /// </summary>
+ Rgba
+ }
+
+ internal static class VisionColorSpaceExtensions
+ {
+ internal static ColorSpace ToCommonColorSpace(this VisionColorSpace value)
+ {
+ Debug.Assert(Enum.IsDefined(typeof(VisionColorSpace), value));
+
+ switch (value)
+ {
+ case VisionColorSpace.Y800: return ColorSpace.Y800;
+
+ case VisionColorSpace.I420: return ColorSpace.I420;
+
+ case VisionColorSpace.NV12: return ColorSpace.NV12;
+
+ case VisionColorSpace.YV12: return ColorSpace.YV12;
+
+ case VisionColorSpace.NV21: return ColorSpace.NV21;
+
+ case VisionColorSpace.Yuyv: return ColorSpace.Yuyv;
+
+ case VisionColorSpace.Uyvy: return ColorSpace.Uyvy;
+
+ case VisionColorSpace.Yuv422P: return ColorSpace.Yuv422P;
+
+ case VisionColorSpace.Rgb565: return ColorSpace.Rgb565;
+
+ case VisionColorSpace.Rgb888: return ColorSpace.Rgb888;
+
+ case VisionColorSpace.Rgba: return ColorSpace.Rgba8888;
+ }
+
+ throw new NotSupportedException("Implementation does not support the specified value." + value.ToString());
+ }
+ }
+
+ internal static class VisionColorSpaceSupport
+ {
+ internal static VisionColorSpace ToVisionColorSpace(this ColorSpace colorSpace)
+ {
+ ValidationUtil.ValidateEnum(typeof(ColorSpace), colorSpace, nameof(colorSpace));
+
+ switch (colorSpace)
+ {
+ case ColorSpace.Y800: return VisionColorSpace.Y800;
+
+ case ColorSpace.I420: return VisionColorSpace.I420;
+
+ case ColorSpace.NV12: return VisionColorSpace.NV12;
+
+ case ColorSpace.YV12: return VisionColorSpace.YV12;
+
+ case ColorSpace.NV21: return VisionColorSpace.NV21;
+
+ case ColorSpace.Yuyv: return VisionColorSpace.Yuyv;
+
+ case ColorSpace.Uyvy: return VisionColorSpace.Uyvy;
+
+ case ColorSpace.Yuv422P: return VisionColorSpace.Yuv422P;
+
+ case ColorSpace.Rgb565: return VisionColorSpace.Rgb565;
+
+ case ColorSpace.Rgb888: return VisionColorSpace.Rgb888;
+
+ case ColorSpace.Rgba8888: return VisionColorSpace.Rgba;
+ }
+
+ throw new NotSupportedException("Implementation does not support the specified value." + colorSpace.ToString());
+ }
+ }
+}