From: Tae-Young Chung Date: Mon, 4 Sep 2017 08:45:20 +0000 (+0900) Subject: [Vision] Modify vision colorsapce to multimedia common colorspace X-Git-Tag: preview1-00155~1^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2823ffdf7079c497216a368b8b007c3265992eae;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [Vision] Modify vision colorsapce to multimedia common colorspace -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 --- diff --git a/src/Tizen.Multimedia.Vision/Interop/Interop.MediaVision.Common.cs b/src/Tizen.Multimedia.Vision/Interop/Interop.MediaVision.Common.cs index 377635f..25df35d 100644 --- a/src/Tizen.Multimedia.Vision/Interop/Interop.MediaVision.Common.cs +++ b/src/Tizen.Multimedia.Vision/Interop/Interop.MediaVision.Common.cs @@ -135,7 +135,7 @@ internal static partial class Interop [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); @@ -150,7 +150,7 @@ internal static partial class Interop 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); } /// diff --git a/src/Tizen.Multimedia.Vision/MediaVision/Colorspace.cs b/src/Tizen.Multimedia.Vision/MediaVision/Colorspace.cs deleted file mode 100755 index f7eee9b..0000000 --- a/src/Tizen.Multimedia.Vision/MediaVision/Colorspace.cs +++ /dev/null @@ -1,86 +0,0 @@ -/* - * 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 -{ - /// - /// Specifies colorspaces for MediaVision. - /// - /// 3 - public enum Colorspace - { - /// - /// The colorspace type is invalid. - /// - /// 3 - Invalid, - /// - /// The colorspace type is Y800. - /// - /// 3 - Y800, - /// - /// The colorspace type is I420. - /// - /// 3 - I420, - /// - /// The colorspace type is NV12. - /// - /// 3 - NV12, - /// - /// The colorspace type is YV12. - /// - /// 3 - YV12, - /// - /// The colorspace type is NV21. - /// - /// 3 - NV21, - /// - /// The colorspace type is YUYV. - /// - /// 3 - Yuyv, - /// - /// The colorspace type is UYVY. - /// - /// 3 - Uyvy, - /// - /// The colorspace type is 422P. - /// - /// 3 - Yuv422P, - /// - /// The colorspace type is RGB565. - /// - /// 3 - Rgb565, - /// - /// The colorspace type is RGB888. - /// - /// 3 - Rgb888, - /// - /// The colorspace type is RGBA. - /// - /// 3 - Rgba - } -} diff --git a/src/Tizen.Multimedia.Vision/MediaVision/MediaVisionSource.cs b/src/Tizen.Multimedia.Vision/MediaVision/MediaVisionSource.cs index 9975eca..9c53f9c 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/MediaVisionSource.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/MediaVisionSource.cs @@ -16,6 +16,8 @@ using System; using System.Diagnostics; +using System.Linq; +using System.Collections.Generic; using InteropSource = Interop.MediaVision.MediaSource; namespace Tizen.Multimedia.Vision @@ -75,7 +77,7 @@ 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); @@ -89,34 +91,33 @@ namespace Tizen.Multimedia.Vision 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"); } /// - /// Initializes a new instance of the class based on the buffer and . + /// Initializes a new instance of the class based on the buffer and . /// /// The buffer of image data. /// The width of image. /// The height of image. - /// The image . - /// The feature is not supported. + /// The image . + /// + /// The feature is not supported.\n + /// -or-\n + /// is not supported. + /// /// is null. /// /// has no element.(The length is zero.)\n /// -or-\n - /// is invalid. + /// is invalid. /// /// 3 - 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.Vision } /// + /// Gets MediaVision's supported ColorSpace state. + /// true if supported, otherwise false. + /// + public static bool IsSupportedColorSpace(ColorSpace colorSpace) + { + return SupportedColorSpaces.Contains(colorSpace); + } + + /// /// Gets height of the media source. /// /// The has already been disposed of. @@ -183,24 +193,36 @@ namespace Tizen.Multimedia.Vision } /// - /// Gets of the media source. + /// Gets of the media source. /// /// The has already been disposed of. /// 3 - 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(); } } /// - /// Releases all resources used by the object. + /// Gets the supported colorspaces for . /// + public static IEnumerable SupportedColorSpaces + { + get + { + foreach (VisionColorSpace value in Enum.GetValues(typeof(VisionColorSpace))) + { + yield return value.ToCommonColorSpace(); + } + } + } + public void Dispose() { Dispose(true); diff --git a/src/Tizen.Multimedia.Vision/MediaVision/VisionColorSpace.cs b/src/Tizen.Multimedia.Vision/MediaVision/VisionColorSpace.cs new file mode 100755 index 0000000..7145428 --- /dev/null +++ b/src/Tizen.Multimedia.Vision/MediaVision/VisionColorSpace.cs @@ -0,0 +1,142 @@ +/* + * 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 +{ + /// + /// Specifies colorspaces for MediaVision. + /// + internal enum VisionColorSpace + { + /// + /// The colorspace type is Y800. + /// + Y800 = 1, + /// + /// The colorspace type is I420. + /// + I420, + /// + /// The colorspace type is NV12. + /// + NV12, + /// + /// The colorspace type is YV12. + /// + YV12, + /// + /// The colorspace type is NV21. + /// + NV21, + /// + /// The colorspace type is YUYV. + /// + Yuyv, + /// + /// The colorspace type is UYVY. + /// + Uyvy, + /// + /// The colorspace type is 422P. + /// + Yuv422P, + /// + /// The colorspace type is RGB565. + /// + Rgb565, + /// + /// The colorspace type is RGB888. + /// + Rgb888, + /// + /// The colorspace type is RGBA. + /// + 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()); + } + } +}