Repository navigation
Expand file tree
/
Copy pathffigen.dart
More file actions
123 lines (120 loc) · 3.63 KB
/
Copy pathffigen.dart
File metadata and controls
123 lines (120 loc) · 3.63 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
// Regenerate bindings with `dart run ffigen.dart`.
import 'package:ffigen/ffigen.dart';
/// Local definitions for the Apple "common" types (CFString, CGRect, ...) that
/// ffigen's built-in type table would otherwise source from package:objective_c.
const _appleTypes = LibraryImport(
'appleCf',
'package:platform_image_converter/src/darwin/apple_cf_types.dart',
);
final config = FfiGenerator(
headers: Headers(
entryPoints: [
Uri.file(
'$macSdkPath/System/Library/Frameworks/ImageIO.framework/Headers/ImageIO.h',
),
],
// Generate for C only (no objective_c interop). Pass the framework search
// path and sysroot that ObjC mode would otherwise supply so the framework
// umbrella headers resolve.
compilerOptions: [
'-isysroot',
macSdkPath,
'-F',
'$macSdkPath/System/Library/Frameworks',
],
),
output: Output(dartFile: Uri.file('lib/src/darwin/bindings.g.dart')),
// Override ffigen's built-in objective_c mapping for the Apple common types,
// pointing them at local definitions so the bindings carry no objective_c dep.
// ignore: deprecated_member_use
libraryImports: const [_appleTypes],
// ignore: deprecated_member_use
importedTypesByUsr: {
'c:@S@__CFString': ImportedType(
_appleTypes,
'CFString',
'CFString',
'__CFString',
importedDartType: true,
),
'c:@S@CGRect': ImportedType(
_appleTypes,
'CGRect',
'CGRect',
'CGRect',
importedDartType: true,
),
'c:@S@CGAffineTransform': ImportedType(
_appleTypes,
'CGAffineTransform',
'CGAffineTransform',
'CGAffineTransform',
importedDartType: true,
),
},
functions: Functions.includeSet({
// CFData operations
'CFDataCreate',
'CFDataCreateMutable',
'CFDataGetBytePtr',
'CFDataGetLength',
// CFDictionary operations
'CFDictionaryCreate',
'CFDictionaryGetValue',
// CFString / CFNumber value creation (replaces objective_c NSString/NSNumber)
'CFStringCreateWithCString',
'CFNumberCreate',
'CFNumberGetValue',
// CGImageSource operations (decoding)
'CGImageSourceCreateWithData',
'CGImageSourceCreateImageAtIndex',
// EXIF orientation lookup from the source's properties
'CGImageSourceCopyPropertiesAtIndex',
// CGImageDestination operations (encoding)
'CGImageDestinationCreateWithData',
'CGImageDestinationAddImage',
'CGImageDestinationFinalize',
// CGImage operations
'CGImageGetWidth',
'CGImageGetHeight',
// CGColorSpace operations
'CGColorSpaceCreateWithName',
// CGContext operations
'CGContextDrawImage',
'CGContextSetInterpolationQuality',
'CGContextConcatCTM',
// CGBitmapContext operations
'CGBitmapContextCreateImage',
'CGBitmapContextCreate',
// Memory management
'CFRelease',
}),
globals: Globals.includeSet({
'kCFAllocatorDefault',
'kCGImageDestinationLossyCompressionQuality',
'kCGColorSpaceSRGB',
'kCGImagePropertyOrientation',
}),
// The CF/CG enum constants used are surfaced as top-level `const int`s via
// unnamedEnums (their named enums are not emitted as Dart enums in C mode).
unnamedEnums: UnnamedEnums.includeSet({
'kCFStringEncodingUTF8',
'kCFNumberFloat64Type',
'kCFNumberIntType',
'kCGImageAlphaPremultipliedLast',
'kCGInterpolationHigh',
}),
typedefs: Typedefs.includeSet({
'CFDataRef',
'CFDictionaryRef',
'CGContextRef',
'CGImageRef',
'CGImageSourceRef',
'CGColorSpaceRef',
'CFMutableDataRef',
'CGImageDestinationRef',
'CFStringRef',
'CFNumberRef',
}),
);
void main() => config.generate();