• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_object_types.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     if  (nameIt == functionsNameMap_.end()) {
134         MEDIA_ERR_LOG("Init call Failed, className not find");
135         return nullptr;
136     }
137     auto className = nameIt->second;
138 
139     auto descIt = functionsDescMap_.find(type);
140     if  (descIt == functionsDescMap_.end()) {
141         MEDIA_ERR_LOG("Init call Failed, descriptors not find");
142         return nullptr;
143     }
144     std::vector<napi_property_descriptor> camera_ability_props = CameraNapiUtils::GetPropertyDescriptor(descIt->second);
145 
146     status = napi_define_class(env, className, NAPI_AUTO_LENGTH,
147                                CameraFunctionsNapiConstructor, nullptr,
148                                camera_ability_props.size(),
149                                camera_ability_props.data(), &ctorObj);
150     if (status == napi_ok) {
151         if (type == FunctionsType::PHOTO_FUNCTIONS) {
152             status = napi_create_reference(env, ctorObj, refCount, &sPhotoConstructor_);
153         } else if (type == FunctionsType::PHOTO_CONFLICT_FUNCTIONS) {
154             status = napi_create_reference(env, ctorObj, refCount, &sPhotoConflictConstructor_);
155         } else if (type == FunctionsType::PORTRAIT_PHOTO_FUNCTIONS) {
156             status = napi_create_reference(env, ctorObj, refCount, &sPortraitPhotoConstructor_);
157         } else if (type == FunctionsType::PORTRAIT_PHOTO_CONFLICT_FUNCTIONS) {
158             status = napi_create_reference(env, ctorObj, refCount, &sPortraitPhotoConflictConstructor_);
159         } else if (type == FunctionsType::VIDEO_FUNCTIONS) {
160             status = napi_create_reference(env, ctorObj, refCount, &sVideoConstructor_);
161         } else if (type == FunctionsType::VIDEO_CONFLICT_FUNCTIONS) {
162             status = napi_create_reference(env, ctorObj, refCount, &sVideoConflictConstructor_);
163         } else {
164             return nullptr;
165         }
166 
167         if (status == napi_ok) {
168             status = napi_set_named_property(env, exports, className, ctorObj);
169             if (status == napi_ok) {
170                 return exports;
171             }
172         }
173     }
174     MEDIA_ERR_LOG("Init call Failed");
175     return nullptr;
176 }
177 
CreateCameraFunctions(napi_env env,sptr<CameraAbility> functions,FunctionsType type)178 napi_value CameraFunctionsNapi::CreateCameraFunctions(napi_env env, sptr<CameraAbility> functions, FunctionsType type)
179 {
180     MEDIA_DEBUG_LOG("CreateCameraFunctions is called");
181     napi_status status;
182     napi_value result = nullptr;
183     napi_value constructor;
184     if (type == FunctionsType::PHOTO_FUNCTIONS) {
185         status = napi_get_reference_value(env, sPhotoConstructor_, &constructor);
186     } else if (type == FunctionsType::PHOTO_CONFLICT_FUNCTIONS) {
187         status = napi_get_reference_value(env, sPhotoConflictConstructor_, &constructor);
188     } else if (type == FunctionsType::PORTRAIT_PHOTO_FUNCTIONS) {
189         status = napi_get_reference_value(env, sPortraitPhotoConstructor_, &constructor);
190     } else if (type == FunctionsType::PORTRAIT_PHOTO_CONFLICT_FUNCTIONS) {
191         status = napi_get_reference_value(env, sPortraitPhotoConflictConstructor_, &constructor);
192     } else if (type == FunctionsType::VIDEO_FUNCTIONS) {
193         status = napi_get_reference_value(env, sVideoConstructor_, &constructor);
194     } else if (type == FunctionsType::VIDEO_CONFLICT_FUNCTIONS) {
195         status = napi_get_reference_value(env, sVideoConflictConstructor_, &constructor);
196     } else {
197         MEDIA_ERR_LOG("CreateCameraFunctions call Failed type not find");
198         napi_get_undefined(env, &result);
199         return result;
200     }
201 
202     if (status == napi_ok) {
203         sCameraAbility_ = functions;
204         status = napi_new_instance(env, constructor, 0, nullptr, &result);
205         sCameraAbility_ = nullptr;
206         if (status == napi_ok && result != nullptr) {
207             return result;
208         } else {
209             MEDIA_ERR_LOG("Failed to create camera functions instance");
210         }
211     }
212     MEDIA_ERR_LOG("CreateCameraFunctions call Failed");
213     napi_get_undefined(env, &result);
214     return result;
215 }
216 
CameraFunctionsNapi()217 CameraFunctionsNapi::CameraFunctionsNapi() : env_(nullptr), wrapper_(nullptr) {}
218 
~CameraFunctionsNapi()219 CameraFunctionsNapi::~CameraFunctionsNapi()
220 {
221     MEDIA_DEBUG_LOG("~CameraFunctionsNapi is called");
222     if (wrapper_ != nullptr) {
223         napi_delete_reference(env_, wrapper_);
224     }
225     if (cameraAbility_) {
226         cameraAbility_ = nullptr;
227     }
228 }
229 
CameraFunctionsNapiConstructor(napi_env env,napi_callback_info info)230 napi_value CameraFunctionsNapi::CameraFunctionsNapiConstructor(napi_env env, napi_callback_info info)
231 {
232     MEDIA_DEBUG_LOG("CameraFunctionsNapiConstructor is called");
233     napi_status status;
234     napi_value result = nullptr;
235     napi_value thisVar = nullptr;
236 
237     napi_get_undefined(env, &result);
238     CAMERA_NAPI_GET_JS_OBJ_WITH_ZERO_ARGS(env, info, status, thisVar);
239 
240     if (status == napi_ok && thisVar != nullptr) {
241         std::unique_ptr<CameraFunctionsNapi> obj = std::make_unique<CameraFunctionsNapi>();
242         obj->env_ = env;
243         obj->cameraAbility_ = sCameraAbility_;
244         status = napi_wrap(env, thisVar, reinterpret_cast<void*>(obj.get()),
245             CameraFunctionsNapi::CameraFunctionsNapiDestructor, nullptr, nullptr);
246         if (status == napi_ok) {
247             obj.release();
248             return thisVar;
249         } else {
250             MEDIA_ERR_LOG("Failure wrapping js to native napi");
251         }
252     }
253     MEDIA_ERR_LOG("CameraFunctionsNapiConstructor call Failed");
254     return result;
255 }
256 
CameraFunctionsNapiDestructor(napi_env env,void * nativeObject,void * finalize_hint)257 void CameraFunctionsNapi::CameraFunctionsNapiDestructor(napi_env env, void* nativeObject, void* finalize_hint)
258 {
259     MEDIA_DEBUG_LOG("CameraFunctionsNapiDestructor is called");
260     CameraFunctionsNapi* cameraAbilityNapi = reinterpret_cast<CameraFunctionsNapi*>(nativeObject);
261     if (cameraAbilityNapi != nullptr) {
262         delete cameraAbilityNapi;
263     }
264 }
265 
266 template<typename U>
HandleQuery(napi_env env,napi_callback_info info,napi_value thisVar,U queryFunction)267 napi_value CameraFunctionsNapi::HandleQuery(napi_env env, napi_callback_info info, napi_value thisVar, U queryFunction)
268 {
269     napi_status status;
270     napi_value result = nullptr;
271     napi_get_undefined(env, &result);
272     CameraFunctionsNapi* napiObj = nullptr;
273     status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&napiObj));
274     if (status == napi_ok && napiObj != nullptr && napiObj->GetNativeObj() != nullptr) {
275         auto queryResult = queryFunction(napiObj->GetNativeObj());
276         if constexpr(std::is_same_v<decltype(queryResult), bool>) {
277             napi_get_boolean(env, queryResult, &result);
278         } else if constexpr(std::is_same_v<decltype(queryResult), std::vector<int32_t>>
279                          || std::is_enum_v<typename decltype(queryResult)::value_type>) {
280             status = napi_create_array(env, &result);
281             CHECK_ERROR_RETURN_RET_LOG(status != napi_ok, result, "napi_create_array call Failed!");
282             for (size_t i = 0; i < queryResult.size(); i++) {
283                 int32_t value = queryResult[i];
284                 napi_value element;
285                 napi_create_int32(env, value, &element);
286                 napi_set_element(env, result, i, element);
287             }
288         } else if constexpr(std::is_same_v<decltype(queryResult), std::vector<uint32_t>>) {
289             status = napi_create_array(env, &result);
290             CHECK_ERROR_RETURN_RET_LOG(status != napi_ok, result, "napi_create_array call Failed!");
291             for (size_t i = 0; i < queryResult.size(); i++) {
292                 uint32_t value = queryResult[i];
293                 napi_value element;
294                 napi_create_uint32(env, value, &element);
295                 napi_set_element(env, result, i, element);
296             }
297         } else if constexpr(std::is_same_v<decltype(queryResult), std::vector<float>>) {
298             status = napi_create_array(env, &result);
299             CHECK_ERROR_RETURN_RET_LOG(status != napi_ok, result, "napi_create_array call Failed!");
300             for (size_t i = 0; i < queryResult.size(); i++) {
301                 float value = queryResult[i];
302                 napi_value element;
303                 napi_create_double(env, CameraNapiUtils::FloatToDouble(value), &element);
304                 napi_set_element(env, result, i, element);
305             }
306         } else {
307             MEDIA_ERR_LOG("Unhandled type in HandleQuery");
308         }
309     } else {
310         MEDIA_ERR_LOG("Query function call Failed!");
311     }
312     return result;
313 }
314 
HasFlash(napi_env env,napi_callback_info info)315 napi_value CameraFunctionsNapi::HasFlash(napi_env env, napi_callback_info info)
316 {
317     MEDIA_DEBUG_LOG("HasFlash is called");
318     size_t argc = ARGS_ZERO;
319     napi_value argv[ARGS_ZERO];
320     napi_value thisVar = nullptr;
321     CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
322 
323     return HandleQuery(env, info, thisVar, [](auto ability) {
324         return ability->HasFlash();
325     });
326 }
327 
IsFlashModeSupported(napi_env env,napi_callback_info info)328 napi_value CameraFunctionsNapi::IsFlashModeSupported(napi_env env, napi_callback_info info)
329 {
330     MEDIA_DEBUG_LOG("IsFlashModeSupported is called");
331     size_t argc = ARGS_ONE;
332     napi_value argv[ARGS_ONE];
333     napi_value thisVar = nullptr;
334     CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
335 
336     return HandleQuery(env, info, thisVar, [env, argv](auto ability) {
337         int32_t value;
338         napi_get_value_int32(env, argv[PARAM0], &value);
339         FlashMode flashMode = (FlashMode)value;
340         return ability->IsFlashModeSupported(flashMode);
341     });
342 }
343 
IsLcdFlashSupported(napi_env env,napi_callback_info info)344 napi_value CameraFunctionsNapi::IsLcdFlashSupported(napi_env env, napi_callback_info info)
345 {
346     MEDIA_DEBUG_LOG("IsLcdFlashSupported is called");
347     size_t argc = ARGS_ZERO;
348     napi_value argv[ARGS_ZERO];
349     napi_value thisVar = nullptr;
350     CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
351 
352     return HandleQuery(env, info, thisVar, [env, argv](auto ability) {
353         return ability->IsLcdFlashSupported();
354     });
355 }
356 
IsExposureModeSupported(napi_env env,napi_callback_info info)357 napi_value CameraFunctionsNapi::IsExposureModeSupported(napi_env env, napi_callback_info info)
358 {
359     MEDIA_DEBUG_LOG("IsExposureModeSupported is called");
360     size_t argc = ARGS_ONE;
361     napi_value argv[ARGS_ONE];
362     napi_value thisVar = nullptr;
363     CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
364 
365     return HandleQuery(env, info, thisVar, [env, argv](auto ability) {
366         int32_t value;
367         napi_get_value_int32(env, argv[PARAM0], &value);
368         ExposureMode exposureMode = (ExposureMode)value;
369         return ability->IsExposureModeSupported(exposureMode);
370     });
371 }
372 
GetExposureBiasRange(napi_env env,napi_callback_info info)373 napi_value CameraFunctionsNapi::GetExposureBiasRange(napi_env env, napi_callback_info info)
374 {
375     MEDIA_DEBUG_LOG("GetExposureBiasRange is called");
376     size_t argc = ARGS_ZERO;
377     napi_value argv[ARGS_ZERO];
378     napi_value thisVar = nullptr;
379     CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
380 
381     return HandleQuery(env, info, thisVar, [](auto ability) {
382         return ability->GetExposureBiasRange();
383     });
384 }
385 
IsFocusModeSupported(napi_env env,napi_callback_info info)386 napi_value CameraFunctionsNapi::IsFocusModeSupported(napi_env env, napi_callback_info info)
387 {
388     MEDIA_DEBUG_LOG("IsFocusModeSupported is called");
389     size_t argc = ARGS_ONE;
390     napi_value argv[ARGS_ONE];
391     napi_value thisVar = nullptr;
392     CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
393 
394     return HandleQuery(env, info, thisVar, [env, argv](auto ability) {
395         int32_t value;
396         napi_get_value_int32(env, argv[PARAM0], &value);
397         FocusMode focusMode = (FocusMode)value;
398         return ability->IsFocusModeSupported(focusMode);
399     });
400 }
401 
IsFocusRangeTypeSupported(napi_env env,napi_callback_info info)402 napi_value CameraFunctionsNapi::IsFocusRangeTypeSupported(napi_env env, napi_callback_info info)
403 {
404     MEDIA_DEBUG_LOG("IsFocusRangeTypeSupported is called");
405     size_t argc = ARGS_ONE;
406     napi_value argv[ARGS_ONE];
407     napi_value thisVar = nullptr;
408     CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
409 
410     return HandleQuery(env, info, thisVar, [env, argv](auto ability) {
411         int32_t value = 0;
412         napi_get_value_int32(env, argv[PARAM0], &value);
413         FocusRangeType focusRangeType = static_cast<FocusRangeType>(value);
414         return ability->IsFocusRangeTypeSupported(focusRangeType);
415     });
416 }
417 
IsFocusDrivenTypeSupported(napi_env env,napi_callback_info info)418 napi_value CameraFunctionsNapi::IsFocusDrivenTypeSupported(napi_env env, napi_callback_info info)
419 {
420     MEDIA_DEBUG_LOG("IsFocusDrivenTypeSupported is called");
421     size_t argc = ARGS_ONE;
422     napi_value argv[ARGS_ONE];
423     napi_value thisVar = nullptr;
424     CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
425 
426     return HandleQuery(env, info, thisVar, [env, argv](auto ability) {
427         int32_t value = 0;
428         napi_get_value_int32(env, argv[PARAM0], &value);
429         FocusDrivenType focusDrivenType = static_cast<FocusDrivenType>(value);
430         return ability->IsFocusDrivenTypeSupported(focusDrivenType);
431     });
432 }
433 
GetZoomRatioRange(napi_env env,napi_callback_info info)434 napi_value CameraFunctionsNapi::GetZoomRatioRange(napi_env env, napi_callback_info info)
435 {
436     MEDIA_DEBUG_LOG("GetZoomRatioRange is called");
437     size_t argc = ARGS_ZERO;
438     napi_value argv[ARGS_ZERO];
439     napi_value thisVar = nullptr;
440     CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
441 
442     return HandleQuery(env, info, thisVar, [](auto ability) {
443         return ability->GetZoomRatioRange();
444     });
445 }
446 
GetSupportedBeautyTypes(napi_env env,napi_callback_info info)447 napi_value CameraFunctionsNapi::GetSupportedBeautyTypes(napi_env env, napi_callback_info info)
448 {
449     MEDIA_DEBUG_LOG("GetSupportedBeautyTypes is called");
450     size_t argc = ARGS_ZERO;
451     napi_value argv[ARGS_ZERO];
452     napi_value thisVar = nullptr;
453     CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
454 
455     return HandleQuery(env, info, thisVar, [](auto ability) {
456         return ability->GetSupportedBeautyTypes();
457     });
458 }
459 
GetSupportedBeautyRange(napi_env env,napi_callback_info info)460 napi_value CameraFunctionsNapi::GetSupportedBeautyRange(napi_env env, napi_callback_info info)
461 {
462     MEDIA_DEBUG_LOG("GetSupportedBeautyRange is called");
463     size_t argc = ARGS_ONE;
464     napi_value argv[ARGS_ONE];
465     napi_value thisVar = nullptr;
466     CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
467 
468     return HandleQuery(env, info, thisVar, [env, argv](auto ability) {
469         int32_t value;
470         napi_get_value_int32(env, argv[PARAM0], &value);
471         BeautyType beautyType = (BeautyType)value;
472         return ability->GetSupportedBeautyRange(beautyType);
473     });
474 }
475 
GetSupportedColorEffects(napi_env env,napi_callback_info info)476 napi_value CameraFunctionsNapi::GetSupportedColorEffects(napi_env env, napi_callback_info info)
477 {
478     MEDIA_DEBUG_LOG("GetSupportedColorEffects is called");
479     size_t argc = ARGS_ZERO;
480     napi_value argv[ARGS_ZERO];
481     napi_value thisVar = nullptr;
482     CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
483 
484     return HandleQuery(env, info, thisVar, [](auto ability) {
485         return ability->GetSupportedColorEffects();
486     });
487 }
488 
GetSupportedColorSpaces(napi_env env,napi_callback_info info)489 napi_value CameraFunctionsNapi::GetSupportedColorSpaces(napi_env env, napi_callback_info info)
490 {
491     MEDIA_DEBUG_LOG("GetSupportedColorSpaces is called.");
492     size_t argc = ARGS_ZERO;
493     napi_value argv[ARGS_ZERO];
494     napi_value thisVar = nullptr;
495     CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
496 
497     return HandleQuery(env, info, thisVar, [](auto ability) {
498         return ability->GetSupportedColorSpaces();
499     });
500 }
501 
IsMacroSupported(napi_env env,napi_callback_info info)502 napi_value CameraFunctionsNapi::IsMacroSupported(napi_env env, napi_callback_info info)
503 {
504     size_t argc = ARGS_ZERO;
505     napi_value argv[ARGS_ZERO];
506     napi_value thisVar = nullptr;
507     CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
508 
509     return HandleQuery(env, info, thisVar, [](auto ability) {
510         return ability->IsMacroSupported();
511     });
512 }
513 
IsDepthFusionSupported(napi_env env,napi_callback_info info)514 napi_value CameraFunctionsNapi::IsDepthFusionSupported(napi_env env, napi_callback_info info)
515 {
516     if (!CameraNapiSecurity::CheckSystemApp(env)) {
517         MEDIA_ERR_LOG("SystemApi IsDepthFusionSupported is called!");
518         return nullptr;
519     }
520     napi_value thisVar = nullptr;
521     CameraFunctionsNapi* cameraFunctionsNapi = nullptr;
522     CameraNapiParamParser jsParamParser(env, info, cameraFunctionsNapi);
523     if (!jsParamParser.AssertStatus(INVALID_ARGUMENT, "parse parameter occur error")) {
524         MEDIA_ERR_LOG("CameraFunctionsNapi::IsDepthFusionSupported parse parameter occur error");
525         return nullptr;
526     }
527     thisVar = jsParamParser.GetThisVar();
528 
529     return HandleQuery(env, info, thisVar, [](auto ability) {
530         return ability->IsDepthFusionSupported();
531     });
532 }
533 
GetDepthFusionThreshold(napi_env env,napi_callback_info info)534 napi_value CameraFunctionsNapi::GetDepthFusionThreshold(napi_env env, napi_callback_info info)
535 {
536     if (!CameraNapiSecurity::CheckSystemApp(env)) {
537         MEDIA_ERR_LOG("SystemApi GetDepthFusionThreshold is called!");
538         return nullptr;
539     }
540     napi_value thisVar = nullptr;
541     CameraFunctionsNapi* cameraFunctionsNapi = nullptr;
542     CameraNapiParamParser jsParamParser(env, info, cameraFunctionsNapi);
543     if (!jsParamParser.AssertStatus(INVALID_ARGUMENT, "parse parameter occur error")) {
544         MEDIA_ERR_LOG("CameraFunctionsNapi::GetDepthFusionThreshold parse parameter occur error");
545         return nullptr;
546     }
547     thisVar = jsParamParser.GetThisVar();
548 
549     return HandleQuery(env, info, thisVar, [](auto ability) {
550         return ability->GetDepthFusionThreshold();
551     });
552 }
553 
GetSupportedPortraitEffects(napi_env env,napi_callback_info info)554 napi_value CameraFunctionsNapi::GetSupportedPortraitEffects(napi_env env, napi_callback_info info)
555 {
556     size_t argc = ARGS_ZERO;
557     napi_value argv[ARGS_ZERO];
558     napi_value thisVar = nullptr;
559     CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
560 
561     return HandleQuery(env, info, thisVar, [](auto ability) {
562         return ability->GetSupportedPortraitEffects();
563     });
564 }
565 
GetSupportedVirtualApertures(napi_env env,napi_callback_info info)566 napi_value CameraFunctionsNapi::GetSupportedVirtualApertures(napi_env env, napi_callback_info info)
567 {
568     size_t argc = ARGS_ZERO;
569     napi_value argv[ARGS_ZERO];
570     napi_value thisVar = nullptr;
571     CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
572 
573     return HandleQuery(env, info, thisVar, [](auto ability) {
574         return ability->GetSupportedVirtualApertures();
575     });
576 }
577 
GetSupportedPhysicalApertures(napi_env env,napi_callback_info info)578 napi_value CameraFunctionsNapi::GetSupportedPhysicalApertures(napi_env env, napi_callback_info info)
579 {
580     MEDIA_DEBUG_LOG("GetSupportedPhysicalApertures is called");
581     size_t argc = ARGS_ZERO;
582     napi_value argv[ARGS_ZERO];
583     napi_value thisVar = nullptr;
584     CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
585 
586     napi_status status;
587     napi_value result = nullptr;
588     napi_get_undefined(env, &result);
589     status = napi_create_array(env, &result);
590     if (status != napi_ok) {
591         MEDIA_ERR_LOG("napi_create_array call Failed!");
592         return result;
593     }
594     CameraFunctionsNapi*  cameraAbilityNapi = nullptr;
595     status = napi_unwrap(env, thisVar, reinterpret_cast<void**>(&cameraAbilityNapi));
596     if (status == napi_ok && cameraAbilityNapi != nullptr && cameraAbilityNapi->GetNativeObj() !=nullptr) {
597         std::vector<std::vector<float>> physicalApertures =
598             cameraAbilityNapi->GetNativeObj()->GetSupportedPhysicalApertures();
599         MEDIA_INFO_LOG("GetSupportedPhysicalApertures len = %{public}zu", physicalApertures.size());
600         if (!physicalApertures.empty()) {
601             result = CameraNapiUtils::ProcessingPhysicalApertures(env, physicalApertures);
602         }
603     } else {
604         MEDIA_ERR_LOG("GetSupportedPhysicalApertures call Failed!");
605     }
606     return result;
607 }
608 
IsVideoStabilizationModeSupported(napi_env env,napi_callback_info info)609 napi_value CameraFunctionsNapi::IsVideoStabilizationModeSupported(napi_env env, napi_callback_info info)
610 {
611     MEDIA_DEBUG_LOG("IsVideoStabilizationModeSupported is called");
612     size_t argc = ARGS_ONE;
613     napi_value argv[ARGS_ONE];
614     napi_value thisVar = nullptr;
615     CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
616 
617     return HandleQuery(env, info, thisVar, [env, argv](auto ability) {
618         int32_t value;
619         napi_get_value_int32(env, argv[PARAM0], &value);
620         VideoStabilizationMode stabilizationMode = (VideoStabilizationMode)value;
621         return ability->IsVideoStabilizationModeSupported(stabilizationMode);
622     });
623 }
624 
GetSupportedExposureRange(napi_env env,napi_callback_info info)625 napi_value CameraFunctionsNapi::GetSupportedExposureRange(napi_env env, napi_callback_info info)
626 {
627     MEDIA_DEBUG_LOG("GetSupportedExposureRange is called");
628     size_t argc = ARGS_ZERO;
629     napi_value argv[ARGS_ZERO];
630     napi_value thisVar = nullptr;
631     CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
632 
633     return HandleQuery(env, info, thisVar, [](auto ability) {
634         return ability->GetSupportedExposureRange();
635     });
636 }
637 
IsFeatureSupported(napi_env env,napi_callback_info info)638 napi_value CameraFunctionsNapi::IsFeatureSupported(napi_env env, napi_callback_info info)
639 {
640     MEDIA_DEBUG_LOG("IsFeatureSupported is called");
641     size_t argc = ARGS_ONE;
642     napi_value argv[ARGS_ONE];
643     napi_value thisVar = nullptr;
644     CAMERA_NAPI_GET_JS_ARGS(env, info, argc, argv, thisVar);
645 
646     return HandleQuery(env, info, thisVar, [env, argv](auto ability) {
647         int32_t value;
648         napi_get_value_int32(env, argv[PARAM0], &value);
649         SceneFeature sceneFeature = (SceneFeature)value;
650         return ability->IsFeatureSupported(sceneFeature);
651     });
652 }
653 } // namespace CameraStandard
654 } // namespace OHOS