1 /*
2 * Copyright (c) 2024-2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "ability/camera_ability_napi.h"
17 #include "camera_log.h"
18 #include "camera_napi_utils.h"
19 #include "napi/native_common.h"
20 #include "napi/native_api.h"
21 #include "js_native_api_types.h"
22 #include "camera_napi_security_utils.h"
23 #include "camera_napi_param_parser.h"
24 #include "camera_napi_security_utils.h"
25 #include "camera_error_code.h"
26
27 namespace OHOS {
28 namespace CameraStandard {
29 using namespace std;
30 thread_local sptr<CameraAbility> CameraFunctionsNapi::sCameraAbility_ = nullptr;
31 thread_local napi_ref CameraFunctionsNapi::sPhotoConstructor_ = nullptr;
32 thread_local napi_ref CameraFunctionsNapi::sPhotoConflictConstructor_ = nullptr;
33 thread_local napi_ref CameraFunctionsNapi::sPortraitPhotoConstructor_ = nullptr;
34 thread_local napi_ref CameraFunctionsNapi::sPortraitPhotoConflictConstructor_ = nullptr;
35 thread_local napi_ref CameraFunctionsNapi::sVideoConstructor_ = nullptr;
36 thread_local napi_ref CameraFunctionsNapi::sVideoConflictConstructor_ = nullptr;
37
38 const std::map<FunctionsType, const char*> CameraFunctionsNapi::functionsNameMap_ = {
39 {FunctionsType::PHOTO_FUNCTIONS, PHOTO_ABILITY_NAPI_CLASS_NAME},
40 {FunctionsType::PHOTO_CONFLICT_FUNCTIONS, PHOTO_CONFLICT_ABILITY_NAPI_CLASS_NAME},
41 {FunctionsType::PORTRAIT_PHOTO_FUNCTIONS, PORTRAIT_PHOTO_ABILITY_NAPI_CLASS_NAME},
42 {FunctionsType::PORTRAIT_PHOTO_CONFLICT_FUNCTIONS, PORTRAIT_PHOTO_CONFLICT_ABILITY_NAPI_CLASS_NAME},
43 {FunctionsType::VIDEO_FUNCTIONS, VIDEO_ABILITY_NAPI_CLASS_NAME},
44 {FunctionsType::VIDEO_CONFLICT_FUNCTIONS, VIDEO_CONFLICT_ABILITY_NAPI_CLASS_NAME}
45 };
46
47 const std::vector<napi_property_descriptor> CameraFunctionsNapi::flash_query_props = {
48 DECLARE_NAPI_FUNCTION("hasFlash", CameraFunctionsNapi::HasFlash),
49 DECLARE_NAPI_FUNCTION("isFlashModeSupported", CameraFunctionsNapi::IsFlashModeSupported),
50 DECLARE_NAPI_FUNCTION("isLcdFlashSupported", CameraFunctionsNapi::IsLcdFlashSupported),
51 };
52
53 const std::vector<napi_property_descriptor> CameraFunctionsNapi::auto_exposure_query_props = {
54 DECLARE_NAPI_FUNCTION("isExposureModeSupported", CameraFunctionsNapi::IsExposureModeSupported),
55 DECLARE_NAPI_FUNCTION("getExposureBiasRange", CameraFunctionsNapi::GetExposureBiasRange)
56 };
57
58 const std::vector<napi_property_descriptor> CameraFunctionsNapi::focus_query_props = {
59 DECLARE_NAPI_FUNCTION("isFocusModeSupported", CameraFunctionsNapi::IsFocusModeSupported),
60 DECLARE_NAPI_FUNCTION("isFocusRangeTypeSupported", CameraFunctionsNapi::IsFocusRangeTypeSupported),
61 DECLARE_NAPI_FUNCTION("isFocusDrivenTypeSupported", CameraFunctionsNapi::IsFocusDrivenTypeSupported)
62 };
63
64 const std::vector<napi_property_descriptor> CameraFunctionsNapi::zoom_query_props = {
65 DECLARE_NAPI_FUNCTION("getZoomRatioRange", CameraFunctionsNapi::GetZoomRatioRange)
66 };
67
68 const std::vector<napi_property_descriptor> CameraFunctionsNapi::beauty_query_props = {
69 DECLARE_NAPI_FUNCTION("getSupportedBeautyTypes", CameraFunctionsNapi::GetSupportedBeautyTypes),
70 DECLARE_NAPI_FUNCTION("getSupportedBeautyRange", CameraFunctionsNapi::GetSupportedBeautyRange)
71 };
72
73 const std::vector<napi_property_descriptor> CameraFunctionsNapi::color_effect_query_props = {
74 DECLARE_NAPI_FUNCTION("getSupportedColorEffects", CameraFunctionsNapi::GetSupportedColorEffects)
75 };
76
77 const std::vector<napi_property_descriptor> CameraFunctionsNapi::color_management_query_props = {
78 DECLARE_NAPI_FUNCTION("getSupportedColorSpaces", CameraFunctionsNapi::GetSupportedColorSpaces)
79 };
80
81 const std::vector<napi_property_descriptor> CameraFunctionsNapi::macro_query_props = {
82 DECLARE_NAPI_FUNCTION("isMacroSupported", CameraFunctionsNapi::IsMacroSupported)
83 };
84
85 const std::vector<napi_property_descriptor> CameraFunctionsNapi::depth_fusion_query_props = {
86 DECLARE_NAPI_FUNCTION("isDepthFusionSupported", CameraFunctionsNapi::IsDepthFusionSupported),
87 DECLARE_NAPI_FUNCTION("getDepthFusionThreshold", CameraFunctionsNapi::GetDepthFusionThreshold)
88 };
89
90 const std::vector<napi_property_descriptor> CameraFunctionsNapi::portrait_query_props = {
91 DECLARE_NAPI_FUNCTION("getSupportedPortraitEffects", CameraFunctionsNapi::GetSupportedPortraitEffects)
92 };
93
94 const std::vector<napi_property_descriptor> CameraFunctionsNapi::aperture_query_props = {
95 DECLARE_NAPI_FUNCTION("getSupportedVirtualApertures", CameraFunctionsNapi::GetSupportedVirtualApertures),
96 DECLARE_NAPI_FUNCTION("getSupportedPhysicalApertures", CameraFunctionsNapi::GetSupportedPhysicalApertures)
97 };
98
99 const std::vector<napi_property_descriptor> CameraFunctionsNapi::stabilization_query_props = {
100 DECLARE_NAPI_FUNCTION("isVideoStabilizationModeSupported", CameraFunctionsNapi::IsVideoStabilizationModeSupported)
101 };
102
103 const std::vector<napi_property_descriptor> CameraFunctionsNapi::manual_exposure_query_props = {
104 DECLARE_NAPI_FUNCTION("getSupportedExposureRange", CameraFunctionsNapi::GetSupportedExposureRange),
105 };
106
107 const std::vector<napi_property_descriptor> CameraFunctionsNapi::features_query_props = {
108 DECLARE_NAPI_FUNCTION("isSceneFeatureSupported", CameraFunctionsNapi::IsFeatureSupported),
109 };
110
111 const std::map<FunctionsType, Descriptor> CameraFunctionsNapi::functionsDescMap_ = {
112 {FunctionsType::PHOTO_FUNCTIONS, {flash_query_props, auto_exposure_query_props, focus_query_props, zoom_query_props,
113 beauty_query_props, color_effect_query_props, color_management_query_props, macro_query_props,
114 depth_fusion_query_props, manual_exposure_query_props, features_query_props}},
115 {FunctionsType::PORTRAIT_PHOTO_FUNCTIONS, {flash_query_props, auto_exposure_query_props, focus_query_props,
116 zoom_query_props, beauty_query_props, color_effect_query_props, color_management_query_props,
117 portrait_query_props, aperture_query_props, features_query_props}},
118 {FunctionsType::VIDEO_FUNCTIONS, {flash_query_props, auto_exposure_query_props, focus_query_props, zoom_query_props,
119 stabilization_query_props, beauty_query_props, color_effect_query_props, color_management_query_props,
120 macro_query_props, manual_exposure_query_props, features_query_props}},
121 {FunctionsType::PHOTO_CONFLICT_FUNCTIONS, {zoom_query_props, macro_query_props}},
122 {FunctionsType::PORTRAIT_PHOTO_CONFLICT_FUNCTIONS, {zoom_query_props, portrait_query_props, aperture_query_props}},
123 {FunctionsType::VIDEO_CONFLICT_FUNCTIONS, {zoom_query_props, macro_query_props}}};
124
Init(napi_env env,napi_value exports,FunctionsType type)125 napi_value CameraFunctionsNapi::Init(napi_env env, napi_value exports, FunctionsType type)
126 {
127 MEDIA_DEBUG_LOG("Init is called");
128 napi_status status;
129 napi_value ctorObj;
130 int32_t refCount = 1;
131 std::vector<std::vector<napi_property_descriptor>> descriptors;
132 auto nameIt = functionsNameMap_.find(type);
133 CHECK_ERROR_RETURN_RET_LOG(nameIt == functionsNameMap_.end(), nullptr, "Init call Failed, className not find");
134 auto className = nameIt->second;
135
136 auto descIt = functionsDescMap_.find(type);
137 CHECK_ERROR_RETURN_RET_LOG(descIt == functionsDescMap_.end(), nullptr, "Init call Failed, descriptors not find");
138 std::vector<napi_property_descriptor> camera_ability_props = CameraNapiUtils::GetPropertyDescriptor(descIt->second);
139
140 status = napi_define_class(env, className, NAPI_AUTO_LENGTH,
141 CameraFunctionsNapiConstructor, nullptr,
142 camera_ability_props.size(),
143 camera_ability_props.data(), &ctorObj);
144 if (status == napi_ok) {
145 if (type == FunctionsType::PHOTO_FUNCTIONS) {
146 status = napi_create_reference(env, ctorObj, refCount, &sPhotoConstructor_);
147 } else if (type == FunctionsType::PHOTO_CONFLICT_FUNCTIONS) {
148 status = napi_create_reference(env, ctorObj, refCount, &sPhotoConflictConstructor_);
149 } else if (type == FunctionsType::PORTRAIT_PHOTO_FUNCTIONS) {
150 status = napi_create_reference(env, ctorObj, refCount, &sPortraitPhotoConstructor_);
151 } else if (type == FunctionsType::PORTRAIT_PHOTO_CONFLICT_FUNCTIONS) {
152 status = napi_create_reference(env, ctorObj, refCount, &sPortraitPhotoConflictConstructor_);
153 } else if (type == FunctionsType::VIDEO_FUNCTIONS) {
154 status = napi_create_reference(env, ctorObj, refCount, &sVideoConstructor_);
155 } else if (type == FunctionsType::VIDEO_CONFLICT_FUNCTIONS) {
156 status = napi_create_reference(env, ctorObj, refCount, &sVideoConflictConstructor_);
157 } else {
158 return nullptr;
159 }
160
161 if (status == napi_ok) {
162 status = napi_set_named_property(env, exports, className, ctorObj);
163 CHECK_ERROR_RETURN_RET(status == napi_ok, exports);
164 }
165 }
166 MEDIA_ERR_LOG("Init call Failed");
167 return nullptr;
168 }
169
CreateCameraFunctions(napi_env env,sptr<CameraAbility> functions,FunctionsType type)170 napi_value CameraFunctionsNapi::CreateCameraFunctions(napi_env env, sptr<CameraAbility> functions, FunctionsType type)
171 {
172 MEDIA_DEBUG_LOG("CreateCameraFunctions is called");
173 napi_status status;
174 napi_value result = nullptr;
175 napi_value constructor;
176 if (type == FunctionsType::PHOTO_FUNCTIONS) {
177 status = napi_get_reference_value(env, sPhotoConstructor_, &constructor);
178 } else if (type == FunctionsType::PHOTO_CONFLICT_FUNCTIONS) {
179 status = napi_get_reference_value(env, sPhotoConflictConstructor_, &constructor);
180 } else if (type == FunctionsType::PORTRAIT_PHOTO_FUNCTIONS) {
181 status = napi_get_reference_value(env, sPortraitPhotoConstructor_, &constructor);
182 } else if (type == FunctionsType::PORTRAIT_PHOTO_CONFLICT_FUNCTIONS) {
183 status = napi_get_reference_value(env, sPortraitPhotoConflictConstructor_, &constructor);
184 } else if (type == FunctionsType::VIDEO_FUNCTIONS) {
185 status = napi_get_reference_value(env, sVideoConstructor_, &constructor);
186 } else if (type == FunctionsType::VIDEO_CONFLICT_FUNCTIONS) {
187 status = napi_get_reference_value(env, sVideoConflictConstructor_, &constructor);
188 } else {
189 MEDIA_ERR_LOG("CreateCameraFunctions call Failed type not find");
190 napi_get_undefined(env, &result);
191 return result;
192 }
193
194 if (status == napi_ok) {
195 sCameraAbility_ = functions;
196 status = napi_new_instance(env, constructor, 0, nullptr, &result);
197 sCameraAbility_ = nullptr;
198 if (status == napi_ok && result != nullptr) {
199 return result;
200 } else {
201 MEDIA_ERR_LOG("Failed to create camera functions instance");
202 }
203 }
204 MEDIA_ERR_LOG("CreateCameraFunctions call Failed");
205 napi_get_undefined(env, &result);
206 return result;
207 }
208
CameraFunctionsNapi()209 CameraFunctionsNapi::CameraFunctionsNapi() : env_(nullptr), wrapper_(nullptr) {}
210
~CameraFunctionsNapi()211 CameraFunctionsNapi::~CameraFunctionsNapi()
212 {
213 MEDIA_DEBUG_LOG("~CameraFunctionsNapi is called");
214 CHECK_EXECUTE(wrapper_ != nullptr, napi_delete_reference(env_, wrapper_));
215 if (cameraAbility_) {
216 cameraAbility_ = nullptr;
217 }
218 }
219
CameraFunctionsNapiConstructor(napi_env env,napi_callback_info info)220 napi_value CameraFunctionsNapi::CameraFunctionsNapiConstructor(napi_env env, napi_callback_info info)
221 {
222 MEDIA_DEBUG_LOG("CameraFunctionsNapiConstructor is called");
223 napi_status status;
224 napi_value result = nullptr;
225 napi_value thisVar = nullptr;
226
227 napi_get_undefined(env, &result);
228 CAMERA_NAPI_GET_JS_OBJ_WITH_ZERO_ARGS(env, info, status, thisVar);
229
230 if (status == napi_ok && thisVar != nullptr) {
231 std::unique_ptr<CameraFunctionsNapi> obj = std::make_unique<CameraFunctionsNapi>();
232 obj->env_ = env;
233 obj->cameraAbility_ = sCameraAbility_;
234 status = napi_wrap(env, thisVar, reinterpret_cast<void*>(obj.get()),
235 CameraFunctionsNapi::CameraFunctionsNapiDestructor, nullptr, nullptr);
236 if (status == napi_ok) {
237 obj.release();
238 return thisVar;
239 } else {
240 MEDIA_ERR_LOG("Failure wrapping js to native napi");
241 }
242 }
243 MEDIA_ERR_LOG("CameraFunctionsNapiConstructor call Failed");
244 return result;
245 }
246
CameraFunctionsNapiDestructor(napi_env env,void * nativeObject,void * finalize_hint)247 void CameraFunctionsNapi::CameraFunctionsNapiDestructor(napi_env env, void* nativeObject, void* finalize_hint)
248 {
249 MEDIA_DEBUG_LOG("CameraFunctionsNapiDestructor is called");
250 CameraFunctionsNapi* cameraAbilityNapi = reinterpret_cast<CameraFunctionsNapi*>(nativeObject);
251 if (cameraAbilityNapi != nullptr) {
252 delete cameraAbilityNapi;
253 }
254 }
255
256 template<typename U>
HandleQuery(napi_env env,napi_callback_info info,napi_value thisVar,U queryFunction)257 napi_value CameraFunctionsNapi::HandleQuery(napi_env env, napi_callback_info info, napi_value thisVar, U queryFunction)
258 {
259 napi_status status;
260 napi_value result = nullptr;
261 napi_get_undefined(env, &result);
262 CameraFunctionsNapi* napiObj = nullptr;
263 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&napiObj));
264 if (status == napi_ok && napiObj != nullptr && napiObj->GetNativeObj() != nullptr) {
265 auto queryResult = queryFunction(napiObj->GetNativeObj());
266 if constexpr(std::is_same_v<decltype(queryResult), bool>) {
267 napi_get_boolean(env, queryResult, &result);
268 } else if constexpr(std::is_same_v<decltype(queryResult), std::vector<int32_t>>
269 || std::is_enum_v<typename decltype(queryResult)::value_type>) {
270 status = napi_create_array(env, &result);
271 CHECK_ERROR_RETURN_RET_LOG(status != napi_ok, result, "napi_create_array call Failed!");
272 for (size_t i = 0; i < queryResult.size(); i++) {
273 int32_t value = queryResult[i];
274 napi_value element;
275 napi_create_int32(env, value, &element);
276 napi_set_element(env, result, i, element);
277 }
278 } else if constexpr(std::is_same_v<decltype(queryResult), std::vector<uint32_t>>) {
279 status = napi_create_array(env, &result);
280 CHECK_ERROR_RETURN_RET_LOG(status != napi_ok, result, "napi_create_array call Failed!");
281 for (size_t i = 0; i < queryResult.size(); i++) {
282 uint32_t value = queryResult[i];
283 napi_value element;
284 napi_create_uint32(env, value, &element);
285 napi_set_element(env, result, i, element);
286 }
287 } else if constexpr(std::is_same_v<decltype(queryResult), std::vector<float>>) {
288 status = napi_create_array(env, &result);
289 CHECK_ERROR_RETURN_RET_LOG(status != napi_ok, result, "napi_create_array call Failed!");
290 for (size_t i = 0; i < queryResult.size(); i++) {
291 float value = queryResult[i];
292 napi_value element;
293 napi_create_double(env, CameraNapiUtils::FloatToDouble(value), &element);
294 napi_set_element(env, result, i, element);
295 }
296 } else {
297 MEDIA_ERR_LOG("Unhandled type in HandleQuery");
298 }
299 } else {
300 MEDIA_ERR_LOG("Query function call Failed!");
301 }
302 return result;
303 }
304
HasFlash(napi_env env,napi_callback_info info)305 napi_value CameraFunctionsNapi::HasFlash(napi_env env, napi_callback_info info)
306 {
307 MEDIA_DEBUG_LOG("HasFlash is called");
308 size_t argc = ARGS_ZERO;
309 napi_value argv[ARGS_ZERO];
310 napi_value thisVar = nullptr;
311 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
312
313 return HandleQuery(env, info, thisVar, [](auto ability) {
314 return ability->HasFlash();
315 });
316 }
317
IsFlashModeSupported(napi_env env,napi_callback_info info)318 napi_value CameraFunctionsNapi::IsFlashModeSupported(napi_env env, napi_callback_info info)
319 {
320 MEDIA_DEBUG_LOG("IsFlashModeSupported is called");
321 size_t argc = ARGS_ONE;
322 napi_value argv[ARGS_ONE];
323 napi_value thisVar = nullptr;
324 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
325
326 return HandleQuery(env, info, thisVar, [env, argv](auto ability) {
327 int32_t value;
328 napi_get_value_int32(env, argv[PARAM0], &value);
329 FlashMode flashMode = (FlashMode)value;
330 return ability->IsFlashModeSupported(flashMode);
331 });
332 }
333
IsLcdFlashSupported(napi_env env,napi_callback_info info)334 napi_value CameraFunctionsNapi::IsLcdFlashSupported(napi_env env, napi_callback_info info)
335 {
336 MEDIA_DEBUG_LOG("IsLcdFlashSupported is called");
337 size_t argc = ARGS_ZERO;
338 napi_value argv[ARGS_ZERO];
339 napi_value thisVar = nullptr;
340 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
341
342 return HandleQuery(env, info, thisVar, [env, argv](auto ability) {
343 return ability->IsLcdFlashSupported();
344 });
345 }
346
IsExposureModeSupported(napi_env env,napi_callback_info info)347 napi_value CameraFunctionsNapi::IsExposureModeSupported(napi_env env, napi_callback_info info)
348 {
349 MEDIA_DEBUG_LOG("IsExposureModeSupported is called");
350 size_t argc = ARGS_ONE;
351 napi_value argv[ARGS_ONE];
352 napi_value thisVar = nullptr;
353 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
354
355 return HandleQuery(env, info, thisVar, [env, argv](auto ability) {
356 int32_t value;
357 napi_get_value_int32(env, argv[PARAM0], &value);
358 ExposureMode exposureMode = (ExposureMode)value;
359 return ability->IsExposureModeSupported(exposureMode);
360 });
361 }
362
GetExposureBiasRange(napi_env env,napi_callback_info info)363 napi_value CameraFunctionsNapi::GetExposureBiasRange(napi_env env, napi_callback_info info)
364 {
365 MEDIA_DEBUG_LOG("GetExposureBiasRange is called");
366 size_t argc = ARGS_ZERO;
367 napi_value argv[ARGS_ZERO];
368 napi_value thisVar = nullptr;
369 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
370
371 return HandleQuery(env, info, thisVar, [](auto ability) {
372 return ability->GetExposureBiasRange();
373 });
374 }
375
IsFocusModeSupported(napi_env env,napi_callback_info info)376 napi_value CameraFunctionsNapi::IsFocusModeSupported(napi_env env, napi_callback_info info)
377 {
378 MEDIA_DEBUG_LOG("IsFocusModeSupported is called");
379 size_t argc = ARGS_ONE;
380 napi_value argv[ARGS_ONE];
381 napi_value thisVar = nullptr;
382 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
383
384 return HandleQuery(env, info, thisVar, [env, argv](auto ability) {
385 int32_t value;
386 napi_get_value_int32(env, argv[PARAM0], &value);
387 FocusMode focusMode = (FocusMode)value;
388 return ability->IsFocusModeSupported(focusMode);
389 });
390 }
391
IsFocusRangeTypeSupported(napi_env env,napi_callback_info info)392 napi_value CameraFunctionsNapi::IsFocusRangeTypeSupported(napi_env env, napi_callback_info info)
393 {
394 MEDIA_DEBUG_LOG("IsFocusRangeTypeSupported is called");
395 size_t argc = ARGS_ONE;
396 napi_value argv[ARGS_ONE];
397 napi_value thisVar = nullptr;
398 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
399
400 return HandleQuery(env, info, thisVar, [env, argv](auto ability) {
401 int32_t value = 0;
402 napi_get_value_int32(env, argv[PARAM0], &value);
403 FocusRangeType focusRangeType = static_cast<FocusRangeType>(value);
404 return ability->IsFocusRangeTypeSupported(focusRangeType);
405 });
406 }
407
IsFocusDrivenTypeSupported(napi_env env,napi_callback_info info)408 napi_value CameraFunctionsNapi::IsFocusDrivenTypeSupported(napi_env env, napi_callback_info info)
409 {
410 MEDIA_DEBUG_LOG("IsFocusDrivenTypeSupported is called");
411 size_t argc = ARGS_ONE;
412 napi_value argv[ARGS_ONE];
413 napi_value thisVar = nullptr;
414 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
415
416 return HandleQuery(env, info, thisVar, [env, argv](auto ability) {
417 int32_t value = 0;
418 napi_get_value_int32(env, argv[PARAM0], &value);
419 FocusDrivenType focusDrivenType = static_cast<FocusDrivenType>(value);
420 return ability->IsFocusDrivenTypeSupported(focusDrivenType);
421 });
422 }
423
GetZoomRatioRange(napi_env env,napi_callback_info info)424 napi_value CameraFunctionsNapi::GetZoomRatioRange(napi_env env, napi_callback_info info)
425 {
426 MEDIA_DEBUG_LOG("GetZoomRatioRange is called");
427 size_t argc = ARGS_ZERO;
428 napi_value argv[ARGS_ZERO];
429 napi_value thisVar = nullptr;
430 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
431
432 return HandleQuery(env, info, thisVar, [](auto ability) {
433 return ability->GetZoomRatioRange();
434 });
435 }
436
GetSupportedBeautyTypes(napi_env env,napi_callback_info info)437 napi_value CameraFunctionsNapi::GetSupportedBeautyTypes(napi_env env, napi_callback_info info)
438 {
439 MEDIA_DEBUG_LOG("GetSupportedBeautyTypes is called");
440 size_t argc = ARGS_ZERO;
441 napi_value argv[ARGS_ZERO];
442 napi_value thisVar = nullptr;
443 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
444
445 return HandleQuery(env, info, thisVar, [](auto ability) {
446 return ability->GetSupportedBeautyTypes();
447 });
448 }
449
GetSupportedBeautyRange(napi_env env,napi_callback_info info)450 napi_value CameraFunctionsNapi::GetSupportedBeautyRange(napi_env env, napi_callback_info info)
451 {
452 MEDIA_DEBUG_LOG("GetSupportedBeautyRange is called");
453 size_t argc = ARGS_ONE;
454 napi_value argv[ARGS_ONE];
455 napi_value thisVar = nullptr;
456 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
457
458 return HandleQuery(env, info, thisVar, [env, argv](auto ability) {
459 int32_t value;
460 napi_get_value_int32(env, argv[PARAM0], &value);
461 BeautyType beautyType = (BeautyType)value;
462 return ability->GetSupportedBeautyRange(beautyType);
463 });
464 }
465
GetSupportedColorEffects(napi_env env,napi_callback_info info)466 napi_value CameraFunctionsNapi::GetSupportedColorEffects(napi_env env, napi_callback_info info)
467 {
468 MEDIA_DEBUG_LOG("GetSupportedColorEffects is called");
469 size_t argc = ARGS_ZERO;
470 napi_value argv[ARGS_ZERO];
471 napi_value thisVar = nullptr;
472 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
473
474 return HandleQuery(env, info, thisVar, [](auto ability) {
475 return ability->GetSupportedColorEffects();
476 });
477 }
478
GetSupportedColorSpaces(napi_env env,napi_callback_info info)479 napi_value CameraFunctionsNapi::GetSupportedColorSpaces(napi_env env, napi_callback_info info)
480 {
481 MEDIA_DEBUG_LOG("GetSupportedColorSpaces is called.");
482 size_t argc = ARGS_ZERO;
483 napi_value argv[ARGS_ZERO];
484 napi_value thisVar = nullptr;
485 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
486
487 return HandleQuery(env, info, thisVar, [](auto ability) {
488 return ability->GetSupportedColorSpaces();
489 });
490 }
491
IsMacroSupported(napi_env env,napi_callback_info info)492 napi_value CameraFunctionsNapi::IsMacroSupported(napi_env env, napi_callback_info info)
493 {
494 size_t argc = ARGS_ZERO;
495 napi_value argv[ARGS_ZERO];
496 napi_value thisVar = nullptr;
497 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
498
499 return HandleQuery(env, info, thisVar, [](auto ability) {
500 return ability->IsMacroSupported();
501 });
502 }
503
IsDepthFusionSupported(napi_env env,napi_callback_info info)504 napi_value CameraFunctionsNapi::IsDepthFusionSupported(napi_env env, napi_callback_info info)
505 {
506 CHECK_ERROR_RETURN_RET_LOG(!CameraNapiSecurity::CheckSystemApp(env),
507 nullptr, "SystemApi IsDepthFusionSupported is called!");
508 napi_value thisVar = nullptr;
509 CameraFunctionsNapi* cameraFunctionsNapi = nullptr;
510 CameraNapiParamParser jsParamParser(env, info, cameraFunctionsNapi);
511 CHECK_ERROR_RETURN_RET_LOG(!jsParamParser.AssertStatus(INVALID_ARGUMENT, "parse parameter occur error"),
512 nullptr, "CameraSessionNapi::IsDepthFusionSupported parse parameter occur error");
513 thisVar = jsParamParser.GetThisVar();
514
515 return HandleQuery(env, info, thisVar, [](auto ability) {
516 return ability->IsDepthFusionSupported();
517 });
518 }
519
GetDepthFusionThreshold(napi_env env,napi_callback_info info)520 napi_value CameraFunctionsNapi::GetDepthFusionThreshold(napi_env env, napi_callback_info info)
521 {
522 CHECK_ERROR_RETURN_RET_LOG(!CameraNapiSecurity::CheckSystemApp(env),
523 nullptr, "SystemApi GetDepthFusionThreshold is called!");
524 napi_value thisVar = nullptr;
525 CameraFunctionsNapi* cameraFunctionsNapi = nullptr;
526 CameraNapiParamParser jsParamParser(env, info, cameraFunctionsNapi);
527 CHECK_ERROR_RETURN_RET_LOG(!jsParamParser.AssertStatus(INVALID_ARGUMENT, "parse parameter occur error"),
528 nullptr, "CameraSessionNapi::GetDepthFusionThreshold parse parameter occur error");
529 thisVar = jsParamParser.GetThisVar();
530
531 return HandleQuery(env, info, thisVar, [](auto ability) {
532 return ability->GetDepthFusionThreshold();
533 });
534 }
535
GetSupportedPortraitEffects(napi_env env,napi_callback_info info)536 napi_value CameraFunctionsNapi::GetSupportedPortraitEffects(napi_env env, napi_callback_info info)
537 {
538 size_t argc = ARGS_ZERO;
539 napi_value argv[ARGS_ZERO];
540 napi_value thisVar = nullptr;
541 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
542
543 return HandleQuery(env, info, thisVar, [](auto ability) {
544 return ability->GetSupportedPortraitEffects();
545 });
546 }
547
GetSupportedVirtualApertures(napi_env env,napi_callback_info info)548 napi_value CameraFunctionsNapi::GetSupportedVirtualApertures(napi_env env, napi_callback_info info)
549 {
550 size_t argc = ARGS_ZERO;
551 napi_value argv[ARGS_ZERO];
552 napi_value thisVar = nullptr;
553 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
554
555 return HandleQuery(env, info, thisVar, [](auto ability) {
556 return ability->GetSupportedVirtualApertures();
557 });
558 }
559
GetSupportedPhysicalApertures(napi_env env,napi_callback_info info)560 napi_value CameraFunctionsNapi::GetSupportedPhysicalApertures(napi_env env, napi_callback_info info)
561 {
562 MEDIA_DEBUG_LOG("GetSupportedPhysicalApertures is called");
563 size_t argc = ARGS_ZERO;
564 napi_value argv[ARGS_ZERO];
565 napi_value thisVar = nullptr;
566 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
567
568 napi_status status;
569 napi_value result = nullptr;
570 napi_get_undefined(env, &result);
571 status = napi_create_array(env, &result);
572 CHECK_ERROR_RETURN_RET_LOG(status != napi_ok, result, "napi_create_array call Failed!");
573 CameraFunctionsNapi* cameraAbilityNapi = nullptr;
574 status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraAbilityNapi));
575 if (status == napi_ok && cameraAbilityNapi != nullptr && cameraAbilityNapi->GetNativeObj() !=nullptr) {
576 std::vector<std::vector<float>> physicalApertures =
577 cameraAbilityNapi->GetNativeObj()->GetSupportedPhysicalApertures();
578 MEDIA_INFO_LOG("GetSupportedPhysicalApertures len = %{public}zu", physicalApertures.size());
579 if (!physicalApertures.empty()) {
580 result = CameraNapiUtils::ProcessingPhysicalApertures(env, physicalApertures);
581 }
582 } else {
583 MEDIA_ERR_LOG("GetSupportedPhysicalApertures call Failed!");
584 }
585 return result;
586 }
587
IsVideoStabilizationModeSupported(napi_env env,napi_callback_info info)588 napi_value CameraFunctionsNapi::IsVideoStabilizationModeSupported(napi_env env, napi_callback_info info)
589 {
590 MEDIA_DEBUG_LOG("IsVideoStabilizationModeSupported is called");
591 size_t argc = ARGS_ONE;
592 napi_value argv[ARGS_ONE];
593 napi_value thisVar = nullptr;
594 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
595
596 return HandleQuery(env, info, thisVar, [env, argv](auto ability) {
597 int32_t value;
598 napi_get_value_int32(env, argv[PARAM0], &value);
599 VideoStabilizationMode stabilizationMode = (VideoStabilizationMode)value;
600 return ability->IsVideoStabilizationModeSupported(stabilizationMode);
601 });
602 }
603
GetSupportedExposureRange(napi_env env,napi_callback_info info)604 napi_value CameraFunctionsNapi::GetSupportedExposureRange(napi_env env, napi_callback_info info)
605 {
606 MEDIA_DEBUG_LOG("GetSupportedExposureRange is called");
607 size_t argc = ARGS_ZERO;
608 napi_value argv[ARGS_ZERO];
609 napi_value thisVar = nullptr;
610 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
611
612 return HandleQuery(env, info, thisVar, [](auto ability) {
613 return ability->GetSupportedExposureRange();
614 });
615 }
616
IsFeatureSupported(napi_env env,napi_callback_info info)617 napi_value CameraFunctionsNapi::IsFeatureSupported(napi_env env, napi_callback_info info)
618 {
619 MEDIA_DEBUG_LOG("IsFeatureSupported is called");
620 size_t argc = ARGS_ONE;
621 napi_value argv[ARGS_ONE];
622 napi_value thisVar = nullptr;
623 CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
624
625 return HandleQuery(env, info, thisVar, [env, argv](auto ability) {
626 int32_t value;
627 napi_get_value_int32(env, argv[PARAM0], &value);
628 SceneFeature sceneFeature = (SceneFeature)value;
629 return ability->IsFeatureSupported(sceneFeature);
630 });
631 }
632 } // namespace CameraStandard
633 } // namespace OHOS