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_CAPTURE_SCENE_CONST_H
17 #define OHOS_CAMERA_CAPTURE_SCENE_CONST_H
18 
19 #include <cstdint>
20 #include <set>
21 #include <sstream>
22 
23 namespace OHOS {
24 namespace CameraStandard {
25 enum JsSceneMode : int32_t {
26     JS_NORMAL = 0,
27     JS_CAPTURE = 1,
28     JS_VIDEO = 2,
29     JS_PORTRAIT = 3,
30     JS_NIGHT = 4,
31     JS_PROFESSIONAL_PHOTO = 5,
32     JS_PROFESSIONAL_VIDEO = 6,
33     JS_SLOW_MOTION = 7,
34     JS_CAPTURE_MARCO = 8,
35     JS_VIDEO_MARCO = 9,
36     JS_LIGHT_PAINTING = 10,
37     JS_HIGH_RES_PHOTO = 11,
38     JS_SECURE_CAMERA = 12,
39     JS_QUICK_SHOT_PHOTO = 13,
40     JS_APERTURE_VIDEO = 14,
41     JS_PANORAMA_PHOTO = 15,
42     JS_TIMELAPSE_PHOTO = 16,
43     JS_FLUORESCENCE_PHOTO = 17,
44 };
45 
46 enum SceneMode : int32_t {
47     NORMAL = 0,
48     CAPTURE = 1,
49     VIDEO = 2,
50     PORTRAIT = 3,
51     NIGHT = 4,
52     PROFESSIONAL = 5,
53     SLOW_MOTION = 6,
54     SCAN = 7,
55     CAPTURE_MACRO = 8,
56     VIDEO_MACRO = 9,
57     PROFESSIONAL_PHOTO = 11,
58     PROFESSIONAL_VIDEO = 12,
59     HIGH_FRAME_RATE = 13,
60     HIGH_RES_PHOTO = 14,
61     SECURE = 15,
62     QUICK_SHOT_PHOTO = 16,
63     LIGHT_PAINTING = 17,
64     PANORAMA_PHOTO = 18,
65     TIMELAPSE_PHOTO = 19,
66     APERTURE_VIDEO = 20,
67     FLUORESCENCE_PHOTO = 21,
68 };
69 
70 enum SceneFeature : int32_t {
71     FEATURE_ENUM_MIN = 0,
72     FEATURE_MOON_CAPTURE_BOOST = 0,
73     FEATURE_TRIPOD_DETECTION,
74     FEATURE_LOW_LIGHT_BOOST,
75     FEATURE_MACRO,
76     FEATURE_ENUM_MAX
77 };
78 
79 enum class JsPolicyType : int32_t {
80     JS_PRIVACY = 1,
81 };
82 
83 struct SceneFeaturesMode {
84 public:
85     SceneFeaturesMode() = default;
SceneFeaturesModeSceneFeaturesMode86     SceneFeaturesMode(SceneMode sceneMode, std::set<SceneFeature> sceneFeatures)
87     {
88         sceneMode_ = sceneMode;
89         sceneFeatures_ = sceneFeatures;
90     }
91 
IsEnableFeatureSceneFeaturesMode92     bool IsEnableFeature(SceneFeature sceneFeature) const
93     {
94         auto it = sceneFeatures_.find(sceneFeature);
95         if (it == sceneFeatures_.end()) {
96             return false;
97         }
98         return true;
99     }
100 
SwitchFeatureSceneFeaturesMode101     void SwitchFeature(SceneFeature sceneFeature, bool enable)
102     {
103         if (enable) {
104             sceneFeatures_.insert(sceneFeature);
105         } else {
106             sceneFeatures_.erase(sceneFeature);
107         }
108     }
109 
SetSceneModeSceneFeaturesMode110     void SetSceneMode(SceneMode sceneMode)
111     {
112         sceneMode_ = sceneMode;
113     }
114 
GetSceneModeSceneFeaturesMode115     SceneMode GetSceneMode() const
116     {
117         return sceneMode_;
118     }
119 
GetFeaturedModeSceneFeaturesMode120     SceneMode GetFeaturedMode() const
121     {
122         if (IsEnableFeature(FEATURE_MACRO)) {
123             if (sceneMode_ == CAPTURE) {
124                 return CAPTURE_MACRO;
125             } else if (sceneMode_ == VIDEO) {
126                 return VIDEO_MACRO;
127             }
128         }
129         return sceneMode_;
130     }
131 
GetFeaturesSceneFeaturesMode132     std::set<SceneFeature> GetFeatures() const
133     {
134         return sceneFeatures_;
135     }
136 
137     bool operator<(const SceneFeaturesMode& sceneFeaturesMode) const
138     {
139         if (sceneMode_ < sceneFeaturesMode.sceneMode_) {
140             return true;
141         } else if (sceneMode_ > sceneFeaturesMode.sceneMode_) {
142             return false;
143         }
144         return sceneFeatures_ < sceneFeaturesMode.sceneFeatures_;
145     }
146 
147     bool operator==(const SceneFeaturesMode& sceneFeaturesMode) const
148     {
149         return sceneMode_ == sceneFeaturesMode.sceneMode_ && sceneFeatures_ == sceneFeaturesMode.sceneFeatures_;
150     }
151 
DumpSceneFeaturesMode152     std::string Dump()
153     {
154         std::stringstream stringStream;
155         stringStream << "SceneMode:" << sceneMode_;
156         stringStream << "..Features:";
157         stringStream << "[";
158         bool isFirstElement = true;
159         auto featuresIt = sceneFeatures_.begin();
160         while (featuresIt != sceneFeatures_.end()) {
161             if (isFirstElement) {
162                 stringStream << *featuresIt;
163                 isFirstElement = false;
164             } else {
165                 stringStream << "," << *featuresIt;
166             }
167             featuresIt++;
168         }
169         stringStream << "]";
170         return stringStream.str();
171     }
172 
173 private:
174     SceneMode sceneMode_ = NORMAL;
175     std::set<SceneFeature> sceneFeatures_;
176 };
177 } // namespace CameraStandard
178 } // namespace OHOS
179 #endif