diff --git a/src/Vision/VNUtils.cs b/src/Vision/VNUtils.cs index 7ec920ce8d06..ecfe6bcd1441 100644 --- a/src/Vision/VNUtils.cs +++ b/src/Vision/VNUtils.cs @@ -37,8 +37,12 @@ public static partial class VNUtils { public static CGRect NormalizedIdentityRect { get; } = Dlfcn.GetCGRect (Libraries.Vision.Handle, "VNNormalizedIdentityRect"); [DllImport (Constants.VisionLibrary, EntryPoint = "VNNormalizedRectIsIdentityRect")] - [return: MarshalAs (UnmanagedType.U1)] - public static extern bool IsIdentityRect (CGRect rect); + static extern byte _IsIdentityRect (CGRect rect); + + public static bool IsIdentityRect (CGRect rect) + { + return _IsIdentityRect (rect) != 0; + } [DllImport (Constants.VisionLibrary, EntryPoint = "VNImagePointForNormalizedPoint")] public static extern CGPoint GetImagePoint (CGPoint normalizedPoint, nuint imageWidth, nuint imageHeight); @@ -120,12 +124,15 @@ public static partial class VNUtils { public static extern CGRect GetNormalizedRect (CGRect imageRect, nuint imageWidth, nuint imageHeight, CGRect regionOfInterest); [DllImport ("__Internal", EntryPoint = "xamarin_CGPoint__VNNormalizedFaceBoundingBoxPointForLandmarkPoint_Vector2_CGRect_nuint_nuint_string")] - static extern CGPoint VNNormalizedFaceBoundingBoxPointForLandmarkPoint (Vector2 faceLandmarkPoint, CGRect faceBoundingBox, nuint imageWidth, nuint imageHeight, out IntPtr error); + unsafe static extern CGPoint VNNormalizedFaceBoundingBoxPointForLandmarkPoint (Vector2 faceLandmarkPoint, CGRect faceBoundingBox, nuint imageWidth, nuint imageHeight, IntPtr* error); public static CGPoint GetNormalizedFaceBoundingBoxPoint (Vector2 faceLandmarkPoint, CGRect faceBoundingBox, nuint imageWidth, nuint imageHeight) { IntPtr error; - var result = VNNormalizedFaceBoundingBoxPointForLandmarkPoint (faceLandmarkPoint, faceBoundingBox, imageWidth, imageHeight, out error); + CGPoint result; + unsafe { + result = VNNormalizedFaceBoundingBoxPointForLandmarkPoint (faceLandmarkPoint, faceBoundingBox, imageWidth, imageHeight, &error); + } if (error != IntPtr.Zero) throw new InvalidOperationException (Marshal.PtrToStringAuto (error)); @@ -133,12 +140,15 @@ public static CGPoint GetNormalizedFaceBoundingBoxPoint (Vector2 faceLandmarkPoi } [DllImport ("__Internal", EntryPoint = "xamarin_CGPoint__VNImagePointForFaceLandmarkPoint_Vector2_CGRect_nuint_nuint_string")] - static extern CGPoint VNImagePointForFaceLandmarkPoint (Vector2 faceLandmarkPoint, CGRect faceBoundingBox, nuint imageWidth, nuint imageHeight, out IntPtr error); + unsafe static extern CGPoint VNImagePointForFaceLandmarkPoint (Vector2 faceLandmarkPoint, CGRect faceBoundingBox, nuint imageWidth, nuint imageHeight, IntPtr* error); public static CGPoint GetImagePoint (Vector2 faceLandmarkPoint, CGRect faceBoundingBox, nuint imageWidth, nuint imageHeight) { IntPtr error; - var result = VNImagePointForFaceLandmarkPoint (faceLandmarkPoint, faceBoundingBox, imageWidth, imageHeight, out error); + CGPoint result; + unsafe { + result = VNImagePointForFaceLandmarkPoint (faceLandmarkPoint, faceBoundingBox, imageWidth, imageHeight, &error); + } if (error != IntPtr.Zero) throw new InvalidOperationException (Marshal.PtrToStringAuto (error)); diff --git a/tests/cecil-tests/BlittablePInvokes.KnownFailures.cs b/tests/cecil-tests/BlittablePInvokes.KnownFailures.cs index 25cee30bd483..aa9059974ce6 100644 --- a/tests/cecil-tests/BlittablePInvokes.KnownFailures.cs +++ b/tests/cecil-tests/BlittablePInvokes.KnownFailures.cs @@ -157,8 +157,6 @@ public partial class BlittablePInvokes { "CoreFoundation.CFMessagePortSendRequestStatus CoreFoundation.CFMessagePort::CFMessagePortSendRequest(System.IntPtr,System.Int32,System.IntPtr,System.Double,System.Double,System.IntPtr,System.IntPtr&)", "CoreFoundation.CFRunLoopExitReason CoreFoundation.CFRunLoop::CFRunLoopRunInMode(System.IntPtr,System.Double,System.Boolean)", "CoreGraphics.CGAffineTransform CoreGraphics.CGPDFPage::CGPDFPageGetDrawingTransform(System.IntPtr,CoreGraphics.CGPDFBox,CoreGraphics.CGRect,System.Int32,System.Boolean)", - "CoreGraphics.CGPoint Vision.VNUtils::VNImagePointForFaceLandmarkPoint(System.Numerics.Vector2,CoreGraphics.CGRect,System.UIntPtr,System.UIntPtr,System.IntPtr&)", - "CoreGraphics.CGPoint Vision.VNUtils::VNNormalizedFaceBoundingBoxPointForLandmarkPoint(System.Numerics.Vector2,CoreGraphics.CGRect,System.UIntPtr,System.UIntPtr,System.IntPtr&)", "CoreGraphics.CGRect CoreMedia.CMFormatDescription::CMVideoFormatDescriptionGetCleanAperture(System.IntPtr,System.Boolean)", "CoreGraphics.CGSize CoreMedia.CMFormatDescription::CMVideoFormatDescriptionGetPresentationDimensions(System.IntPtr,System.Boolean,System.Boolean)", "CoreGraphics.CGSize CoreText.CTFramesetter::CTFramesetterSuggestFrameSizeWithConstraints(System.IntPtr,Foundation.NSRange,System.IntPtr,CoreGraphics.CGSize,Foundation.NSRange&)", @@ -575,7 +573,6 @@ public partial class BlittablePInvokes { "System.Boolean UIKit.UIFloatRange::UIFloatRangeIsInfinite(UIKit.UIFloatRange)", "System.Boolean UIKit.UIVideo::UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(System.IntPtr)", "System.Boolean VideoToolbox.VTDecompressionSession::VTIsHardwareDecodeSupported(CoreMedia.CMVideoCodecType)", - "System.Boolean Vision.VNUtils::IsIdentityRect(CoreGraphics.CGRect)", "System.Byte Security.SecProtocolMetadata::sec_protocol_metadata_access_supported_signature_algorithms(System.IntPtr,ObjCRuntime.BlockLiteral*)", "System.Byte* Network.NWEndpoint::nw_endpoint_get_signature(System.IntPtr,System.UIntPtr&)", "System.Char CoreFoundation.CFString::CFStringGetCharacterAtIndex(System.IntPtr,System.IntPtr)", diff --git a/tests/monotouch-test/Vision/VNUtilsTests.cs b/tests/monotouch-test/Vision/VNUtilsTests.cs index 3d507180a422..d0e26885348d 100644 --- a/tests/monotouch-test/Vision/VNUtilsTests.cs +++ b/tests/monotouch-test/Vision/VNUtilsTests.cs @@ -18,6 +18,12 @@ using Foundation; using Vision; +#if NET +using Vector2 = global::System.Numerics.Vector2; +#else +using Vector2 = global::OpenTK.Vector2; +#endif + namespace MonoTouchFixtures.Vision { [TestFixture] @@ -54,6 +60,24 @@ public void GetNormalizedRectTest () var normalizedRect = VNUtils.GetImageRect (new CGRect (2, 34, 5, 67), 8, 90, new CGRect (123, 4, 56, 7)); Assert.That (normalizedRect, Is.Not.EqualTo (CGRect.Empty), "VNNormalizedRectForImageRectUsingRegionOfInterest is not empty"); } + + [Test] + public void GetNormalizedFaceBoundingBoxPointTest () + { + var normalizedPoint = VNUtils.GetNormalizedFaceBoundingBoxPoint (new Vector2 (9, 8), new CGRect (3, 14, 15, 92), 2, 11); + Assert.That (normalizedPoint, Is.Not.EqualTo (CGPoint.Empty), "VNNormalizedFaceBoundingBoxPointForLandmarkPoint is not empty"); + } + + + [Test] + public void IsIdentityTest () + { + Assert.True (VNUtils.IsIdentityRect (new CGRect (0, 0, 1, 1)), "Identity"); + Assert.False (VNUtils.IsIdentityRect (new CGRect (0, 0, 2, 2)), "Not Identity A"); + Assert.False (VNUtils.IsIdentityRect (new CGRect (1, 1, 1, 1)), "Not Identity B"); + Assert.False (VNUtils.IsIdentityRect (new CGRect (1, 1, 0, 0)), "Not Identity C"); + } + } } #endif