react-native-camera-vision-pixel-colors 0.1.0
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.
- package/CameraVisionPixelColors.podspec +32 -0
- package/LICENSE +21 -0
- package/README.md +190 -0
- package/android/CMakeLists.txt +32 -0
- package/android/build.gradle +151 -0
- package/android/fix-prefab.gradle +51 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/cpp/cpp-adapter.cpp +6 -0
- package/android/src/main/java/com/cameravisionpixelcolors/CameraVisionPixelColorsPackage.kt +24 -0
- package/android/src/main/java/com/cameravisionpixelcolors/PixelAnalyzerEngine.kt +256 -0
- package/android/src/main/java/com/cameravisionpixelcolors/PixelColorsFrameProcessor.kt +40 -0
- package/android/src/main/java/com/cameravisionpixelcolors/YuvToBitmapConverter.kt +33 -0
- package/android/src/main/java/com/margelo/nitro/cameravisionpixelcolors/HybridCameraVisionPixelColors.kt +50 -0
- package/app.plugin.js +1 -0
- package/ios/Bridge.h +8 -0
- package/ios/HybridCameraVisionPixelColors.swift +53 -0
- package/ios/PixelAnalyzerEngine.swift +346 -0
- package/ios/PixelColorsFrameProcessor.m +5 -0
- package/ios/PixelColorsFrameProcessor.swift +50 -0
- package/lib/commonjs/index.js +28 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/specs/camera-vision-pixel-colors.nitro.js +6 -0
- package/lib/commonjs/specs/camera-vision-pixel-colors.nitro.js.map +1 -0
- package/lib/module/index.js +23 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/specs/camera-vision-pixel-colors.nitro.js +4 -0
- package/lib/module/specs/camera-vision-pixel-colors.nitro.js.map +1 -0
- package/lib/typescript/src/index.d.ts +6 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/specs/camera-vision-pixel-colors.nitro.d.ts +40 -0
- package/lib/typescript/src/specs/camera-vision-pixel-colors.nitro.d.ts.map +1 -0
- package/nitro.json +25 -0
- package/nitrogen/generated/.gitattributes +1 -0
- package/nitrogen/generated/android/CameraVisionPixelColors+autolinking.cmake +81 -0
- package/nitrogen/generated/android/CameraVisionPixelColors+autolinking.gradle +27 -0
- package/nitrogen/generated/android/CameraVisionPixelColorsOnLoad.cpp +44 -0
- package/nitrogen/generated/android/CameraVisionPixelColorsOnLoad.hpp +25 -0
- package/nitrogen/generated/android/c++/JHybridCameraVisionPixelColorsSpec.cpp +90 -0
- package/nitrogen/generated/android/c++/JHybridCameraVisionPixelColorsSpec.hpp +66 -0
- package/nitrogen/generated/android/c++/JImageData.hpp +66 -0
- package/nitrogen/generated/android/c++/JMotionResult.hpp +61 -0
- package/nitrogen/generated/android/c++/JPixelColorsResult.hpp +114 -0
- package/nitrogen/generated/android/c++/JRGBColor.hpp +65 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cameravisionpixelcolors/CameraVisionPixelColorsOnLoad.kt +35 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cameravisionpixelcolors/HybridCameraVisionPixelColorsSpec.kt +58 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cameravisionpixelcolors/ImageData.kt +44 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cameravisionpixelcolors/MotionResult.kt +41 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cameravisionpixelcolors/PixelColorsResult.kt +50 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cameravisionpixelcolors/RGBColor.kt +44 -0
- package/nitrogen/generated/ios/CameraVisionPixelColors+autolinking.rb +60 -0
- package/nitrogen/generated/ios/CameraVisionPixelColors-Swift-Cxx-Bridge.cpp +49 -0
- package/nitrogen/generated/ios/CameraVisionPixelColors-Swift-Cxx-Bridge.hpp +162 -0
- package/nitrogen/generated/ios/CameraVisionPixelColors-Swift-Cxx-Umbrella.hpp +59 -0
- package/nitrogen/generated/ios/CameraVisionPixelColorsAutolinking.mm +33 -0
- package/nitrogen/generated/ios/CameraVisionPixelColorsAutolinking.swift +26 -0
- package/nitrogen/generated/ios/c++/HybridCameraVisionPixelColorsSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridCameraVisionPixelColorsSpecSwift.hpp +99 -0
- package/nitrogen/generated/ios/swift/Func_void_PixelColorsResult.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +47 -0
- package/nitrogen/generated/ios/swift/HybridCameraVisionPixelColorsSpec.swift +56 -0
- package/nitrogen/generated/ios/swift/HybridCameraVisionPixelColorsSpec_cxx.swift +146 -0
- package/nitrogen/generated/ios/swift/ImageData.swift +40 -0
- package/nitrogen/generated/ios/swift/MotionResult.swift +35 -0
- package/nitrogen/generated/ios/swift/PixelColorsResult.swift +81 -0
- package/nitrogen/generated/ios/swift/RGBColor.swift +40 -0
- package/nitrogen/generated/shared/c++/HybridCameraVisionPixelColorsSpec.cpp +21 -0
- package/nitrogen/generated/shared/c++/HybridCameraVisionPixelColorsSpec.hpp +67 -0
- package/nitrogen/generated/shared/c++/ImageData.hpp +91 -0
- package/nitrogen/generated/shared/c++/MotionResult.hpp +87 -0
- package/nitrogen/generated/shared/c++/PixelColorsResult.hpp +105 -0
- package/nitrogen/generated/shared/c++/RGBColor.hpp +91 -0
- package/package.json +143 -0
- package/plugin/withPixelColors.js +12 -0
- package/plugin/withPixelColorsAndroid.js +11 -0
- package/plugin/withPixelColorsIOS.js +11 -0
- package/src/index.ts +42 -0
- package/src/specs/camera-vision-pixel-colors.nitro.ts +40 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = "CameraVisionPixelColors"
|
|
7
|
+
s.version = package["version"]
|
|
8
|
+
s.summary = package["description"]
|
|
9
|
+
s.homepage = package["homepage"]
|
|
10
|
+
s.license = package["license"]
|
|
11
|
+
s.authors = package["author"]
|
|
12
|
+
|
|
13
|
+
s.platforms = { :ios => min_ios_version_supported, :visionos => 1.0 }
|
|
14
|
+
s.source = { :git => "https://github.com/yevhenjl/react-native-camera-vision-pixel-colors.git", :tag => "#{s.version}" }
|
|
15
|
+
|
|
16
|
+
s.source_files = [
|
|
17
|
+
# Implementation (Swift)
|
|
18
|
+
"ios/**/*.{swift}",
|
|
19
|
+
# Autolinking/Registration (Objective-C++)
|
|
20
|
+
"ios/**/*.{m,mm}",
|
|
21
|
+
# Implementation (C++ objects)
|
|
22
|
+
"cpp/**/*.{hpp,cpp}",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
load 'nitrogen/generated/ios/CameraVisionPixelColors+autolinking.rb'
|
|
26
|
+
add_nitrogen_files(s)
|
|
27
|
+
|
|
28
|
+
s.dependency 'React-jsi'
|
|
29
|
+
s.dependency 'React-callinvoker'
|
|
30
|
+
s.dependency 'VisionCamera'
|
|
31
|
+
install_modules_dependencies(s)
|
|
32
|
+
end
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Yevhen Lahodiuk
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
# react-native-camera-vision-pixel-colors
|
|
2
|
+
|
|
3
|
+
High-performance **Vision Camera Frame Processor** for React Native (Expo compatible) that analyzes pixel colors **in real time**.
|
|
4
|
+
This plugin extracts:
|
|
5
|
+
- **Top 3 most frequent colors (RGB)**
|
|
6
|
+
- **Top 3 brightest colors (RGB)**
|
|
7
|
+
- **Total number of unique colors**
|
|
8
|
+
- **ROI analysis (configurable region)**
|
|
9
|
+
- **Motion detection (frame diff)**
|
|
10
|
+
|
|
11
|
+
It is implemented using **Nitro Modules** and runs **synchronously on the native thread** for use as a Vision Camera frame processor, while also exposing an async Nitro API for offline image analysis.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Features
|
|
16
|
+
- Real-time processing (frame processor, synchronous)
|
|
17
|
+
- Color frequency analysis
|
|
18
|
+
- Brightness-based color ranking
|
|
19
|
+
- ROI analysis (configurable region)
|
|
20
|
+
- Motion detection (frame diff)
|
|
21
|
+
- Works directly on camera frames (Vision Camera)
|
|
22
|
+
- Written in **Swift (iOS)** and **Kotlin (Android)**
|
|
23
|
+
- Expo compatible via Config Plugin
|
|
24
|
+
- Minimal JS bridge overhead during processing
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Requirements
|
|
29
|
+
- React Native >= 0.81
|
|
30
|
+
- Expo >= 54
|
|
31
|
+
- react-native-vision-camera >= 4.x
|
|
32
|
+
- react-native-nitro-modules (for Nitro API)
|
|
33
|
+
- iOS >= 15.1, Android >= 26
|
|
34
|
+
|
|
35
|
+
> This plugin is built to be used as a **Vision Camera frame processor**. It does **NOT** process images from gallery or URLs via the frame-processor path — use the async Nitro API for that.
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Install (example)
|
|
40
|
+
```bash
|
|
41
|
+
npx expo install react-native-vision-camera
|
|
42
|
+
npm install react-native-camera-vision-pixel-colors
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Add to `app.json` (or `app.config.js`) plugins:
|
|
46
|
+
```json
|
|
47
|
+
{
|
|
48
|
+
"expo": {
|
|
49
|
+
"plugins": [
|
|
50
|
+
"react-native-vision-camera",
|
|
51
|
+
"react-native-camera-vision-pixel-colors"
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Then:
|
|
58
|
+
```bash
|
|
59
|
+
npx expo prebuild
|
|
60
|
+
eas build -p ios
|
|
61
|
+
eas build -p android
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## Usage
|
|
67
|
+
|
|
68
|
+
### Basic Frame Processor
|
|
69
|
+
```ts
|
|
70
|
+
import { useFrameProcessor } from 'react-native-vision-camera';
|
|
71
|
+
import { analyzePixelColors, type PixelColorsResult } from 'react-native-camera-vision-pixel-colors';
|
|
72
|
+
|
|
73
|
+
const frameProcessor = useFrameProcessor((frame) => {
|
|
74
|
+
'worklet';
|
|
75
|
+
const result: PixelColorsResult = analyzePixelColors(frame);
|
|
76
|
+
// result => { uniqueColorCount, topColors: [{r,g,b}], brightestColors: [{r,g,b}] }
|
|
77
|
+
console.log(result);
|
|
78
|
+
}, []);
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Attach to `<Camera />` as `frameProcessor`.
|
|
82
|
+
|
|
83
|
+
### Advanced Options
|
|
84
|
+
|
|
85
|
+
Pass optional analysis options to enable additional features:
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
import { useFrameProcessor } from 'react-native-vision-camera';
|
|
89
|
+
import { analyzePixelColors, type AnalysisOptions } from 'react-native-camera-vision-pixel-colors';
|
|
90
|
+
|
|
91
|
+
const frameProcessor = useFrameProcessor((frame) => {
|
|
92
|
+
'worklet';
|
|
93
|
+
const options: AnalysisOptions = {
|
|
94
|
+
// Analyze only center 20% of frame
|
|
95
|
+
roi: { x: 0.4, y: 0.4, width: 0.2, height: 0.2 },
|
|
96
|
+
|
|
97
|
+
// Enable motion detection
|
|
98
|
+
enableMotionDetection: true,
|
|
99
|
+
motionThreshold: 0.1, // 0-1, default: 0.1
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const result = analyzePixelColors(frame, options);
|
|
103
|
+
|
|
104
|
+
if (result.motion?.hasMotion) {
|
|
105
|
+
console.log('Motion detected!', result.motion.score);
|
|
106
|
+
}
|
|
107
|
+
}, []);
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Async Nitro API (outside camera)
|
|
111
|
+
```ts
|
|
112
|
+
import { CameraVisionPixelColors, type ImageData } from 'react-native-camera-vision-pixel-colors';
|
|
113
|
+
|
|
114
|
+
const imageData: ImageData = { width, height, data: arrayBuffer }; // data: ArrayBuffer (RGBA)
|
|
115
|
+
const result = await CameraVisionPixelColors.analyzeImageAsync(imageData);
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## Output format
|
|
121
|
+
|
|
122
|
+
All types are exported from the library:
|
|
123
|
+
```ts
|
|
124
|
+
import {
|
|
125
|
+
type RGBColor,
|
|
126
|
+
type PixelColorsResult,
|
|
127
|
+
type ImageData,
|
|
128
|
+
type AnalysisOptions,
|
|
129
|
+
type ROIConfig,
|
|
130
|
+
type MotionResult,
|
|
131
|
+
} from 'react-native-camera-vision-pixel-colors';
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
```ts
|
|
135
|
+
type RGBColor = { r: number; g: number; b: number };
|
|
136
|
+
|
|
137
|
+
type ROIConfig = {
|
|
138
|
+
x: number; // 0-1 normalized
|
|
139
|
+
y: number; // 0-1 normalized
|
|
140
|
+
width: number; // 0-1 normalized
|
|
141
|
+
height: number; // 0-1 normalized
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
type AnalysisOptions = {
|
|
145
|
+
enableMotionDetection?: boolean; // default: false
|
|
146
|
+
motionThreshold?: number; // default: 0.1
|
|
147
|
+
roi?: ROIConfig; // if provided, analyze only this region
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
type MotionResult = {
|
|
151
|
+
score: number; // 0-1
|
|
152
|
+
hasMotion: boolean; // score > threshold
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
type PixelColorsResult = {
|
|
156
|
+
uniqueColorCount: number;
|
|
157
|
+
topColors: RGBColor[];
|
|
158
|
+
brightestColors: RGBColor[];
|
|
159
|
+
motion?: MotionResult; // always present if enableMotionDetection=true
|
|
160
|
+
roiApplied?: boolean; // true if ROI config was provided
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
type ImageData = {
|
|
164
|
+
width: number;
|
|
165
|
+
height: number;
|
|
166
|
+
data: ArrayBuffer; // RGBA pixel data
|
|
167
|
+
};
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
## Architecture summary
|
|
173
|
+
- Frame Processor path: **synchronous**, returns the latest cached result (0–1 frame latency).
|
|
174
|
+
- Async Nitro API: full GPU/CPU pipeline, returns an up-to-date result (Promise-based).
|
|
175
|
+
- Shared native engine (iOS/Android) exposes `analyzeAsync(...)` and `analyzeSync()` for the frame-processor path to read cached results.
|
|
176
|
+
|
|
177
|
+
### Memory & Performance Notes
|
|
178
|
+
- **Motion detection**: Uses grayscale comparison with configurable threshold
|
|
179
|
+
- **ROI**: Crops before analysis for improved performance on smaller regions
|
|
180
|
+
- **First frame motion**: Returns `{score: 0, hasMotion: false}` (not null)
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
## Contributing
|
|
185
|
+
PRs welcome. Please keep performance constraints in mind (avoid allocations per frame, reuse buffers).
|
|
186
|
+
|
|
187
|
+
---
|
|
188
|
+
|
|
189
|
+
## License
|
|
190
|
+
MIT © 2026
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
project(CameraVisionPixelColors)
|
|
2
|
+
cmake_minimum_required(VERSION 3.9.0)
|
|
3
|
+
|
|
4
|
+
set (PACKAGE_NAME CameraVisionPixelColors)
|
|
5
|
+
set (CMAKE_VERBOSE_MAKEFILE ON)
|
|
6
|
+
set (CMAKE_CXX_STANDARD 20)
|
|
7
|
+
|
|
8
|
+
# Enable Raw Props parsing in react-native (for Nitro Views)
|
|
9
|
+
add_compile_options(-DRN_SERIALIZABLE_STATE=1)
|
|
10
|
+
|
|
11
|
+
# Define C++ library and add all sources
|
|
12
|
+
add_library(${PACKAGE_NAME} SHARED
|
|
13
|
+
src/main/cpp/cpp-adapter.cpp
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
# Add Nitrogen specs :)
|
|
17
|
+
include(${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/CameraVisionPixelColors+autolinking.cmake)
|
|
18
|
+
|
|
19
|
+
# Set up local includes
|
|
20
|
+
include_directories(
|
|
21
|
+
"src/main/cpp"
|
|
22
|
+
"../cpp"
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
find_library(LOG_LIB log)
|
|
26
|
+
|
|
27
|
+
# Link all libraries together
|
|
28
|
+
target_link_libraries(
|
|
29
|
+
${PACKAGE_NAME}
|
|
30
|
+
${LOG_LIB}
|
|
31
|
+
android # <-- Android core
|
|
32
|
+
)
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
buildscript {
|
|
2
|
+
repositories {
|
|
3
|
+
google()
|
|
4
|
+
mavenCentral()
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
dependencies {
|
|
8
|
+
classpath "com.android.tools.build:gradle:8.8.0"
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
def reactNativeArchitectures() {
|
|
13
|
+
def value = rootProject.getProperties().get("reactNativeArchitectures")
|
|
14
|
+
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
def isNewArchitectureEnabled() {
|
|
18
|
+
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
apply plugin: "com.android.library"
|
|
22
|
+
apply plugin: 'org.jetbrains.kotlin.android'
|
|
23
|
+
apply from: '../nitrogen/generated/android/CameraVisionPixelColors+autolinking.gradle'
|
|
24
|
+
apply from: "./fix-prefab.gradle"
|
|
25
|
+
|
|
26
|
+
if (isNewArchitectureEnabled()) {
|
|
27
|
+
apply plugin: "com.facebook.react"
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
def getExtOrDefault(name) {
|
|
31
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["CameraVisionPixelColors_" + name]
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
def getExtOrIntegerDefault(name) {
|
|
35
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["CameraVisionPixelColors_" + name]).toInteger()
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
android {
|
|
39
|
+
namespace "com.cameravisionpixelcolors"
|
|
40
|
+
|
|
41
|
+
ndkVersion getExtOrDefault("ndkVersion")
|
|
42
|
+
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
|
|
43
|
+
|
|
44
|
+
defaultConfig {
|
|
45
|
+
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
|
|
46
|
+
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
|
|
47
|
+
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
|
|
48
|
+
|
|
49
|
+
externalNativeBuild {
|
|
50
|
+
cmake {
|
|
51
|
+
cppFlags "-frtti -fexceptions -Wall -Wextra -fstack-protector-all"
|
|
52
|
+
arguments "-DANDROID_STL=c++_shared", "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON"
|
|
53
|
+
abiFilters (*reactNativeArchitectures())
|
|
54
|
+
|
|
55
|
+
buildTypes {
|
|
56
|
+
debug {
|
|
57
|
+
cppFlags "-O1 -g"
|
|
58
|
+
}
|
|
59
|
+
release {
|
|
60
|
+
cppFlags "-O2"
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
externalNativeBuild {
|
|
68
|
+
cmake {
|
|
69
|
+
path "CMakeLists.txt"
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
packagingOptions {
|
|
74
|
+
excludes = [
|
|
75
|
+
"META-INF",
|
|
76
|
+
"META-INF/**",
|
|
77
|
+
"**/libc++_shared.so",
|
|
78
|
+
"**/libfbjni.so",
|
|
79
|
+
"**/libjsi.so",
|
|
80
|
+
"**/libfolly_json.so",
|
|
81
|
+
"**/libfolly_runtime.so",
|
|
82
|
+
"**/libglog.so",
|
|
83
|
+
"**/libhermes.so",
|
|
84
|
+
"**/libhermes-executor-debug.so",
|
|
85
|
+
"**/libhermes_executor.so",
|
|
86
|
+
"**/libreactnative.so",
|
|
87
|
+
"**/libreactnativejni.so",
|
|
88
|
+
"**/libturbomodulejsijni.so",
|
|
89
|
+
"**/libreact_nativemodule_core.so",
|
|
90
|
+
"**/libjscexecutor.so"
|
|
91
|
+
]
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
buildFeatures {
|
|
95
|
+
buildConfig true
|
|
96
|
+
prefab true
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
buildTypes {
|
|
100
|
+
release {
|
|
101
|
+
minifyEnabled false
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
lintOptions {
|
|
106
|
+
disable "GradleCompatible"
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
compileOptions {
|
|
110
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
111
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
sourceSets {
|
|
115
|
+
main {
|
|
116
|
+
if (isNewArchitectureEnabled()) {
|
|
117
|
+
java.srcDirs += [
|
|
118
|
+
// React Codegen files
|
|
119
|
+
"${project.buildDir}/generated/source/codegen/java"
|
|
120
|
+
]
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
repositories {
|
|
127
|
+
mavenCentral()
|
|
128
|
+
google()
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
dependencies {
|
|
133
|
+
// For < 0.71, this will be from the local maven repo
|
|
134
|
+
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
|
|
135
|
+
//noinspection GradleDynamicVersion
|
|
136
|
+
implementation "com.facebook.react:react-native:+"
|
|
137
|
+
|
|
138
|
+
// Add a dependency on NitroModules
|
|
139
|
+
implementation project(":react-native-nitro-modules")
|
|
140
|
+
|
|
141
|
+
// VisionCamera for frame processor
|
|
142
|
+
implementation project(":react-native-vision-camera")
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (isNewArchitectureEnabled()) {
|
|
146
|
+
react {
|
|
147
|
+
jsRootDir = file("../src/")
|
|
148
|
+
libraryName = "CameraVisionPixelColors"
|
|
149
|
+
codegenJavaPackageName = "com.cameravisionpixelcolors"
|
|
150
|
+
}
|
|
151
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
tasks.configureEach { task ->
|
|
2
|
+
// Make sure that we generate our prefab publication file only after having built the native library
|
|
3
|
+
// so that not a header publication file, but a full configuration publication will be generated, which
|
|
4
|
+
// will include the .so file
|
|
5
|
+
|
|
6
|
+
def prefabConfigurePattern = ~/^prefab(.+)ConfigurePackage$/
|
|
7
|
+
def matcher = task.name =~ prefabConfigurePattern
|
|
8
|
+
if (matcher.matches()) {
|
|
9
|
+
def variantName = matcher[0][1]
|
|
10
|
+
task.outputs.upToDateWhen { false }
|
|
11
|
+
task.dependsOn("externalNativeBuild${variantName}")
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
afterEvaluate {
|
|
16
|
+
def abis = reactNativeArchitectures()
|
|
17
|
+
rootProject.allprojects.each { proj ->
|
|
18
|
+
if (proj === rootProject) return
|
|
19
|
+
|
|
20
|
+
def dependsOnThisLib = proj.configurations.findAll { it.canBeResolved }.any { config ->
|
|
21
|
+
config.dependencies.any { dep ->
|
|
22
|
+
dep.group == project.group && dep.name == project.name
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (!dependsOnThisLib && proj != project) return
|
|
26
|
+
|
|
27
|
+
if (!proj.plugins.hasPlugin('com.android.application') && !proj.plugins.hasPlugin('com.android.library')) {
|
|
28
|
+
return
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
def variants = proj.android.hasProperty('applicationVariants') ? proj.android.applicationVariants : proj.android.libraryVariants
|
|
32
|
+
// Touch the prefab_config.json files to ensure that in ExternalNativeJsonGenerator.kt we will re-trigger the prefab CLI to
|
|
33
|
+
// generate a libnameConfig.cmake file that will contain our native library (.so).
|
|
34
|
+
// See this condition: https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:build-system/gradle-core/src/main/java/com/android/build/gradle/tasks/ExternalNativeJsonGenerator.kt;l=207-219?q=createPrefabBuildSystemGlue
|
|
35
|
+
variants.all { variant ->
|
|
36
|
+
def variantName = variant.name
|
|
37
|
+
abis.each { abi ->
|
|
38
|
+
def searchDir = new File(proj.projectDir, ".cxx/${variantName}")
|
|
39
|
+
if (!searchDir.exists()) return
|
|
40
|
+
def matches = []
|
|
41
|
+
searchDir.eachDir { randomDir ->
|
|
42
|
+
def prefabFile = new File(randomDir, "${abi}/prefab_config.json")
|
|
43
|
+
if (prefabFile.exists()) matches << prefabFile
|
|
44
|
+
}
|
|
45
|
+
matches.each { prefabConfig ->
|
|
46
|
+
prefabConfig.setLastModified(System.currentTimeMillis())
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
package com.cameravisionpixelcolors;
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.NativeModule;
|
|
4
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
5
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider;
|
|
6
|
+
import com.facebook.react.TurboReactPackage;
|
|
7
|
+
import com.margelo.nitro.cameravisionpixelcolors.CameraVisionPixelColorsOnLoad;
|
|
8
|
+
import com.mrousavy.camera.frameprocessors.FrameProcessorPluginRegistry;
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
public class CameraVisionPixelColorsPackage : TurboReactPackage() {
|
|
12
|
+
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? = null
|
|
13
|
+
|
|
14
|
+
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider = ReactModuleInfoProvider { emptyMap() }
|
|
15
|
+
|
|
16
|
+
companion object {
|
|
17
|
+
init {
|
|
18
|
+
CameraVisionPixelColorsOnLoad.initializeNative();
|
|
19
|
+
FrameProcessorPluginRegistry.addFrameProcessorPlugin("pixelColors") { proxy, options ->
|
|
20
|
+
PixelColorsFrameProcessor(proxy, options)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|