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

[CoreVideo] Create a strongly typed dictionary for the CVPixelFormat values. #21110

Merged
merged 3 commits into from
Aug 30, 2024
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
291 changes: 216 additions & 75 deletions src/CoreVideo/CVPixelFormatDescription.cs

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions src/CoreVideo/CoreVideo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public struct CVSMPTETime {
public Int16 Frames;
}

#if !XAMCORE_5_0
#if NET
[SupportedOSPlatform ("ios")]
[SupportedOSPlatform ("maccatalyst")]
Expand All @@ -131,4 +132,32 @@ public struct CVFillExtendedPixelsCallBackData {
}

public delegate bool CVFillExtendedPixelsCallBack (IntPtr pixelBuffer, IntPtr refCon);
#endif // !XAMCORE_5_0

#if NET
[SupportedOSPlatform ("ios")]
[SupportedOSPlatform ("maccatalyst")]
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("tvos")]
#if XAMCORE_5_0
public unsafe struct CVFillExtendedPixelsCallBackData {
#else
[NativeName ("CVFillExtendedPixelsCallBackData")]
public unsafe struct CVFillExtendedPixelsCallBackDataStruct {
#endif
public nint /* CFIndex */ Version;
public delegate* unmanaged<IntPtr, IntPtr, byte> FillCallBack;
public IntPtr UserInfo;
#if !COREBUILD
public unsafe bool CallFillCallback (CVPixelBuffer buffer)
{
if (FillCallBack is null)
throw new InvalidOperationException ($"The callback is null.");
var rv = FillCallBack (buffer.GetCheckedHandle (), UserInfo);
return rv != 0;
}
#endif
}
#endif

}
200 changes: 200 additions & 0 deletions src/corevideo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
//

using System;

using CoreGraphics;
using Foundation;
using ObjCRuntime;
#if !WATCH
Expand Down Expand Up @@ -568,4 +570,202 @@ public enum CVVersatileBayerPattern : uint {
Gbrg = 2,
Bggr = 3,
}

[Partial]
interface CVPixelFormatKeys {
[Field ("kCVPixelFormatName")]
NSString Name { get; }

[Field ("kCVPixelFormatConstant")]
NSString Constant { get; }

[Field ("kCVPixelFormatCodecType")]
NSString CodecType { get; }

[Field ("kCVPixelFormatFourCC")]
NSString FourCC { get; }

[Field ("kCVPixelFormatContainsAlpha")]
NSString ContainsAlpha { get; }

[Field ("kCVPixelFormatContainsYCbCr")]
NSString ContainsYCbCr { get; }

[Field ("kCVPixelFormatContainsRGB")]
NSString ContainsRgb { get; }

[Field ("kCVPixelFormatContainsGrayscale")]
NSString ContainsGrayscale { get; }

[iOS (16, 0), Mac (13, 0), MacCatalyst (16, 0), TV (16, 0), Watch (9, 0)]
[Field ("kCVPixelFormatContainsSenselArray")]
NSString ContainsSenselArray { get; }

[Field ("kCVPixelFormatComponentRange")]
NSString ComponentRange { get; }

[Field ("kCVPixelFormatPlanes")]
NSString Planes { get; }

[Field ("kCVPixelFormatBlockWidth")]
NSString BlockWidth { get; }

[Field ("kCVPixelFormatBlockHeight")]
NSString BlockHeight { get; }

[Field ("kCVPixelFormatBitsPerBlock")]
NSString BitsPerBlock { get; }

[Field ("kCVPixelFormatBlockHorizontalAlignment")]
NSString BlockHorizontalAlignment { get; }

[Field ("kCVPixelFormatBlockVerticalAlignment")]
NSString BlockVerticalAlignment { get; }

[Field ("kCVPixelFormatBlackBlock")]
NSString BlackBlock { get; }

[Field ("kCVPixelFormatHorizontalSubsampling")]
NSString HorizontalSubsampling { get; }

[Field ("kCVPixelFormatVerticalSubsampling")]
NSString VerticalSubsampling { get; }

[Field ("kCVPixelFormatOpenGLFormat")]
NSString OpenGLFormat { get; }

[Field ("kCVPixelFormatOpenGLType")]
NSString OpenGLType { get; }

[Field ("kCVPixelFormatOpenGLInternalFormat")]
NSString OpenGLInternalFormat { get; }

[Field ("kCVPixelFormatCGBitmapInfo")]
NSString CGBitmapInfo { get; }

[Field ("kCVPixelFormatQDCompatibility")]
NSString QDCompatibility { get; }

[Field ("kCVPixelFormatCGBitmapContextCompatibility")]
NSString CGBitmapContextCompatibility { get; }

[Field ("kCVPixelFormatCGImageCompatibility")]
NSString CGImageCompatibility { get; }

[Field ("kCVPixelFormatOpenGLCompatibility")]
NSString OpenGLCompatibility { get; }

[NoWatch, NoMacCatalyst, NoMac]
[Field ("kCVPixelFormatOpenGLESCompatibility")]
NSString OpenGlesCompatibility { get; }

[Field ("kCVPixelFormatFillExtendedPixelsCallback")]
NSString FillExtendedPixelsCallback { get; }
}

[Partial]
interface CVPixelFormatComponentRangeKeys {
[Field ("kCVPixelFormatComponentRange_VideoRange")]
NSString VideoRange { get; }

[Field ("kCVPixelFormatComponentRange_FullRange")]
NSString FullRange { get; }

[Field ("kCVPixelFormatComponentRange_WideRange")]
NSString WideRange { get; }
}


[StrongDictionary ("CVPixelFormatComponentRangeKeys", Suffix = "")]
interface CVPixelFormatComponentRange {
// there's no documentation about the type, so binding as NSObject
NSObject VideoRange { get; set; }

// there's no documentation about the type, so binding as NSObject
NSObject FullRange { get; set; }

// there's no documentation about the type, so binding as NSObject
NSObject WideRange { get; set; }
}

[StrongDictionary ("CVPixelFormatKeys", Suffix = "")]
interface CVPixelFormatDescription {
string Name { get; set; }

CVPixelFormatType Constant { get; set; }

// Documentation says 'CFString', but it also says 'CFString' about another property which clearly isn't, so I don't trust the documentation.
// Headers don't say, and tests don't show anything useful, there are no hits on Google for the underlying field, so leaving this typed as 'NSObject'.
NSObject CodecType { get; set; }

int FourCC { get; set; }

bool ContainsAlpha { get; set; }

#if XAMCORE_5_0
bool ContainsYCbCr { get; set; }
#else
[Export ("ContainsYCbCr")]
bool FormatContainsYCbCr { get; set; }
#endif

#if XAMCORE_5_0
bool ContainsRgb { get; set; }
#else
[Export ("ContainsRgb")]
bool FormatContainsRgb { get; set; }
#endif

bool ContainsGrayscale { get; set; }

[iOS (16, 0), Mac (13, 0), MacCatalyst (16, 0), TV (16, 0), Watch (9, 0)]
#if XAMCORE_5_0
bool ContainsSenselArray { get; set; }
#else
[Export ("ContainsSenselArray")]
bool FormatContainsSenselArray { get; set; }
#endif

CVPixelFormatComponentRange ComponentRange { get; set; }

// This can be an array of dictionaries, or a single dictionary when there's only one plane, so we have to type as 'NSObject'.
NSObject Planes { get; set; }

int BlockWidth { get; set; }

int BlockHeight { get; set; }

int BitsPerBlock { get; set; }

int BlockHorizontalAlignment { get; set; }

int BlockVerticalAlignment { get; set; }

NSData BlackBlock { get; set; }

int HorizontalSubsampling { get; set; }

int VerticalSubsampling { get; set; }

int OpenGLFormat { get; set; }

int OpenGLType { get; set; }

int OpenGLInternalFormat { get; set; }

CGBitmapFlags CGBitmapInfo { get; set; }

bool QDCompatibility { get; set; }

bool CGBitmapContextCompatibility { get; set; }

bool CGImageCompatibility { get; set; }

bool OpenGLCompatibility { get; set; }

[NoWatch, NoMacCatalyst, NoMac]
bool OpenGlesCompatibility { get; set; }

NSData FillExtendedPixelsCallback { get; set; }
}
}
Loading