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 #ifndef OHOS_CAMERA_CAMERA_ABILITY_H
17 #define OHOS_CAMERA_CAMERA_ABILITY_H
18 
19 #include "refbase.h"
20 #include <map>
21 #include <vector>
22 #include <cstdint>
23 #include "ability/camera_ability_const.h"
24 #include "session/capture_scene_const.h"
25 
26 namespace OHOS {
27 namespace CameraStandard {
28 
29 class CameraAbility : public RefBase {
30 public:
31     CameraAbility() = default;
32     virtual ~CameraAbility() = default;
33     void DumpCameraAbilityInfo();
34 
35     bool HasFlash();
36     bool IsFlashModeSupported(FlashMode flashMode);
37     std::vector<FlashMode> GetSupportedFlashModes();
38     bool IsExposureModeSupported(ExposureMode exposureMode);
39     std::vector<ExposureMode> GetSupportedExposureModes();
40     std::vector<float> GetExposureBiasRange();
41     std::vector<FocusMode> GetSupportedFocusModes();
42     bool IsFocusModeSupported(FocusMode focusMode);
43     std::vector<float> GetZoomRatioRange();
44     std::vector<BeautyType> GetSupportedBeautyTypes();
45     std::vector<int32_t> GetSupportedBeautyRange(BeautyType type);
46     std::vector<ColorEffect> GetSupportedColorEffects();
47     std::vector<ColorSpace> GetSupportedColorSpaces();
48     bool IsMacroSupported();
49     bool IsDepthFusionSupported();
50     std::vector<float> GetDepthFusionThreshold();
51     std::vector<PortraitEffect> GetSupportedPortraitEffects();
52     std::vector<float> GetSupportedVirtualApertures();
53     std::vector<std::vector<float>> GetSupportedPhysicalApertures();
54     std::vector<VideoStabilizationMode> GetSupportedStabilizationMode();
55     bool IsVideoStabilizationModeSupported(VideoStabilizationMode stabilizationMode);
56     std::vector<uint32_t> GetSupportedExposureRange();
57     bool IsFeatureSupported(SceneFeature sceneFeature);
58     bool IsLcdFlashSupported();
59 
60     std::vector<FlashMode> supportedFlashModes_;
61     std::vector<ExposureMode> supportedExposureModes_;
62     std::vector<float> exposureBiasRange_;
63     std::vector<FocusMode> supportedFocusModes_;
64     std::vector<BeautyType> supportedBeautyTypes_;
65     std::map<BeautyType, std::vector<int32_t>> supportedBeautyRangeMap_;
66     std::vector<ColorEffect> supportedColorEffects_;
67     std::vector<ColorSpace> supportedColorSpaces_;
68     std::vector<PortraitEffect> supportedPortraitEffects_;
69     std::vector<float> supportedVirtualApertures_;
70     std::vector<std::vector<float>> supportedPhysicalApertures_;
71     std::vector<VideoStabilizationMode> supportedVideoStabilizationMode_;
72     std::vector<uint32_t> supportedExposureRange_;
73     std::vector<SceneFeature> supportedSceneFeature_;
74     bool isLcdFlashSupported_;
75 
76     std::optional<std::vector<float>> zoomRatioRange_;
77     std::optional<bool> isMacroSupported_;
78     std::optional<bool> isDepthFusionSupported_;
79     std::optional<std::vector<float>> getDepthFusionThreshold_;
80 };
81 
82 class CaptureSession;
83 class CameraAbilityContainer : public RefBase {
84 public:
85     ~CameraAbilityContainer();
86     void PrepareSpecMaximumValue(std::vector<sptr<CameraAbility>>& abilities);
87 
88     CameraAbilityContainer(std::vector<sptr<CameraAbility>> abilities,
89                            std::vector<sptr<CameraAbility>> conflictAbilities,
90                            wptr<CaptureSession> session);
91     void FilterByZoomRatio(float zoomRatio);
92     void FilterByMacro(bool enableMacro);
93     std::vector<float> GetZoomRatioRange();
94     bool IsMacroSupported();
95 
96 private:
97 
98     void OnAbilityChange();
99 
100 private:
101     wptr<CaptureSession> session_;
102     std::vector<sptr<CameraAbility>> conflictAbilities_;
103 
104     bool IsMacroSupportedInSpec_ = false;
105     std::vector<float> zoomRatioRangeInSpec_;
106 
107     std::optional<std::vector<float>> lastGetZoomRatioRange_;
108     std::optional<bool> lastIsMacroSupported_;
109 
110     std::optional<float> zoomRatioSet_;
111     std::optional<bool> enableMacroSet_;
112 };
113 } // namespace CameraStandard
114 } // namespace OHOS
115 #endif // OHOS_CAMERA_CAMERA_ABILITY_H