2016-05-26 16:06:52 +03:00
|
|
|
//
|
|
|
|
// Unit tests for CIImage
|
|
|
|
//
|
|
|
|
// Authors:
|
|
|
|
// Marek Safar (marek.safar@gmail.com)
|
|
|
|
//
|
|
|
|
// Copyright 2012 Xamarin Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#if !__WATCHOS__
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
#if XAMCORE_2_0
|
|
|
|
using Foundation;
|
2017-01-12 21:13:56 +03:00
|
|
|
#if MONOMAC
|
|
|
|
using AppKit;
|
|
|
|
#else
|
2016-05-26 16:06:52 +03:00
|
|
|
using UIKit;
|
2017-01-12 21:13:56 +03:00
|
|
|
#endif
|
2016-05-26 16:06:52 +03:00
|
|
|
using CoreImage;
|
|
|
|
using CoreGraphics;
|
|
|
|
using ObjCRuntime;
|
|
|
|
#else
|
|
|
|
using MonoTouch.CoreImage;
|
|
|
|
using MonoTouch.CoreGraphics;
|
|
|
|
using MonoTouch.Foundation;
|
|
|
|
using MonoTouch.UIKit;
|
|
|
|
using MonoTouch.ObjCRuntime;
|
|
|
|
#endif
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
|
|
#if XAMCORE_2_0
|
|
|
|
using RectangleF=CoreGraphics.CGRect;
|
|
|
|
using SizeF=CoreGraphics.CGSize;
|
|
|
|
using PointF=CoreGraphics.CGPoint;
|
|
|
|
#else
|
|
|
|
using nfloat=global::System.Single;
|
|
|
|
using nint=global::System.Int32;
|
|
|
|
using nuint=global::System.UInt32;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace MonoTouchFixtures.CoreImage {
|
|
|
|
|
|
|
|
[TestFixture]
|
|
|
|
[Preserve (AllMembers = true)]
|
|
|
|
public class ImageTest {
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void EmptyImage ()
|
|
|
|
{
|
2018-07-04 12:44:14 +03:00
|
|
|
TestRuntime.AssertSystemVersion (PlatformName.MacOSX, 10, 8, throwIfOtherPlatform: false);
|
2016-05-26 16:06:52 +03:00
|
|
|
Assert.IsNull (CIImage.EmptyImage.Properties);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void InitializationWithCustomMetadata ()
|
|
|
|
{
|
2018-07-04 12:44:14 +03:00
|
|
|
TestRuntime.AssertSystemVersion (PlatformName.MacOSX, 10, 8, throwIfOtherPlatform: false);
|
2016-05-26 16:06:52 +03:00
|
|
|
string file = Path.Combine (NSBundle.MainBundle.ResourcePath, "basn3p08.png");
|
|
|
|
using (var dp = new CGDataProvider (file)) {
|
|
|
|
using (var img = CGImage.FromPNG (dp, null, false, CGColorRenderingIntent.Default)) {
|
|
|
|
|
|
|
|
var opt = new CIImageInitializationOptionsWithMetadata () {
|
|
|
|
Properties = new CGImageProperties () {
|
|
|
|
ProfileName = "test profile name"
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
using (var ci = new CIImage (img, opt)) {
|
|
|
|
Assert.AreEqual ("test profile name", ci.Properties.ProfileName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-12 21:13:56 +03:00
|
|
|
#if !MONOMAC // Testing an issue with UIImage.CIImage, iOS specific (NSImage has no CIImage property)
|
2016-05-26 16:06:52 +03:00
|
|
|
[Test]
|
|
|
|
public void UIImageInterop ()
|
|
|
|
{
|
|
|
|
// to validate http://stackoverflow.com/q/14464154/220643
|
|
|
|
string file = Path.Combine (NSBundle.MainBundle.ResourcePath, "basn3p08.png");
|
|
|
|
using (var url = NSUrl.FromFilename (file))
|
|
|
|
using (var ci = CIImage.FromUrl (url))
|
|
|
|
using (var ui = new UIImage (ci, 1.0f, UIImageOrientation.Up)) {
|
|
|
|
Assert.IsNotNull (ui.CIImage, "CIImage");
|
|
|
|
}
|
|
|
|
}
|
2017-01-12 21:13:56 +03:00
|
|
|
#endif
|
2016-05-26 16:06:52 +03:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void AreaHistogram ()
|
|
|
|
{
|
2018-07-04 12:44:14 +03:00
|
|
|
TestRuntime.AssertSystemVersion (PlatformName.iOS, 8, 0, throwIfOtherPlatform: false);
|
|
|
|
TestRuntime.AssertSystemVersion (PlatformName.MacOSX, 10, 10, throwIfOtherPlatform: false);
|
2016-05-26 16:06:52 +03:00
|
|
|
|
|
|
|
// validate that a null NSDictionary is correct (i.e. uses filter defaults)
|
|
|
|
using (var h = CIImage.EmptyImage.CreateByFiltering ("CIAreaHistogram", null)) {
|
|
|
|
// broken on simulator/64 bits on iOS9 beta 2 - radar 21564256 -> fixed in beta 4
|
2018-07-03 18:09:49 +03:00
|
|
|
var success = true;
|
|
|
|
#if __MACOS__
|
2018-07-04 12:44:14 +03:00
|
|
|
if (!TestRuntime.CheckSystemVersion (PlatformName.MacOSX, 10, 11))
|
2018-07-03 18:09:49 +03:00
|
|
|
success = false;
|
|
|
|
#endif
|
|
|
|
if (success) {
|
|
|
|
Assert.That (h.Extent.Height, Is.EqualTo ((nfloat)1), "Height");
|
|
|
|
} else {
|
|
|
|
Assert.IsNull (h, "Image");
|
|
|
|
}
|
2016-05-26 16:06:52 +03:00
|
|
|
}
|
|
|
|
}
|
2016-09-28 13:33:51 +03:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void CIImageColorSpaceTest ()
|
|
|
|
{
|
|
|
|
if (!TestRuntime.CheckXcodeVersion (7, 0))
|
|
|
|
Assert.Inconclusive ("requires iOS9+");
|
|
|
|
|
2017-01-12 21:13:56 +03:00
|
|
|
using (var cgimage = new CIImage (NSBundle.MainBundle.GetUrlForResource ("xamarin1", "png")))
|
2016-09-28 13:33:51 +03:00
|
|
|
using (var cs = cgimage.ColorSpace) {
|
2017-01-13 21:05:32 +03:00
|
|
|
Assert.NotNull (cs, "ColorSpace");
|
|
|
|
Assert.That (cs.Handle, Is.Not.EqualTo (IntPtr.Zero), "Handle");
|
2016-09-28 13:33:51 +03:00
|
|
|
}
|
|
|
|
}
|
2016-05-26 16:06:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // !__WATCHOS__
|