Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
27 changes: 27 additions & 0 deletions src/CoreVideo/CVPixelBufferAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,33 @@ public CVPixelFormatType? PixelFormatType {
}
}

/// <summary>The pixel formats of the pixel buffer.</summary>
/// <value></value>
/// <remarks>The property uses constant kCVPixelBufferPixelFormatTypeKey value to access the underlying dictionary.</remarks>
public CVPixelFormatType []? PixelFormatTypes {
get {
var obj = GetNativeValue<NSObject> (CVPixelBuffer.PixelFormatTypeKey);
if (obj is null) {
return null;
} else if (obj is NSNumber number) {
return new CVPixelFormatType [] { (CVPixelFormatType) number.UInt32Value };
} else if (obj is NSArray array) {
return Array.ConvertAll (array.ToArray (), (v) => (CVPixelFormatType) ((NSNumber) v).UInt32Value);
} else {
throw new InvalidOperationException ($"Unable to convert object of type {obj.GetType ()} into an array of CVPixelFormatType.");
}
}
set {
if (value is null) {
SetNumberValue (CVPixelBuffer.PixelFormatTypeKey, (uint?) null);
} else if (value.Length == 1) {
SetNumberValue (CVPixelBuffer.PixelFormatTypeKey, (uint?) value [0]);
} else {
SetArrayValue (CVPixelBuffer.PixelFormatTypeKey, Array.ConvertAll (value, (v) => new NSNumber ((uint) v)));
}
}
}

/// <summary>The allocator used for the pixel buffer.</summary>
/// <value>
/// </value>
Expand Down
18 changes: 18 additions & 0 deletions src/Foundation/NSIndexSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,24 @@ public nuint [] ToArray ()
return indexes;
}

internal T [] ToInt64EnumArray<T> () where T: System.Enum
{
var array = ToArray ();
var rv = new T [array.Length];
for (var i = 0; i < array.Length; i++)
rv [i] = (T) (object) (long) array [i];
return rv;
}

internal HashSet<T> ToInt64EnumHashSet<T> () where T: System.Enum
{
var array = ToArray ();
var rv = new HashSet<T> ();
for (var i = 0; i < array.Length; i++)
rv.Add ((T) (object) (long) array [i]);
return rv;
}

public static NSIndexSet FromArray (nuint [] items)
{
if (items is null)
Expand Down
Loading
Loading