@succinctlabs/react-native-zcam1 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/README.md +61 -0
  2. package/Zcam1Sdk.podspec +157 -0
  3. package/app.plugin.js +11 -0
  4. package/cpp/generated/zcam1_c2pa_utils.cpp +4091 -0
  5. package/cpp/generated/zcam1_c2pa_utils.hpp +367 -0
  6. package/cpp/generated/zcam1_certs_utils.cpp +1799 -0
  7. package/cpp/generated/zcam1_certs_utils.hpp +72 -0
  8. package/cpp/generated/zcam1_verify_utils.cpp +1857 -0
  9. package/cpp/generated/zcam1_verify_utils.hpp +79 -0
  10. package/cpp/proving/generated/zcam1_proving_utils.cpp +3661 -0
  11. package/cpp/proving/generated/zcam1_proving_utils.hpp +275 -0
  12. package/cpp/proving/zcam1-proving.cpp +16 -0
  13. package/cpp/proving/zcam1-proving.h +15 -0
  14. package/cpp/zcam1-sdk.cpp +20 -0
  15. package/cpp/zcam1-sdk.h +15 -0
  16. package/ios/Zcam1Camera.swift +2945 -0
  17. package/ios/Zcam1CameraFilmStyle.swift +191 -0
  18. package/ios/Zcam1CameraViewManager.m +86 -0
  19. package/ios/Zcam1Capture.h +13 -0
  20. package/ios/Zcam1Capture.mm +500 -0
  21. package/ios/Zcam1DepthData.swift +417 -0
  22. package/ios/Zcam1Sdk.h +16 -0
  23. package/ios/Zcam1Sdk.mm +66 -0
  24. package/ios/proving/Zcam1Proving.h +16 -0
  25. package/ios/proving/Zcam1Proving.mm +66 -0
  26. package/lib/module/NativeZcam1Capture.js +12 -0
  27. package/lib/module/NativeZcam1Capture.js.map +1 -0
  28. package/lib/module/NativeZcam1Sdk.js +7 -0
  29. package/lib/module/NativeZcam1Sdk.js.map +1 -0
  30. package/lib/module/bindings.js +51 -0
  31. package/lib/module/bindings.js.map +1 -0
  32. package/lib/module/camera.js +522 -0
  33. package/lib/module/camera.js.map +1 -0
  34. package/lib/module/capture.js +120 -0
  35. package/lib/module/capture.js.map +1 -0
  36. package/lib/module/common.js +35 -0
  37. package/lib/module/common.js.map +1 -0
  38. package/lib/module/generated/zcam1_c2pa_utils-ffi.js +43 -0
  39. package/lib/module/generated/zcam1_c2pa_utils-ffi.js.map +1 -0
  40. package/lib/module/generated/zcam1_c2pa_utils.js +1202 -0
  41. package/lib/module/generated/zcam1_c2pa_utils.js.map +1 -0
  42. package/lib/module/generated/zcam1_certs_utils-ffi.js +43 -0
  43. package/lib/module/generated/zcam1_certs_utils-ffi.js.map +1 -0
  44. package/lib/module/generated/zcam1_certs_utils.js +399 -0
  45. package/lib/module/generated/zcam1_certs_utils.js.map +1 -0
  46. package/lib/module/generated/zcam1_proving_utils-ffi.js +43 -0
  47. package/lib/module/generated/zcam1_proving_utils-ffi.js.map +1 -0
  48. package/lib/module/generated/zcam1_proving_utils.js +515 -0
  49. package/lib/module/generated/zcam1_proving_utils.js.map +1 -0
  50. package/lib/module/generated/zcam1_verify_utils-ffi.js +43 -0
  51. package/lib/module/generated/zcam1_verify_utils-ffi.js.map +1 -0
  52. package/lib/module/generated/zcam1_verify_utils.js +252 -0
  53. package/lib/module/generated/zcam1_verify_utils.js.map +1 -0
  54. package/lib/module/index.js +31 -0
  55. package/lib/module/index.js.map +1 -0
  56. package/lib/module/package.json +1 -0
  57. package/lib/module/picker.js +222 -0
  58. package/lib/module/picker.js.map +1 -0
  59. package/lib/module/proving/NativeZcam1Proving.js +7 -0
  60. package/lib/module/proving/NativeZcam1Proving.js.map +1 -0
  61. package/lib/module/proving/bindings.js +46 -0
  62. package/lib/module/proving/bindings.js.map +1 -0
  63. package/lib/module/proving/index.js +5 -0
  64. package/lib/module/proving/index.js.map +1 -0
  65. package/lib/module/proving/prove.js +346 -0
  66. package/lib/module/proving/prove.js.map +1 -0
  67. package/lib/module/utils.js +27 -0
  68. package/lib/module/utils.js.map +1 -0
  69. package/lib/module/verify.js +82 -0
  70. package/lib/module/verify.js.map +1 -0
  71. package/lib/typescript/package.json +1 -0
  72. package/lib/typescript/src/NativeZcam1Capture.d.ts +280 -0
  73. package/lib/typescript/src/NativeZcam1Capture.d.ts.map +1 -0
  74. package/lib/typescript/src/NativeZcam1Sdk.d.ts +8 -0
  75. package/lib/typescript/src/NativeZcam1Sdk.d.ts.map +1 -0
  76. package/lib/typescript/src/bindings.d.ts +14 -0
  77. package/lib/typescript/src/bindings.d.ts.map +1 -0
  78. package/lib/typescript/src/camera.d.ts +300 -0
  79. package/lib/typescript/src/camera.d.ts.map +1 -0
  80. package/lib/typescript/src/capture.d.ts +59 -0
  81. package/lib/typescript/src/capture.d.ts.map +1 -0
  82. package/lib/typescript/src/common.d.ts +10 -0
  83. package/lib/typescript/src/common.d.ts.map +1 -0
  84. package/lib/typescript/src/generated/zcam1_c2pa_utils-ffi.d.ts +175 -0
  85. package/lib/typescript/src/generated/zcam1_c2pa_utils-ffi.d.ts.map +1 -0
  86. package/lib/typescript/src/generated/zcam1_c2pa_utils.d.ts +811 -0
  87. package/lib/typescript/src/generated/zcam1_c2pa_utils.d.ts.map +1 -0
  88. package/lib/typescript/src/generated/zcam1_certs_utils-ffi.d.ts +82 -0
  89. package/lib/typescript/src/generated/zcam1_certs_utils-ffi.d.ts.map +1 -0
  90. package/lib/typescript/src/generated/zcam1_certs_utils.d.ts +413 -0
  91. package/lib/typescript/src/generated/zcam1_certs_utils.d.ts.map +1 -0
  92. package/lib/typescript/src/generated/zcam1_proving_utils-ffi.d.ts +153 -0
  93. package/lib/typescript/src/generated/zcam1_proving_utils-ffi.d.ts.map +1 -0
  94. package/lib/typescript/src/generated/zcam1_proving_utils.d.ts +321 -0
  95. package/lib/typescript/src/generated/zcam1_proving_utils.d.ts.map +1 -0
  96. package/lib/typescript/src/generated/zcam1_verify_utils-ffi.d.ts +84 -0
  97. package/lib/typescript/src/generated/zcam1_verify_utils-ffi.d.ts.map +1 -0
  98. package/lib/typescript/src/generated/zcam1_verify_utils.d.ts +286 -0
  99. package/lib/typescript/src/generated/zcam1_verify_utils.d.ts.map +1 -0
  100. package/lib/typescript/src/index.d.ts +29 -0
  101. package/lib/typescript/src/index.d.ts.map +1 -0
  102. package/lib/typescript/src/picker.d.ts +103 -0
  103. package/lib/typescript/src/picker.d.ts.map +1 -0
  104. package/lib/typescript/src/proving/NativeZcam1Proving.d.ts +8 -0
  105. package/lib/typescript/src/proving/NativeZcam1Proving.d.ts.map +1 -0
  106. package/lib/typescript/src/proving/bindings.d.ts +8 -0
  107. package/lib/typescript/src/proving/bindings.d.ts.map +1 -0
  108. package/lib/typescript/src/proving/index.d.ts +3 -0
  109. package/lib/typescript/src/proving/index.d.ts.map +1 -0
  110. package/lib/typescript/src/proving/prove.d.ts +74 -0
  111. package/lib/typescript/src/proving/prove.d.ts.map +1 -0
  112. package/lib/typescript/src/utils.d.ts +2 -0
  113. package/lib/typescript/src/utils.d.ts.map +1 -0
  114. package/lib/typescript/src/verify.d.ts +45 -0
  115. package/lib/typescript/src/verify.d.ts.map +1 -0
  116. package/package.json +118 -0
  117. package/src/NativeZcam1Capture.ts +335 -0
  118. package/src/NativeZcam1Sdk.ts +10 -0
  119. package/src/bindings.tsx +49 -0
  120. package/src/camera.tsx +705 -0
  121. package/src/capture.tsx +165 -0
  122. package/src/common.tsx +46 -0
  123. package/src/generated/zcam1_c2pa_utils-ffi.ts +456 -0
  124. package/src/generated/zcam1_c2pa_utils.ts +1866 -0
  125. package/src/generated/zcam1_certs_utils-ffi.ts +187 -0
  126. package/src/generated/zcam1_certs_utils.ts +549 -0
  127. package/src/generated/zcam1_proving_utils-ffi.ts +374 -0
  128. package/src/generated/zcam1_proving_utils.ts +804 -0
  129. package/src/generated/zcam1_verify_utils-ffi.ts +196 -0
  130. package/src/generated/zcam1_verify_utils.ts +372 -0
  131. package/src/index.ts +73 -0
  132. package/src/picker.tsx +342 -0
  133. package/src/proving/NativeZcam1Proving.ts +10 -0
  134. package/src/proving/bindings.tsx +50 -0
  135. package/src/proving/index.ts +8 -0
  136. package/src/proving/prove.tsx +492 -0
  137. package/src/utils.ts +38 -0
  138. package/src/verify.tsx +119 -0
  139. package/turbo.json +27 -0
@@ -0,0 +1,191 @@
1
+ //
2
+ // Zcam1CameraFilmStyle.swift
3
+ // react-native-zcam1-sdk
4
+ //
5
+ // Camera film style presets using Harbeth for real-time preview and capture.
6
+ //
7
+
8
+ import Harbeth
9
+ import UIKit
10
+
11
+ /// Camera film style presets.
12
+ public enum Zcam1CameraFilmStyle: String, CaseIterable {
13
+ case normal
14
+ case mellow
15
+ case bw
16
+ case nostalgic
17
+
18
+ /// Initialize from a string (case-insensitive).
19
+ init(from string: String?) {
20
+ switch string?.lowercased() {
21
+ case "mellow":
22
+ self = .mellow
23
+ case "bw":
24
+ self = .bw
25
+ case "nostalgic":
26
+ self = .nostalgic
27
+ default:
28
+ self = .normal
29
+ }
30
+ }
31
+
32
+ // MARK: - Custom Film Style Recipe Parser
33
+
34
+ /// Parse a film style recipe from JavaScript into Harbeth effects.
35
+ /// Each effect dictionary should have a "type" key and either a "value" or "config" key.
36
+ static func createFilmStyles(from recipe: [[String: Any]]) -> [C7FilterProtocol] {
37
+ var filmStyles: [C7FilterProtocol] = []
38
+
39
+ for effect in recipe {
40
+ guard let type = effect["type"] as? String else { continue }
41
+
42
+ switch type {
43
+ case "whiteBalance":
44
+ if let config = effect["config"] as? [String: Any],
45
+ let temp = config["temperature"] as? Float {
46
+ let tint = config["tint"] as? Float ?? 0
47
+ filmStyles.append(C7WhiteBalance(temperature: temp, tint: tint))
48
+ }
49
+ case "saturation":
50
+ if let value = effect["value"] as? Float {
51
+ filmStyles.append(C7Saturation(saturation: value))
52
+ }
53
+ case "contrast":
54
+ if let value = effect["value"] as? Float {
55
+ filmStyles.append(C7Contrast(contrast: value))
56
+ }
57
+ case "brightness":
58
+ if let value = effect["value"] as? Float {
59
+ filmStyles.append(C7Brightness(brightness: value))
60
+ }
61
+ case "hue":
62
+ if let value = effect["value"] as? Float {
63
+ filmStyles.append(C7Hue(hue: value))
64
+ }
65
+ case "vibrance":
66
+ if let value = effect["value"] as? Float {
67
+ filmStyles.append(C7Vibrance(vibrance: value))
68
+ }
69
+ case "highlightShadow":
70
+ if let config = effect["config"] as? [String: Any],
71
+ let highlights = config["highlights"] as? Float,
72
+ let shadows = config["shadows"] as? Float {
73
+ filmStyles.append(C7HighlightShadow(highlights: highlights, shadows: shadows))
74
+ }
75
+ case "monochrome":
76
+ if let config = effect["config"] as? [String: Any],
77
+ let intensity = config["intensity"] as? Float {
78
+ var color = C7Color.zero
79
+ if let colorConfig = config["color"] as? [String: Any],
80
+ let r = colorConfig["r"] as? CGFloat,
81
+ let g = colorConfig["g"] as? CGFloat,
82
+ let b = colorConfig["b"] as? CGFloat {
83
+ color = C7Color(red: r, green: g, blue: b, alpha: 1.0)
84
+ }
85
+ filmStyles.append(C7Monochrome(intensity: intensity, color: color))
86
+ }
87
+ default:
88
+ print("[Zcam1CameraFilmStyle] Unknown effect type: \(type)")
89
+ }
90
+ }
91
+
92
+ return filmStyles
93
+ }
94
+
95
+ /// Apply an array of film style effects to a UIImage.
96
+ static func apply(filmStyles: [C7FilterProtocol], to image: UIImage) -> UIImage {
97
+ guard !filmStyles.isEmpty else {
98
+ return image
99
+ }
100
+
101
+ var result = image
102
+ for effect in filmStyles {
103
+ do {
104
+ result = try result.make(filter: effect)
105
+ } catch {
106
+ print("[Zcam1CameraFilmStyle] Failed to apply film style effect: \(error)")
107
+ }
108
+ }
109
+ return result
110
+ }
111
+
112
+ // MARK: - Pixel Buffer Filtering for Video Recording
113
+
114
+ /// Shared CIContext for efficient pixel buffer rendering.
115
+ private static let ciContext: CIContext = {
116
+ // Use Metal for GPU-accelerated rendering.
117
+ if let device = MTLCreateSystemDefaultDevice() {
118
+ return CIContext(mtlDevice: device, options: [.cacheIntermediates: false])
119
+ }
120
+ return CIContext(options: [.useSoftwareRenderer: false])
121
+ }()
122
+
123
+ /// Apply an array of film style effects to a CVPixelBuffer.
124
+ /// Returns a new filtered pixel buffer, or nil if filtering fails.
125
+ /// Used for applying film styles to video frames during recording.
126
+ static func apply(
127
+ filmStyles: [C7FilterProtocol],
128
+ to pixelBuffer: CVPixelBuffer,
129
+ orientation: UIImage.Orientation
130
+ ) -> CVPixelBuffer? {
131
+ guard !filmStyles.isEmpty else {
132
+ return nil
133
+ }
134
+
135
+ // Convert pixel buffer to CIImage.
136
+ let ciImage = CIImage(cvPixelBuffer: pixelBuffer)
137
+
138
+ // Create CGImage from CIImage.
139
+ guard let cgImage = ciContext.createCGImage(ciImage, from: ciImage.extent) else {
140
+ print("[Zcam1CameraFilmStyle] Failed to create CGImage from pixel buffer")
141
+ return nil
142
+ }
143
+
144
+ // Create UIImage with correct orientation and apply filters.
145
+ var image = UIImage(cgImage: cgImage, scale: 1.0, orientation: orientation)
146
+ for effect in filmStyles {
147
+ do {
148
+ image = try image.make(filter: effect)
149
+ } catch {
150
+ print("[Zcam1CameraFilmStyle] Failed to apply film style effect: \(error)")
151
+ }
152
+ }
153
+
154
+ // Convert filtered UIImage back to pixel buffer.
155
+ guard let filteredCGImage = image.cgImage else {
156
+ print("[Zcam1CameraFilmStyle] Failed to get CGImage from filtered UIImage")
157
+ return nil
158
+ }
159
+
160
+ // Create a new pixel buffer with the same dimensions as the original.
161
+ let width = CVPixelBufferGetWidth(pixelBuffer)
162
+ let height = CVPixelBufferGetHeight(pixelBuffer)
163
+
164
+ var newPixelBuffer: CVPixelBuffer?
165
+ let attributes: [String: Any] = [
166
+ kCVPixelBufferCGImageCompatibilityKey as String: true,
167
+ kCVPixelBufferCGBitmapContextCompatibilityKey as String: true,
168
+ kCVPixelBufferIOSurfacePropertiesKey as String: [:],
169
+ ]
170
+
171
+ let status = CVPixelBufferCreate(
172
+ kCFAllocatorDefault,
173
+ width,
174
+ height,
175
+ kCVPixelFormatType_32BGRA,
176
+ attributes as CFDictionary,
177
+ &newPixelBuffer
178
+ )
179
+
180
+ guard status == kCVReturnSuccess, let outputBuffer = newPixelBuffer else {
181
+ print("[Zcam1CameraFilmStyle] Failed to create output pixel buffer: \(status)")
182
+ return nil
183
+ }
184
+
185
+ // Render the filtered CIImage to the new pixel buffer.
186
+ let filteredCIImage = CIImage(cgImage: filteredCGImage)
187
+ ciContext.render(filteredCIImage, to: outputBuffer)
188
+
189
+ return outputBuffer
190
+ }
191
+ }
@@ -0,0 +1,86 @@
1
+ #import <React/RCTViewManager.h>
2
+ #import <React/RCTConvert.h>
3
+ #import <UIKit/UIKit.h>
4
+ #import <AVFoundation/AVFoundation.h>
5
+
6
+ #if __has_include("Zcam1Sdk-Swift.h")
7
+ #import "Zcam1Sdk-Swift.h"
8
+ #endif
9
+
10
+ @interface Zcam1CameraViewManager : RCTViewManager
11
+ @end
12
+
13
+ @implementation Zcam1CameraViewManager
14
+
15
+ // Expose this view to JS as "Zcam1CameraView", matching the
16
+ // name used in `requireNativeComponent("Zcam1CameraView")`.
17
+ RCT_EXPORT_MODULE(Zcam1CameraView);
18
+
19
+ - (UIView *)view
20
+ {
21
+ #if __has_include("Zcam1Sdk-Swift.h")
22
+ if (@available(iOS 16.0, *)) {
23
+ // Zcam1CameraView is the Swift UIView subclass defined in Zcam1Camera.swift
24
+ return [Zcam1CameraView new];
25
+ }
26
+ #endif
27
+
28
+ // Fallback dummy view if the Swift implementation is not available
29
+ UIView *fallback = [UIView new];
30
+ fallback.backgroundColor = [UIColor blackColor];
31
+ return fallback;
32
+ }
33
+
34
+ + (BOOL)requiresMainQueueSetup
35
+ {
36
+ // Camera / UIKit objects must be created on the main thread
37
+ return YES;
38
+ }
39
+
40
+ // Props bridged to Swift Zcam1CameraView:
41
+ //
42
+ // @property (nonatomic) BOOL isActive;
43
+ // @property (nonatomic, copy) NSString *position; // "front" | "back"
44
+ // @property (nonatomic, copy) NSString *captureFormat; // "jpeg" | "dng"
45
+ // @property (nonatomic) CGFloat zoom; // 1.0 = no zoom
46
+ // @property (nonatomic) BOOL torch; // torch on/off
47
+ // @property (nonatomic) float exposure; // exposure bias in EV
48
+ // @property (nonatomic, copy) NSString *filmStyle; // "normal" | "mellow" | "bw" | "nostalgic" or custom name
49
+ // @property (nonatomic, copy) NSDictionary *filmStyleOverrides; // custom recipes for built-in presets
50
+ // @property (nonatomic, copy) NSDictionary *customFilmStyles; // additional custom film styles by name
51
+ // @property (nonatomic) BOOL depthEnabled; // enable depth data at session level (default: NO)
52
+ // @property (nonatomic, copy) RCTDirectEventBlock onOrientationChange; // orientation change callback
53
+ RCT_EXPORT_VIEW_PROPERTY(isActive, BOOL);
54
+ RCT_EXPORT_VIEW_PROPERTY(position, NSString);
55
+ RCT_EXPORT_VIEW_PROPERTY(captureFormat, NSString);
56
+ RCT_EXPORT_VIEW_PROPERTY(zoom, CGFloat);
57
+ RCT_EXPORT_VIEW_PROPERTY(torch, BOOL);
58
+ RCT_EXPORT_VIEW_PROPERTY(exposure, float);
59
+ RCT_EXPORT_VIEW_PROPERTY(depthEnabled, BOOL);
60
+ RCT_EXPORT_VIEW_PROPERTY(onOrientationChange, RCTDirectEventBlock);
61
+
62
+ // Use custom property setter to ensure the Swift setter is called properly.
63
+ RCT_CUSTOM_VIEW_PROPERTY(filmStyle, NSString, Zcam1CameraView)
64
+ {
65
+ NSString *filmStyleValue = json ? [RCTConvert NSString:json] : @"normal";
66
+ NSLog(@"[Zcam1CameraViewManager] Setting filmStyle to: %@", filmStyleValue);
67
+ view.filmStyle = filmStyleValue;
68
+ }
69
+
70
+ // Custom film style recipe overrides for built-in presets.
71
+ RCT_CUSTOM_VIEW_PROPERTY(filmStyleOverrides, NSDictionary, Zcam1CameraView)
72
+ {
73
+ NSDictionary *overrides = json ? [RCTConvert NSDictionary:json] : nil;
74
+ NSLog(@"[Zcam1CameraViewManager] Setting filmStyleOverrides: %@", overrides ? @"present" : @"nil");
75
+ view.filmStyleOverrides = overrides;
76
+ }
77
+
78
+ // Additional custom film styles defined by name.
79
+ RCT_CUSTOM_VIEW_PROPERTY(customFilmStyles, NSDictionary, Zcam1CameraView)
80
+ {
81
+ NSDictionary *custom = json ? [RCTConvert NSDictionary:json] : nil;
82
+ NSLog(@"[Zcam1CameraViewManager] Setting customFilmStyles: %@", custom ? @"present" : @"nil");
83
+ view.customFilmStyles = custom;
84
+ }
85
+
86
+ @end
@@ -0,0 +1,13 @@
1
+
2
+ #ifdef RCT_NEW_ARCH_ENABLED
3
+ #import <Zcam1SdkSpec/Zcam1SdkSpec.h>
4
+
5
+ @interface Zcam1Capture : NSObject <NativeZcam1CaptureSpec>
6
+
7
+ #else
8
+ #import <React/RCTBridgeModule.h>
9
+
10
+ @interface Zcam1Capture : NSObject <RCTBridgeModule>
11
+ #endif
12
+
13
+ @end