| 
									
										
										
										
											2021-05-06 14:11:55 +02:00
										 |  |  | //
 | 
					
						
							|  |  |  | //  FrameProcessorPlugin.h
 | 
					
						
							|  |  |  | //  VisionCamera
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //  Created by Marc Rousavy on 01.05.21.
 | 
					
						
							| 
									
										
										
										
											2021-06-01 13:07:57 +02:00
										 |  |  | //  Copyright © 2021 mrousavy. All rights reserved.
 | 
					
						
							| 
									
										
										
										
											2021-05-06 14:11:55 +02:00
										 |  |  | //
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-27 11:18:03 +01:00
										 |  |  | #pragma once
 | 
					
						
							| 
									
										
										
										
											2021-05-06 14:11:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-09 10:57:05 +02:00
										 |  |  | #import "Frame.h"
 | 
					
						
							| 
									
										
										
										
											2024-01-12 16:00:36 +01:00
										 |  |  | #import "VisionCameraProxy.h"
 | 
					
						
							| 
									
										
										
										
											2023-09-01 12:58:32 +02:00
										 |  |  | #import <Foundation/Foundation.h>
 | 
					
						
							| 
									
										
										
										
											2021-05-06 14:11:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-16 20:02:03 +01:00
										 |  |  | NS_ASSUME_NONNULL_BEGIN | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-19 11:19:47 +02:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * The base class of a native Frame Processor Plugin. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Subclass this to create a custom Frame Processor Plugin, which can be called from a JS Frame Processor. | 
					
						
							|  |  |  |  * Once subclassed, it needs to be registered in the VisionCamera Frame Processor runtime via | 
					
						
							|  |  |  |  * the `VISION_EXPORT_FRAME_PROCESSOR` or `VISION_EXPORT_SWIFT_FRAME_PROCESSOR` macros. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  * See: <a href="https://react-native-vision-camera.com/docs/guides/frame-processors-plugins-ios">Creating Frame Processor Plugins (iOS)</a> | 
					
						
							|  |  |  |  * for more information | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2023-02-27 11:18:03 +01:00
										 |  |  | @interface FrameProcessorPlugin : NSObject | 
					
						
							| 
									
										
										
										
											2021-05-06 14:11:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-19 11:19:47 +02:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * The initializer of this Frame Processor Plugin. | 
					
						
							|  |  |  |  * This is called everytime this Frame Processor Plugin is loaded from the JS side (`initFrameProcessorPlugin(..)`). | 
					
						
							|  |  |  |  * Optionally override this method to implement custom initialization logic. | 
					
						
							|  |  |  |  * - Parameters: | 
					
						
							| 
									
										
										
										
											2024-01-12 16:00:36 +01:00
										 |  |  |  *   - proxy: The VisionCameraProxy instance for using the Frame Processor Context, e.g. to initialize SharedArrays. | 
					
						
							| 
									
										
										
										
											2023-10-19 11:19:47 +02:00
										 |  |  |  *   - options: An options dictionary passed from the JS side, or `nil` if none. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2024-01-16 20:02:03 +01:00
										 |  |  | - (instancetype _Nonnull)initWithProxy:(VisionCameraProxyHolder*)proxy | 
					
						
							| 
									
										
										
										
											2024-01-12 16:00:36 +01:00
										 |  |  |                            withOptions:(NSDictionary* _Nullable)options NS_SWIFT_NAME(init(proxy:options:)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-12 16:13:56 +01:00
										 |  |  | - (instancetype _Nonnull)init NS_UNAVAILABLE; | 
					
						
							| 
									
										
										
										
											2023-10-19 10:35:14 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-19 11:19:47 +02:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * The actual Frame Processor Plugin's implementation that runs when `plugin.call(..)` is called in the JS Frame Processor. | 
					
						
							|  |  |  |  * Implement your Frame Processing here, and keep in mind that this is a hot-path so optimize as good as possible. | 
					
						
							|  |  |  |  * See: <a href="https://react-native-vision-camera.com/docs/guides/frame-processors-tips#fast-frame-processor-plugins">Performance Tips</a> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * - Parameters: | 
					
						
							|  |  |  |  *   - frame: The Frame from the Camera. Don't do any ref-counting on this, as VisionCamera handles that. | 
					
						
							| 
									
										
										
										
											2024-01-16 20:02:03 +01:00
										 |  |  |  *   - arguments: An options dictionary passed from the JS side, or `nil` if none. | 
					
						
							| 
									
										
										
										
											2023-10-19 11:19:47 +02:00
										 |  |  |  * - Returns: You can return any primitive, map or array you want. | 
					
						
							|  |  |  |  *            See the <a href="https://react-native-vision-camera.com/docs/guides/frame-processors-plugins-overview#types">Types</a> | 
					
						
							|  |  |  |  *            table for a list of supported types. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2024-01-16 20:02:03 +01:00
										 |  |  | - (id _Nullable)callback:(Frame*)frame withArguments:(NSDictionary* _Nullable)arguments; | 
					
						
							| 
									
										
										
										
											2023-07-21 17:52:30 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | @end | 
					
						
							| 
									
										
										
										
											2023-10-19 10:35:14 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-16 20:02:03 +01:00
										 |  |  | NS_ASSUME_NONNULL_END | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-19 10:35:14 +02:00
										 |  |  | #define VISION_CONCAT2(A, B) A##B
 | 
					
						
							|  |  |  | #define VISION_CONCAT(A, B) VISION_CONCAT2(A, B)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define VISION_EXPORT_FRAME_PROCESSOR(frame_processor_class, frame_processor_plugin_name)                                                  \
 | 
					
						
							|  |  |  |   +(void)load {                                                                                                                            \ | 
					
						
							| 
									
										
										
										
											2024-01-12 16:00:36 +01:00
										 |  |  |     [FrameProcessorPluginRegistry                                                                                                          \ | 
					
						
							|  |  |  |         addFrameProcessorPlugin:@ #frame_processor_plugin_name                                                                             \ | 
					
						
							|  |  |  |                 withInitializer:^FrameProcessorPlugin*(VisionCameraProxyHolder* _Nonnull proxy, NSDictionary* _Nullable options) {         \ | 
					
						
							|  |  |  |                   return [[frame_processor_class alloc] initWithProxy:proxy withOptions:options];                                          \ | 
					
						
							|  |  |  |                 }];                                                                                                                        \ | 
					
						
							| 
									
										
										
										
											2023-10-19 10:35:14 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define VISION_EXPORT_SWIFT_FRAME_PROCESSOR(frame_processor_class, frame_processor_plugin_name)                                            \
 | 
					
						
							|  |  |  |                                                                                                                                            \ | 
					
						
							|  |  |  |   @interface frame_processor_class (FrameProcessorPluginLoader)                                                                            \ | 
					
						
							|  |  |  |   @end                                                                                                                                     \ | 
					
						
							|  |  |  |                                                                                                                                            \ | 
					
						
							|  |  |  |   @implementation frame_processor_class (FrameProcessorPluginLoader)                                                                       \ | 
					
						
							|  |  |  |                                                                                                                                            \ | 
					
						
							|  |  |  |   __attribute__((constructor)) static void VISION_CONCAT(initialize_, frame_processor_plugin_name)(void) {                                 \ | 
					
						
							|  |  |  |     [FrameProcessorPluginRegistry addFrameProcessorPlugin:@ #frame_processor_plugin_name                                                   \ | 
					
						
							| 
									
										
										
										
											2024-01-12 16:00:36 +01:00
										 |  |  |                                           withInitializer:^FrameProcessorPlugin* _Nonnull(VisionCameraProxyHolder* _Nonnull proxy,         \ | 
					
						
							|  |  |  |                                                                                           NSDictionary* _Nullable options) {               \ | 
					
						
							|  |  |  |                                             return [[frame_processor_class alloc] initWithProxy:proxy withOptions:options];                \ | 
					
						
							| 
									
										
										
										
											2023-10-19 10:35:14 +02:00
										 |  |  |                                           }];                                                                                              \ | 
					
						
							|  |  |  |   }                                                                                                                                        \ | 
					
						
							|  |  |  |                                                                                                                                            \ | 
					
						
							|  |  |  |   @end |