Skip to content

Commit

Permalink
[coreimage] Add new Image Dictionary Keys
Browse files Browse the repository at this point in the history
- 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.
```
  • Loading branch information
VincentDondain committed Nov 19, 2017
1 parent fc7f6ce commit f307f37
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/CoreImage/CIImage.cs
Expand Up @@ -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);
}
Expand Down
29 changes: 4 additions & 25 deletions src/CoreImage/CIImageInitializationOptions.cs
Expand Up @@ -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<CGColorSpace> (CIImage.CIImageColorSpaceKey);
return GetNativeValue<CGColorSpace> (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
Expand All @@ -69,18 +60,6 @@ public CIImageInitializationOptionsWithMetadata (NSDictionary dictionary)
: base (dictionary)
{
}

public CGImageProperties Properties {
get {
var dict = GetNativeValue<NSDictionary> (CIImage.CIImagePropertiesKey);
if (dict == null)
return null;
return new CGImageProperties (dict);
}
set {
SetNativeValue (CIImage.CIImagePropertiesKey, value == null ? null : value.Dictionary, false);
}
}
#endif
}
}
2 changes: 2 additions & 0 deletions src/Foundation/DictionaryContainer.cs
Expand Up @@ -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 }
);
Expand Down
63 changes: 56 additions & 7 deletions src/coreimage.cs
Expand Up @@ -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)]
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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:")]
Expand Down
8 changes: 0 additions & 8 deletions tests/xtro-sharpie/common.pending
Expand Up @@ -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

Expand Down

0 comments on commit f307f37

Please sign in to comment.