-
Notifications
You must be signed in to change notification settings - Fork 559
Expand file tree
/
Copy pathCVPixelFormatDescription.cs
More file actions
405 lines (353 loc) · 16.8 KB
/
CVPixelFormatDescription.cs
File metadata and controls
405 lines (353 loc) · 16.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
//
// CVPixelFormatDescription.cs: Implements the managed CVPixelFormatDescription
//
// Authors: Mono Team
//
// Copyright 2010 Novell, Inc
// Copyright 2015 Xamarin Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.ComponentModel;
using CoreFoundation;
#if XAMCORE_5_0
using CVFillExtendedPixelsCallBackDataStruct = CoreVideo.CVFillExtendedPixelsCallBackData;
#endif
#nullable enable
namespace CoreVideo {
/// <summary>A class that supports the definition of customer pixel formats.</summary>
/// <remarks>To be added.</remarks>
public partial class CVPixelFormatDescription {
#if !COREBUILD
#if !XAMCORE_5_0
/// <summary>To be added.</summary>
/// <remarks>To be added.</remarks>
[Obsolete ("Use 'CVPixelFormatKeys.Name' instead.")]
[EditorBrowsable (EditorBrowsableState.Never)]
public static readonly NSString NameKey;
/// <summary>To be added.</summary>
/// <remarks>To be added.</remarks>
[Obsolete ("Use 'CVPixelFormatKeys.Constant' instead.")]
[EditorBrowsable (EditorBrowsableState.Never)]
public static readonly NSString ConstantKey;
/// <summary>To be added.</summary>
/// <remarks>To be added.</remarks>
[Obsolete ("Use 'CVPixelFormatKeys.CodecType' instead.")]
[EditorBrowsable (EditorBrowsableState.Never)]
public static readonly NSString CodecTypeKey;
/// <summary>To be added.</summary>
/// <remarks>To be added.</remarks>
[Obsolete ("Use 'CVPixelFormatKeys.FourCCKey' instead.")]
[EditorBrowsable (EditorBrowsableState.Never)]
public static readonly NSString FourCCKey;
/// <summary>To be added.</summary>
/// <remarks>To be added.</remarks>
[Obsolete ("Use 'CVPixelFormatKeys.Planes' instead.")]
[EditorBrowsable (EditorBrowsableState.Never)]
public static readonly NSString PlanesKey;
/// <summary>To be added.</summary>
/// <remarks>To be added.</remarks>
[Obsolete ("Use 'CVPixelFormatKeys.BlockWidth' instead.")]
[EditorBrowsable (EditorBrowsableState.Never)]
public static readonly NSString BlockWidthKey;
/// <summary>To be added.</summary>
/// <remarks>To be added.</remarks>
[Obsolete ("Use 'CVPixelFormatKeys.BlockHeight' instead.")]
[EditorBrowsable (EditorBrowsableState.Never)]
public static readonly NSString BlockHeightKey;
/// <summary>To be added.</summary>
/// <remarks>To be added.</remarks>
[Obsolete ("Use 'CVPixelFormatKeys.BitsPerBlock' instead.")]
[EditorBrowsable (EditorBrowsableState.Never)]
public static readonly NSString BitsPerBlockKey;
/// <summary>To be added.</summary>
/// <remarks>To be added.</remarks>
[Obsolete ("Use 'CVPixelFormatKeys.BlockHorizontalAlignment' instead.")]
[EditorBrowsable (EditorBrowsableState.Never)]
public static readonly NSString BlockHorizontalAlignmentKey;
/// <summary>To be added.</summary>
/// <remarks>To be added.</remarks>
[Obsolete ("Use 'CVPixelFormatKeys.BlockVerticalAlignment' instead.")]
[EditorBrowsable (EditorBrowsableState.Never)]
public static readonly NSString BlockVerticalAlignmentKey;
/// <summary>To be added.</summary>
/// <remarks>To be added.</remarks>
[Obsolete ("Use 'CVPixelFormatKeys.BlackBlock' instead.")]
[EditorBrowsable (EditorBrowsableState.Never)]
public static readonly NSString BlackBlockKey;
/// <summary>To be added.</summary>
/// <remarks>To be added.</remarks>
[Obsolete ("Use 'CVPixelFormatKeys.HorizontalSubsampling' instead.")]
[EditorBrowsable (EditorBrowsableState.Never)]
public static readonly NSString HorizontalSubsamplingKey;
/// <summary>To be added.</summary>
/// <remarks>To be added.</remarks>
[Obsolete ("Use 'CVPixelFormatKeys.VerticalSubsampling' instead.")]
[EditorBrowsable (EditorBrowsableState.Never)]
public static readonly NSString VerticalSubsamplingKey;
/// <summary>To be added.</summary>
/// <remarks>To be added.</remarks>
[Obsolete ("Use 'CVPixelFormatKeys.OpenGLFormat' instead.")]
[EditorBrowsable (EditorBrowsableState.Never)]
public static readonly NSString OpenGLFormatKey;
/// <summary>To be added.</summary>
/// <remarks>To be added.</remarks>
[Obsolete ("Use 'CVPixelFormatKeys.OpenGLType' instead.")]
[EditorBrowsable (EditorBrowsableState.Never)]
public static readonly NSString OpenGLTypeKey;
/// <summary>To be added.</summary>
/// <remarks>To be added.</remarks>
[Obsolete ("Use 'CVPixelFormatKeys.OpenGLInternalFormat' instead.")]
[EditorBrowsable (EditorBrowsableState.Never)]
public static readonly NSString OpenGLInternalFormatKey;
/// <summary>To be added.</summary>
/// <remarks>To be added.</remarks>
[Obsolete ("Use 'CVPixelFormatKeys.CGBitmapInfo' instead.")]
[EditorBrowsable (EditorBrowsableState.Never)]
public static readonly NSString CGBitmapInfoKey;
/// <summary>To be added.</summary>
/// <remarks>To be added.</remarks>
[Obsolete ("Use 'CVPixelFormatKeys.QDCompatibility' instead.")]
[EditorBrowsable (EditorBrowsableState.Never)]
public static readonly NSString QDCompatibilityKey;
/// <summary>To be added.</summary>
/// <remarks>To be added.</remarks>
[Obsolete ("Use 'CVPixelFormatKeys.CGBitmapContextCompatibility' instead.")]
[EditorBrowsable (EditorBrowsableState.Never)]
public static readonly NSString CGBitmapContextCompatibilityKey;
/// <summary>To be added.</summary>
/// <remarks>To be added.</remarks>
[Obsolete ("Use 'CVPixelFormatKeys.CGImageCompatibility' instead.")]
[EditorBrowsable (EditorBrowsableState.Never)]
public static readonly NSString CGImageCompatibilityKey;
/// <summary>To be added.</summary>
/// <remarks>To be added.</remarks>
[Obsolete ("Use 'CVPixelFormatKeys.OpenGLCompatibility' instead.")]
[EditorBrowsable (EditorBrowsableState.Never)]
public static readonly NSString OpenGLCompatibilityKey;
/// <summary>To be added.</summary>
/// <remarks>To be added.</remarks>
[Obsolete ("Use 'CVPixelFormatKeys.FillExtendedPixelsCallback' instead.")]
[EditorBrowsable (EditorBrowsableState.Never)]
public static readonly NSString FillExtendedPixelsCallbackKey;
/// <summary>To be added.</summary>
/// <remarks>To be added.</remarks>
[Obsolete ("Use 'CVPixelFormatKeys.ContainsRgb' instead.")]
[EditorBrowsable (EditorBrowsableState.Never)]
public static readonly NSString ContainsRgb;
/// <summary>To be added.</summary>
/// <remarks>To be added.</remarks>
[Obsolete ("Use 'CVPixelFormatKeys.ContainsYCbCr' instead.")]
[EditorBrowsable (EditorBrowsableState.Never)]
public static readonly NSString ContainsYCbCr;
/// <summary>To be added.</summary>
/// <remarks>To be added.</remarks>
[Obsolete ("Use 'CVPixelFormatKeys.ComponentRange' instead.")]
[EditorBrowsable (EditorBrowsableState.Never)]
public static readonly NSString ComponentRangeKey;
/// <summary>To be added.</summary>
/// <remarks>To be added.</remarks>
[Obsolete ("Use 'CVPixelFormatComponentRangeKeys.FullRange' instead.")]
[EditorBrowsable (EditorBrowsableState.Never)]
public static readonly NSString ComponentRangeFullRangeKey;
/// <summary>To be added.</summary>
/// <remarks>To be added.</remarks>
[Obsolete ("Use 'CVPixelFormatComponentRangeKeys.VideoRange' instead.")]
[EditorBrowsable (EditorBrowsableState.Never)]
public static readonly NSString ComponentRangeVideoRangeKey;
/// <summary>To be added.</summary>
/// <remarks>To be added.</remarks>
[Obsolete ("Use 'CVPixelFormatComponentRangeKeys.WideRange' instead.")]
[EditorBrowsable (EditorBrowsableState.Never)]
public static readonly NSString ComponentRangeWideRangeKey;
/// <summary>To be added.</summary>
/// <remarks>To be added.</remarks>
[Obsolete ("Use 'CVPixelFormatKeys.ContainsGrayscale' instead.")]
[EditorBrowsable (EditorBrowsableState.Never)]
[SupportedOSPlatform ("ios")]
[SupportedOSPlatform ("tvos")]
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("maccatalyst")]
public static readonly NSString ContainsGrayscaleKey;
[Obsolete ("Use 'CVPixelFormatKeys.ContainsSenselArray' instead.")]
[EditorBrowsable (EditorBrowsableState.Never)]
[SupportedOSPlatform ("ios16.0")]
[SupportedOSPlatform ("maccatalyst16.0")]
[SupportedOSPlatform ("macos13.0")]
[SupportedOSPlatform ("tvos16.0")]
public static readonly NSString ContainsSenselArray;
#endif // !XAMCORE_5_0
#if !XAMCORE_5_0
static CVPixelFormatDescription ()
{
NameKey = CVPixelFormatKeys.Name;
ConstantKey = CVPixelFormatKeys.Constant;
CodecTypeKey = CVPixelFormatKeys.CodecType;
FourCCKey = CVPixelFormatKeys.FourCC;
PlanesKey = CVPixelFormatKeys.Planes;
BlockWidthKey = CVPixelFormatKeys.BlockWidth;
BlockHeightKey = CVPixelFormatKeys.BlockHeight;
BitsPerBlockKey = CVPixelFormatKeys.BitsPerBlock;
BlockHorizontalAlignmentKey = CVPixelFormatKeys.BlockHorizontalAlignment;
BlockVerticalAlignmentKey = CVPixelFormatKeys.BlockVerticalAlignment;
BlackBlockKey = CVPixelFormatKeys.BlackBlock;
HorizontalSubsamplingKey = CVPixelFormatKeys.HorizontalSubsampling;
VerticalSubsamplingKey = CVPixelFormatKeys.VerticalSubsampling;
OpenGLFormatKey = CVPixelFormatKeys.OpenGLFormat;
OpenGLTypeKey = CVPixelFormatKeys.OpenGLType;
OpenGLInternalFormatKey = CVPixelFormatKeys.OpenGLInternalFormat;
CGBitmapInfoKey = CVPixelFormatKeys.CGBitmapInfo;
QDCompatibilityKey = CVPixelFormatKeys.QDCompatibility;
CGBitmapContextCompatibilityKey = CVPixelFormatKeys.CGBitmapContextCompatibility;
CGImageCompatibilityKey = CVPixelFormatKeys.CGImageCompatibility;
OpenGLCompatibilityKey = CVPixelFormatKeys.OpenGLCompatibility;
FillExtendedPixelsCallbackKey = CVPixelFormatKeys.FillExtendedPixelsCallback;
//iOS8 only
ContainsRgb = CVPixelFormatKeys.ContainsRgb;
ContainsYCbCr = CVPixelFormatKeys.ContainsYCbCr;
//iOS9 only
ComponentRangeKey = CVPixelFormatKeys.ComponentRange;
ComponentRangeFullRangeKey = CVPixelFormatComponentRangeKeys.FullRange;
ComponentRangeVideoRangeKey = CVPixelFormatComponentRangeKeys.VideoRange;
ComponentRangeWideRangeKey = CVPixelFormatComponentRangeKeys.WideRange;
// Xcode 10
ContainsGrayscaleKey = CVPixelFormatKeys.ContainsGrayscale;
// Xcode 14
#pragma warning disable CA1416 // This call site is reachable on: 'ios' 12.2 and later, 'maccatalyst' 12.2 and later, 'macOS/OSX' 12.0 and later, 'tvos' 12.2 and later. 'CVPixelFormatKeys.ContainsSenselArray.get' is only supported on: 'ios' 16.0 and later, 'maccatalyst' 16.0 and later, 'macOS/OSX' 13.0 and later, 'tvos' 16.0 and later.
ContainsSenselArray = CVPixelFormatKeys.ContainsSenselArray;
#pragma warning restore CA1416
}
#endif
// note: bad documentation, ref: https://bugzilla.xamarin.com/show_bug.cgi?id=13917
[DllImport (Constants.CoreVideoLibrary)]
extern static/* CFArrayRef __nullable */ IntPtr CVPixelFormatDescriptionArrayCreateWithAllPixelFormatTypes (
/* CFAllocatorRef __nullable */ IntPtr allocator);
/// <summary>Get all the known pixel format types.</summary>
public static NSNumber [] AllTypes {
get {
return NSArray.NonNullArrayFromHandleDropNullElements<NSNumber> (CVPixelFormatDescriptionArrayCreateWithAllPixelFormatTypes (IntPtr.Zero), releaseHandle: true);
}
}
/// <summary>Get all the known pixel format types.</summary>
public static CVPixelFormatType [] AllPixelFormatTypes {
get {
var all = AllTypes;
var rv = new CVPixelFormatType [all.Length];
for (var i = 0; i < rv.Length; i++)
rv [i] = (CVPixelFormatType) all [i].Int32Value;
return rv;
}
}
[DllImport (Constants.CoreVideoLibrary)]
extern static /* CFDictionaryRef __nullable */ IntPtr CVPixelFormatDescriptionCreateWithPixelFormatType (
/* CFAllocatorRef __nullable */ IntPtr allocator, int /* OSType = int32_t */ pixelFormat);
/// <summary>Create a description of the specified pixel format.</summary>
/// <param name="pixelFormat">The pixel format to create a description of.</param>
public static NSDictionary? Create (CVPixelFormatType pixelFormat)
{
return Runtime.GetNSObject<NSDictionary> (CVPixelFormatDescriptionCreateWithPixelFormatType (IntPtr.Zero, (int) pixelFormat), true);
}
/// <summary>Create a description of the specified pixel format.</summary>
/// <param name="pixelFormat">The pixel format to create a description of.</param>
public static CVPixelFormatDescription? CreatePixelFormat (CVPixelFormatType pixelFormat)
{
var dict = Create (pixelFormat);
if (dict is null)
return null;
return new CVPixelFormatDescription (dict);
}
[DllImport (Constants.CoreVideoLibrary)]
extern static void CVPixelFormatDescriptionRegisterDescriptionWithPixelFormatType (
/* CFDictionaryRef __nonnull */ IntPtr description, int /* OSType = int32_t */ pixelFormat);
/// <summary>Register a new pixel format with CoreVideo.</summary>
/// <param name="description">The pixel format description for the pixel format to register.</param>
/// <param name="pixelFormat">The pixel format to register.</param>
public static void Register (NSDictionary description, CVPixelFormatType pixelFormat)
{
if (description is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (description));
CVPixelFormatDescriptionRegisterDescriptionWithPixelFormatType (description.Handle, (int) pixelFormat);
GC.KeepAlive (description);
}
/// <summary>Register a new pixel format with CoreVideo.</summary>
/// <param name="description">The pixel format description for the pixel format to register.</param>
/// <param name="pixelFormat">The pixel format to register.</param>
public static void Register (CVPixelFormatDescription description, CVPixelFormatType pixelFormat)
{
Register (description?.Dictionary!, pixelFormat);
}
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("tvos15.0")]
[SupportedOSPlatform ("ios15.0")]
[SupportedOSPlatform ("maccatalyst")]
[DllImport (Constants.CoreVideoLibrary)]
extern static byte CVIsCompressedPixelFormatAvailable (int /* OSType = int32_t */ pixelFormat);
/// <summary>Check if the specified pixel format is supported on this platform.</summary>
/// <param name="pixelFormat">The pixel format to check.</param>
/// <returns>Whether the specified pixel format is supported or not.</returns>
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("tvos15.0")]
[SupportedOSPlatform ("ios15.0")]
[SupportedOSPlatform ("maccatalyst")]
public static bool IsPixelFormatAvailable (CVPixelFormatType pixelFormat)
{
return CVIsCompressedPixelFormatAvailable ((int) pixelFormat) != 0;
}
[SupportedOSPlatform ("ios")]
[SupportedOSPlatform ("maccatalyst")]
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("tvos")]
public CVFillExtendedPixelsCallBackDataStruct? FillExtendedPixelsCallbackStruct {
get {
var data = FillExtendedPixelsCallback;
if (data is null)
return null;
var bytes = data.ToArray ();
unsafe {
if (bytes.Length < sizeof (CVFillExtendedPixelsCallBackDataStruct))
throw new InvalidOperationException ($"The size of the callback data structure is smaller than expected (got {bytes.Length} bytes, expected at least {sizeof (CVFillExtendedPixelsCallBackDataStruct)} bytes)");
fixed (byte* ptr = bytes)
return Marshal.PtrToStructure<CVFillExtendedPixelsCallBackDataStruct> ((IntPtr) ptr);
}
}
set {
if (value is null) {
FillExtendedPixelsCallback = null;
return;
}
NSData data;
CVFillExtendedPixelsCallBackDataStruct v = value.Value;
unsafe {
data = NSData.FromBytes ((IntPtr) (&v), (nuint) sizeof (CVFillExtendedPixelsCallBackDataStruct));
}
FillExtendedPixelsCallback = data;
}
}
#if !XAMCORE_5_0
[Obsolete ("Use 'ComponentRangeValue' instead, the property type is incorrect for this property.")]
[EditorBrowsable (EditorBrowsableState.Never)]
public CVPixelFormatComponentRange? ComponentRange {
get => null;
set { }
}
#endif // !XAMCORE_5_0
#endif // !COREBUILD
}
}