Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ImageIO] Update to Xcode 9 #2353

Merged
merged 6 commits into from
Jul 27, 2017
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion src/ImageIO/CGImageDestination.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,31 @@ internal NSMutableDictionary ToDictionary ()
}
#endif

[Watch (4,0), TV (11,0), Mac (10,13), iOS (11,0)]
public partial class CGImageAuxiliaryDataInfo {
public NSData DepthData { get; set; }

public NSDictionary DepthDataDescription { get; set; }

public CGImageMetadata Metadata { get; set; }

internal NSMutableDictionary ToDictionary ()
{
var dict = new NSMutableDictionary ();

if (Metadata != null)
dict.LowlevelSetObject (Metadata.Handle, kMetadata);

if (DepthDataDescription != null)
dict.LowlevelSetObject (DepthDataDescription.Handle, DataDescription);

if (DepthData != null)
dict.LowlevelSetObject (DepthDataDescription.Handle, Data);

return dict;
}
}

public class CGImageDestination : INativeObject, IDisposable {
internal IntPtr handle;

Expand Down Expand Up @@ -470,5 +495,16 @@ public bool CopyImageSource (CGImageSource image, CGImageDestinationOptions opti
o.Dispose ();
}
}

[Watch (4, 0), TV (11, 0), Mac (10, 13), iOS (11, 0)]
[DllImport (Constants.ImageIOLibrary)]
static extern void CGImageDestinationAddAuxiliaryDataInfo (IntPtr /* CGImageDestinationRef* */ idst, IntPtr /* CFStringRef* */ auxiliaryImageDataType, IntPtr /* CFDictionaryRef* */ auxiliaryDataInfoDictionary);

public void AddAuxiliaryDataInfo (CGImageDestination dest, CGImageAuxiliaryDataType auxiliaryImageDataType, CGImageAuxiliaryDataInfo auxiliaryDataInfo)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, missed that earlier. Copy [Watch (4, 0), TV (11, 0), Mac (10, 13), iOS (11, 0)] to the public method, otherwise the developer won't know if it's available.

{
using (var dict = auxiliaryDataInfo?.ToDictionary ()) {
CGImageDestinationAddAuxiliaryDataInfo (dest.GetHandle (), auxiliaryImageDataType.GetConstant ().GetHandle (), dict.GetHandle ());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If auxiliaryDataInfo is null, dict will be null, which will throw an NRE.

Arguments that shouldn't be null should be validated (null-checked) and ArgumentNullException should be thrown.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetHandle is an extension method, so it won't crash when dict is null. For a null value, dict.GetHandle () should return IntPtr.Zero

}
}
}
}
}
38 changes: 38 additions & 0 deletions src/ImageIO/CGImageSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -376,5 +376,43 @@ public CGImageSourceStatus GetStatus (int index)
{
return CGImageSourceGetStatusAtIndex (handle, index);
}

[iOS(11,0)][Mac (10,13)][Watch(4,0)][TV(11,0)]
[DllImport (Constants.ImageIOLibrary)]
static extern IntPtr /* CFDictionaryRef* */ CGImageSourceCopyAuxiliaryDataInfoAtIndex (IntPtr /* CGImageSourceRef* */ isrc, nuint index, IntPtr /* CFStringRef* */ auxiliaryImageDataType);

public CGImageAuxiliaryDataInfo CopyAuxiliaryDataInfo (CGImageSource imageSource, nuint index, CGImageAuxiliaryDataType auxiliaryImageDataType)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same (copy availability attributes)

{
var ptr = CGImageSourceCopyAuxiliaryDataInfoAtIndex (imageSource.GetHandle (), index, auxiliaryImageDataType.GetConstant ().GetHandle ());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arguments that shouldn't be null should be validated (null-checked) and ArgumentNullException should be thrown.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

if (ptr == IntPtr.Zero)
return null;

var info = new CGImageAuxiliaryDataInfo ();

using (var dictionary = Runtime.GetNSObject<NSDictionary> (ptr)) {
bool success;

NSData data;
success = dictionary.TryGetValue<NSData> (new NSString (CGImageAuxiliaryDataInfo.Data), out data);

if (success)
info.DepthData = data;

NSDictionary dict;
success = dictionary.TryGetValue<NSDictionary> (new NSString (CGImageAuxiliaryDataInfo.DataDescription), out dict);

if (success)
info.DepthDataDescription = dict;

CGImageMetadata metadata;
success = dictionary.TryGetValue<CGImageMetadata> (new NSString (CGImageAuxiliaryDataInfo.kMetadata), out metadata);

if (success)
info.Metadata = metadata;
}

return info;

}
}
}
66 changes: 66 additions & 0 deletions src/imageio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,50 @@ interface CGImageProperties {
[Field ("kCGImagePropertyMakerAppleDictionary")]
NSString MakerAppleDictionary { get; }
#endif

[Mac (10, 13), iOS (11,0), TV (11,0), Watch (4,0)]
[Field ("kCGImagePropertyImageCount")]
NSString ImageCount { get; }

[Mac (10, 13), iOS (11,0), TV (11,0), Watch (4,0)]
[Field ("kCGImagePropertyWidth")]
NSString Width { get; }

[Mac (10, 13), iOS (11,0), TV (11,0), Watch (4,0)]
[Field ("kCGImagePropertyHeight")]
NSString Height { get; }

[Mac (10, 13), iOS (11,0), TV (11,0), Watch (4,0)]
[Field ("kCGImagePropertyBytesPerRow")]
NSString BytesPerRow { get; }

[Mac (10, 13), iOS (11,0), TV (11,0), Watch (4,0)]
[Field ("kCGImagePropertyNamedColorSpace")]
NSString NamedColorSpace { get; }

[Mac (10, 13), iOS (11,0), TV (11,0), Watch (4,0)]
[Field ("kCGImagePropertyPixelFormat")]
NSString PixelFormat { get; }

[Mac (10, 13), iOS (11,0), TV (11,0), Watch (4,0)]
[Field ("kCGImagePropertyImages")]
NSString Images { get; }

[Mac (10, 13), iOS (11,0), TV (11,0), Watch (4,0)]
[Field ("kCGImagePropertyThumbnailImages")]
NSString ThumbnailImages { get; }

[Mac (10, 13), iOS (11,0), TV (11,0), Watch (4,0)]
[Field ("kCGImagePropertyAuxiliaryData")]
NSString AuxiliaryData { get; }

[Mac (10, 13), iOS (11,0), TV (11,0), Watch (4,0)]
[Field ("kCGImagePropertyAuxiliaryDataType")]
NSString AuxiliaryDataType { get; }

[Mac (10, 13), iOS (11,0), TV (11,0), Watch (4,0)]
[Field ("kCGImagePropertyFileContentsDictionary")]
NSString FileContentsDictionary { get; }
}

[Since (7,0), MountainLion]
Expand Down Expand Up @@ -1169,4 +1213,26 @@ interface CGCopyImageSourceOptions {
IntPtr kOrientation { get; }
}
#endif

[Mac (10, 13), iOS (11,0), TV (11,0), Watch (4,0)]
enum CGImageAuxiliaryDataType {
[Field ("kCGImageAuxiliaryDataTypeDepth")]
Depth,

[Field ("kCGImageAuxiliaryDataTypeDisparity")]
Disparity,
}

[Partial]
[Mac (10, 13), iOS (11,0), TV (11,0), Watch (4,0)]
interface CGImageAuxiliaryDataInfo {
[Internal, Field ("kCGImageAuxiliaryDataInfoData")]
IntPtr Data { get; }

[Internal, Field ("kCGImageAuxiliaryDataInfoDataDescription")]
IntPtr DataDescription { get; }

[Internal, Field ("kCGImageAuxiliaryDataInfoMetadata")]
IntPtr kMetadata { get; }
}
}