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 1 commit
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
5 changes: 3 additions & 2 deletions src/ImageIO/CGImageDestination.cs
Original file line number Diff line number Diff line change
Expand Up @@ -502,8 +502,9 @@ public bool CopyImageSource (CGImageSource image, CGImageDestinationOptions opti

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.

{
var dict = auxiliaryDataInfo == null ? null : auxiliaryDataInfo.ToDictionary ();
CGImageDestinationAddAuxiliaryDataInfo (dest.Handle, auxiliaryImageDataType.GetConstant ().Handle, dict == null ? IntPtr.Zero : dict.Handle);
using (var dict = auxiliaryDataInfo?.ToDictionary ()) {
CGImageDestinationAddAuxiliaryDataInfo (NativeObjectHelper.GetHandle (dest), auxiliaryImageDataType.GetConstant ().Handle, dict == null ? IntPtr.Zero : dict.Handle);
Copy link
Contributor

Choose a reason for hiding this comment

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

NativeObjectHelper.GetHandle is an extension method so you can do:

CGImageDestinationAddAuxiliaryDataInfo (dest.GetHandle (), auxiliaryImageDataType.GetConstant ().GetHandle (), dict.GetHandle ());

it's shorter and also cover the case where a constant might be null (e.g. if only available in a more recent version of iOS/macOS)

}
}
}
}
33 changes: 17 additions & 16 deletions src/ImageIO/CGImageSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -383,35 +383,36 @@ public CGImageSourceStatus GetStatus (int index)

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.Handle, index, auxiliaryImageDataType.GetConstant ().Handle);
var ptr = CGImageSourceCopyAuxiliaryDataInfoAtIndex (imageSource?.Handle ?? IntPtr.Zero, index, auxiliaryImageDataType.GetConstant ().Handle);
Copy link
Contributor

Choose a reason for hiding this comment

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

imageSource.GetHandle() is simpler here too

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

var dictionary = new NSDictionary (ptr);

var info = new CGImageAuxiliaryDataInfo ();

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

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

if (success)
info.DepthData = data;
if (success)
info.DepthData = data;

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

if (success)
info.DepthDataDescription = dict;
if (success)
info.DepthDataDescription = dict;

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

if (success)
info.Metadata = metadata;
if (success)
info.Metadata = metadata;
}

return info;

}
}
}
4 changes: 2 additions & 2 deletions src/imageio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,7 @@ interface CGCopyImageSourceOptions {
#endif

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

Expand All @@ -1225,7 +1225,7 @@ public enum CGImageAuxiliaryDataType {

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

Expand Down