From f307f377a19d30d7cbac05478e37dd4d81350741 Mon Sep 17 00:00:00 2001 From: Vincent Dondain Date: Thu, 16 Nov 2017 13:47:21 -0500 Subject: [PATCH] [coreimage] Add new Image Dictionary Keys - Fixes bug #59296: [coreimage] Some `kCI*`keys are not bound (https://bugzilla.xamarin.com/show_bug.cgi?id=59296) - Generate a StrongDictionary for `CIImageInitializationOptions` to avoid manual code. - Move `CGImageProperties Properties { get; set; }` to parent type `CIImageInitializationOptions` (avoid 2 strong dictionaries). Reason: Even though the headers give us an indication of which constructors should use some CIImage keys it's hard to apply that to all constructors consistently. We could have 1 strong dictionary per constructor (duplicate members) with just the exact members we know it supports (based on headers) however it's better to have a single strong dictionary and document the options because A might be available only in X today and Y next too next year. - Fix `DictionaryContainer`'s `GetStrongDictionary` to return null and not throw if target StrongDictionary is not yet set. Basically: ``` var options = new CIImageInitializationOptionsWithMetadata (); Assert.That (options.Dictionary.Count, Is.EqualTo (0), "Count"); ``` Would throw: ``` System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation. ----> System.ArgumentNullException : Value cannot be null. ``` --- src/CoreImage/CIImage.cs | 2 +- src/CoreImage/CIImageInitializationOptions.cs | 29 ++------- src/Foundation/DictionaryContainer.cs | 2 + src/coreimage.cs | 63 ++++++++++++++++--- tests/xtro-sharpie/common.pending | 8 --- 5 files changed, 63 insertions(+), 41 deletions(-) diff --git a/src/CoreImage/CIImage.cs b/src/CoreImage/CIImage.cs index 259eaf9b3cfd..205bf301d457 100644 --- a/src/CoreImage/CIImage.cs +++ b/src/CoreImage/CIImage.cs @@ -144,7 +144,7 @@ public static CIImage FromCGImage (CGImage image, CGColorSpace colorSpace) throw new ArgumentNullException ("colorSpace"); using (var arr = NSArray.FromIntPtrs (new IntPtr [] { colorSpace.Handle })){ - using (var keys = NSArray.FromIntPtrs (new IntPtr [] { CIImageColorSpaceKey.Handle } )){ + using (var keys = NSArray.FromIntPtrs (new IntPtr [] { CIImageInitializationOptionsKeys.ColorSpaceKey.Handle } )){ using (var dict = NSDictionary.FromObjectsAndKeysInternal (arr, keys)){ return FromCGImage (image, dict); } diff --git a/src/CoreImage/CIImageInitializationOptions.cs b/src/CoreImage/CIImageInitializationOptions.cs index 387c6e7e26c5..8a803fd2e97a 100644 --- a/src/CoreImage/CIImageInitializationOptions.cs +++ b/src/CoreImage/CIImageInitializationOptions.cs @@ -34,30 +34,21 @@ namespace XamCore.CoreImage { - public class CIImageInitializationOptions : DictionaryContainer + public partial class CIImageInitializationOptions { #if !COREBUILD - public CIImageInitializationOptions () - : base (new NSMutableDictionary ()) - { - } - - public CIImageInitializationOptions (NSDictionary dictionary) - : base (dictionary) - { - } - public CGColorSpace ColorSpace { get { - return GetNativeValue (CIImage.CIImageColorSpaceKey); + return GetNativeValue (CIImageInitializationOptionsKeys.ColorSpaceKey); } set { - SetNativeValue (CIImage.CIImageColorSpaceKey, value == null ? null : value); + SetNativeValue (CIImageInitializationOptionsKeys.ColorSpaceKey, value == null ? null : value); } } #endif } + // Keeping 'CIImageInitializationOptionsWithMetadata' to avoid breaking change public class CIImageInitializationOptionsWithMetadata : CIImageInitializationOptions { #if !COREBUILD @@ -69,18 +60,6 @@ public CIImageInitializationOptionsWithMetadata (NSDictionary dictionary) : base (dictionary) { } - - public CGImageProperties Properties { - get { - var dict = GetNativeValue (CIImage.CIImagePropertiesKey); - if (dict == null) - return null; - return new CGImageProperties (dict); - } - set { - SetNativeValue (CIImage.CIImagePropertiesKey, value == null ? null : value.Dictionary, false); - } - } #endif } } diff --git a/src/Foundation/DictionaryContainer.cs b/src/Foundation/DictionaryContainer.cs index 51db962f0990..e282c63f4fc8 100644 --- a/src/Foundation/DictionaryContainer.cs +++ b/src/Foundation/DictionaryContainer.cs @@ -237,6 +237,8 @@ protected NSDictionary GetNSDictionary (NSString key) throw new ArgumentNullException ("key"); var dict = GetNSDictionary (key); + if (dict == null) + return null; T value = (T)Activator.CreateInstance (typeof(T), new object[] { dict } ); diff --git a/src/coreimage.cs b/src/coreimage.cs index 71452e0a83b7..7670b223c642 100644 --- a/src/coreimage.cs +++ b/src/coreimage.cs @@ -942,6 +942,14 @@ interface CIFilterInputKey { [Since (7,0)] [Field ("kCIInputExtentKey", "+CoreImage")] NSString Extent { get; } + + [iOS (11,0), TV (11,0), Mac (10,13)] + [Field ("kCIInputDepthImageKey", "+CoreImage")] + NSString DepthImage { get; } + + [iOS (11,0), TV (11,0), Mac (10,13)] + [Field ("kCIInputDisparityImageKey", "+CoreImage")] + NSString DisparityImage { get; } } [Since (5,0)] @@ -1262,6 +1270,54 @@ interface CIFilterShape : NSCopying { [Export ("extent")] CGRect Extent { get; } } + + [StrongDictionary ("CIImageInitializationOptionsKeys")] + interface CIImageInitializationOptions { + // Bug #60726: [Generator] Support INativeObject in StrongDictionary + // (https://bugzilla.xamarin.com/show_bug.cgi?id=60726) + // CGColorSpace ColorSpace { get; set; } + + CoreGraphics.CGImageProperties Properties { get; set; } + + [iOS (11,0), TV (11,0), Mac (10,13)] + bool ApplyOrientationProperty { get; set; } + + [iOS (11,0), TV (11,0), Mac (10,13)] + bool NearestSampling { get; set; } + + [iOS (11,0), TV (11,0), Mac (10,13)] + bool AuxiliaryDepth { get; set; } + + [iOS (11,0), TV (11,0), Mac (10,13)] + bool AuxiliaryDisparity { get; set; } + } + + [Internal] + [Static] + interface CIImageInitializationOptionsKeys { + [Field ("kCIImageColorSpace")] + NSString ColorSpaceKey { get; } + + [MountainLion] + [Field ("kCIImageProperties")] + NSString PropertiesKey { get; } + + [iOS (11,0), TV (11,0), Mac (10,13)] + [Field ("kCIImageNearestSampling")] + NSString NearestSamplingKey { get; } + + [iOS (11,0), TV (11,0), Mac (10,13)] + [Field ("kCIImageApplyOrientationProperty")] + NSString ApplyOrientationPropertyKey { get; } + + [iOS (11,0), TV (11,0), Mac (10,13)] + [Field ("kCIImageAuxiliaryDepth")] + NSString AuxiliaryDepthKey { get; } + + [iOS (11,0), TV (11,0), Mac (10,13)] + [Field ("kCIImageAuxiliaryDisparity")] + NSString AuxiliaryDisparityKey { get; } + } [BaseType (typeof (NSObject))] [Since (5,0)] @@ -1692,13 +1748,6 @@ interface CIImage : NSSecureCoding, NSCopying { [Export ("autoAdjustmentFiltersWithOptions:"), Internal] NSArray _GetAutoAdjustmentFilters ([NullAllowed] NSDictionary opts); - [Field ("kCIImageColorSpace"), Internal] - NSString CIImageColorSpaceKey { get; } - - [MountainLion] - [Field ("kCIImageProperties"), Internal] - NSString CIImagePropertiesKey { get; } - [Since (6,0)] // publicly documented in 7.0 but really available since 6.0 [Mac (10,12)] [Export ("regionOfInterestForImage:inRect:")] diff --git a/tests/xtro-sharpie/common.pending b/tests/xtro-sharpie/common.pending index bd8cb9cb9965..8a6ad07cffae 100644 --- a/tests/xtro-sharpie/common.pending +++ b/tests/xtro-sharpie/common.pending @@ -65,14 +65,6 @@ !missing-selector! CISampler::initWithImage:keysAndValues: not bound !missing-selector! +CISampler::samplerWithImage:keysAndValues: not bound -## https://bugzilla.xamarin.com/show_bug.cgi?id=59296 -!missing-field! kCIImageApplyOrientationProperty not bound -!missing-field! kCIImageAuxiliaryDepth not bound -!missing-field! kCIImageAuxiliaryDisparity not bound -!missing-field! kCIImageNearestSampling not bound -!missing-field! kCIInputDepthImageKey not bound -!missing-field! kCIInputDisparityImageKey not bound - # Foundation