@@ -94,29 +94,53 @@ jsi::Value OpenCVPlugin::get(jsi::Runtime& runtime, const jsi::PropNameID& propN
94
94
[=](jsi::Runtime& runtime, const jsi::Value& thisValue, const jsi::Value* arguments,
95
95
size_t count) -> jsi::Object {
96
96
97
- std::string id = FOCV_JsiObject::id_from_wrap (runtime, arguments[0 ]);
98
- auto mat = *FOCV_Storage::get<cv::Mat>(id);
99
-
100
- jsi::Object value (runtime);
101
-
102
- value.setProperty (runtime, " cols" , jsi::Value (mat.cols ));
103
- value.setProperty (runtime, " rows" , jsi::Value (mat.rows ));
104
- value.setProperty (runtime, " channels" , jsi::Value (mat.channels ()));
105
-
106
- auto type = arguments[1 ].asString (runtime).utf8 (runtime);
107
- int size = mat.cols * mat.rows * mat.channels ();
108
-
109
- if (type == " uint8" ) {
110
- auto arr = TypedArray<TypedArrayKind::Uint8Array>(runtime, size);
111
- arr.updateUnsafe (runtime, (uint8_t *)mat.data , size * sizeof (uint8_t ));
112
- value.setProperty (runtime, " buffer" , arr);
113
- } else if (type == " float32" ) {
114
- auto arr = TypedArray<TypedArrayKind::Float32Array>(runtime, size);
115
- arr.updateUnsafe (runtime, (float *)mat.data , size * sizeof (float ));
116
- value.setProperty (runtime, " buffer" , arr);
117
- }
118
-
119
- return value;
97
+ std::string id = FOCV_JsiObject::id_from_wrap (runtime, arguments[0 ]);
98
+ auto mat = *FOCV_Storage::get<cv::Mat>(id);
99
+
100
+ jsi::Object value (runtime);
101
+
102
+ value.setProperty (runtime, " cols" , jsi::Value (mat.cols ));
103
+ value.setProperty (runtime, " rows" , jsi::Value (mat.rows ));
104
+ value.setProperty (runtime, " channels" , jsi::Value (mat.channels ()));
105
+
106
+ auto type = arguments[1 ].asString (runtime).utf8 (runtime);
107
+ int size = mat.cols * mat.rows * mat.channels ();
108
+
109
+ if (type == " uint8" ) {
110
+ auto arr = TypedArray<TypedArrayKind::Uint8Array>(runtime, size);
111
+ arr.updateUnsafe (runtime, (uint8_t *)mat.data , size * sizeof (uint8_t ));
112
+ value.setProperty (runtime, " buffer" , arr);
113
+ } else if (type == " uint16" ) {
114
+ auto arr = TypedArray<TypedArrayKind::Uint16Array>(runtime, size);
115
+ arr.updateUnsafe (runtime, (uint16_t *)mat.data , size * sizeof (uint16_t ));
116
+ value.setProperty (runtime, " buffer" , arr);
117
+ } else if (type == " uint32" ) {
118
+ auto arr = TypedArray<TypedArrayKind::Uint32Array>(runtime, size);
119
+ arr.updateUnsafe (runtime, (uint32_t *)mat.data , size * sizeof (uint32_t ));
120
+ value.setProperty (runtime, " buffer" , arr);
121
+ } else if (type == " int8" ) {
122
+ auto arr = TypedArray<TypedArrayKind::Int8Array>(runtime, size);
123
+ arr.updateUnsafe (runtime, (int8_t *)mat.data , size * sizeof (int8_t ));
124
+ value.setProperty (runtime, " buffer" , arr);
125
+ } else if (type == " int16" ) {
126
+ auto arr = TypedArray<TypedArrayKind::Int16Array>(runtime, size);
127
+ arr.updateUnsafe (runtime, (int16_t *)mat.data , size * sizeof (int16_t ));
128
+ value.setProperty (runtime, " buffer" , arr);
129
+ } else if (type == " int32" ) {
130
+ auto arr = TypedArray<TypedArrayKind::Int32Array>(runtime, size);
131
+ arr.updateUnsafe (runtime, (int32_t *)mat.data , size * sizeof (int32_t ));
132
+ value.setProperty (runtime, " buffer" , arr);
133
+ } else if (type == " float32" ) {
134
+ auto arr = TypedArray<TypedArrayKind::Float32Array>(runtime, size);
135
+ arr.updateUnsafe (runtime, (float *)mat.data , size * sizeof (float ));
136
+ value.setProperty (runtime, " buffer" , arr);
137
+ } else if (type == " float64" ) {
138
+ auto arr = TypedArray<TypedArrayKind::Float64Array>(runtime, size);
139
+ arr.updateUnsafe (runtime, (double *)mat.data , size * sizeof (double ));
140
+ value.setProperty (runtime, " buffer" , arr);
141
+ }
142
+
143
+ return value;
120
144
});
121
145
} else if (propName == " createObject" ) {
122
146
return jsi::Function::createFromHostFunction (
0 commit comments