1 /*
2 * Copyright (C) 2025 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 "shooting_mode_column.h"
17
18 #include <string>
19
20 #include "abs_rdb_predicates.h"
21 #include "datashare_predicates.h"
22 #include "media_column.h"
23 #include "media_log.h"
24 #include "medialibrary_type_const.h"
25 #include "photo_album_column.h"
26 #include "photo_map_column.h"
27 #include "photo_query_filter.h"
28 #include "value_object.h"
29 #include "vision_column.h"
30
31 namespace OHOS::Media {
32 using namespace std;
33 using namespace NativeRdb;
34
35 template <class T>
GetMovingPhotoAlbumPredicates(T & predicates,const bool hiddenState)36 void ShootingModeAlbum::GetMovingPhotoAlbumPredicates(T& predicates, const bool hiddenState)
37 {
38 PhotoQueryFilter::Config config {};
39 config.hiddenConfig = hiddenState ? PhotoQueryFilter::ConfigType::INCLUDE : PhotoQueryFilter::ConfigType::EXCLUDE;
40 PhotoQueryFilter::ModifyPredicate(config, predicates);
41 predicates.BeginWrap();
42 predicates.EqualTo(PhotoColumn::PHOTO_SUBTYPE, to_string(static_cast<int32_t>(PhotoSubType::MOVING_PHOTO)));
43 predicates.Or();
44 predicates.BeginWrap();
45 predicates.EqualTo(PhotoColumn::MOVING_PHOTO_EFFECT_MODE,
46 to_string(static_cast<int32_t>(MovingPhotoEffectMode::IMAGE_ONLY)));
47 predicates.EqualTo(PhotoColumn::PHOTO_SUBTYPE, to_string(static_cast<int32_t>(PhotoSubType::DEFAULT)));
48 predicates.EndWrap();
49 predicates.EndWrap();
50 }
51
52 template <class T>
GetBurstModeAlbumPredicates(T & predicates,const bool hiddenState)53 void ShootingModeAlbum::GetBurstModeAlbumPredicates(T& predicates, const bool hiddenState)
54 {
55 PhotoQueryFilter::Config config {};
56 config.hiddenConfig = hiddenState ? PhotoQueryFilter::ConfigType::INCLUDE : PhotoQueryFilter::ConfigType::EXCLUDE;
57 PhotoQueryFilter::ModifyPredicate(config, predicates);
58 predicates.EqualTo(PhotoColumn::PHOTO_SUBTYPE, to_string(static_cast<int32_t>(PhotoSubType::BURST)));
59 predicates.IsNotNull(PhotoColumn::PHOTO_BURST_KEY);
60 }
61
62 template <class T>
GetFrontCameraAlbumPredicates(T & predicates,const bool hiddenState)63 void ShootingModeAlbum::GetFrontCameraAlbumPredicates(T& predicates, const bool hiddenState)
64 {
65 PhotoQueryFilter::Config config {};
66 config.hiddenConfig = hiddenState ? PhotoQueryFilter::ConfigType::INCLUDE : PhotoQueryFilter::ConfigType::EXCLUDE;
67 PhotoQueryFilter::ModifyPredicate(config, predicates);
68 predicates.EqualTo(PhotoColumn::PHOTO_FRONT_CAMERA, to_string(1));
69 }
70
71 template <class T>
GetRAWImageAlbumPredicates(T & predicates,const bool hiddenState)72 void ShootingModeAlbum::GetRAWImageAlbumPredicates(T& predicates, const bool hiddenState)
73 {
74 const string rawImageMimeType = "image/x-adobe-dng";
75 PhotoQueryFilter::Config config {};
76 config.hiddenConfig = hiddenState ? PhotoQueryFilter::ConfigType::INCLUDE : PhotoQueryFilter::ConfigType::EXCLUDE;
77 PhotoQueryFilter::ModifyPredicate(config, predicates);
78 predicates.EqualTo(MediaColumn::MEDIA_MIME_TYPE, rawImageMimeType);
79 }
80
81 template <class T>
GetGeneralShootingModeAlbumPredicates(const ShootingModeAlbumType type,T & predicates,const bool hiddenState)82 void ShootingModeAlbum::GetGeneralShootingModeAlbumPredicates(const ShootingModeAlbumType type,
83 T& predicates, const bool hiddenState)
84 {
85 PhotoQueryFilter::Config config {};
86 config.hiddenConfig = hiddenState ? PhotoQueryFilter::ConfigType::INCLUDE : PhotoQueryFilter::ConfigType::EXCLUDE;
87 PhotoQueryFilter::ModifyPredicate(config, predicates);
88 predicates.EqualTo(PhotoColumn::PHOTO_SHOOTING_MODE, to_string(static_cast<int32_t>(type)));
89 }
90
91 template <class T>
GetShootingModeAlbumPredicates(const ShootingModeAlbumType type,T & predicates,const bool hiddenState)92 void ShootingModeAlbum::GetShootingModeAlbumPredicates(const ShootingModeAlbumType type,
93 T& predicates, const bool hiddenState)
94 {
95 switch (type) {
96 case ShootingModeAlbumType::MOVING_PICTURE: {
97 GetMovingPhotoAlbumPredicates(predicates, hiddenState);
98 return;
99 }
100 case ShootingModeAlbumType::BURST_MODE_ALBUM: {
101 GetBurstModeAlbumPredicates(predicates, hiddenState);
102 return;
103 }
104 case ShootingModeAlbumType::FRONT_CAMERA_ALBUM: {
105 GetFrontCameraAlbumPredicates(predicates, hiddenState);
106 return;
107 }
108 case ShootingModeAlbumType::RAW_IMAGE_ALBUM: {
109 GetRAWImageAlbumPredicates(predicates, hiddenState);
110 return;
111 }
112 default: {
113 GetGeneralShootingModeAlbumPredicates(type, predicates, hiddenState);
114 return;
115 }
116 }
117 }
118
AlbumNameToShootingModeAlbumType(const std::string & albumName,ShootingModeAlbumType & parseResult)119 bool ShootingModeAlbum::AlbumNameToShootingModeAlbumType(const std::string& albumName,
120 ShootingModeAlbumType& parseResult)
121 {
122 int32_t albumValue = atoi(albumName.c_str());
123 if (albumValue < static_cast<int32_t>(ShootingModeAlbumType::START) ||
124 albumValue > static_cast<int32_t>(ShootingModeAlbumType::END)) {
125 MEDIA_ERR_LOG("album name can not be converted to shooting mode album type, input: %{public}s",
126 albumName.c_str());
127 return false;
128 }
129 parseResult = static_cast<ShootingModeAlbumType>(albumValue);
130 return true;
131 }
132
GetQueryAssetsIndex(const ShootingModeAlbumType type)133 string ShootingModeAlbum::GetQueryAssetsIndex(const ShootingModeAlbumType type)
134 {
135 static const std::unordered_map<ShootingModeAlbumType, std::string> SHOOTING_MODE_INDEX_MAP = {
136 {ShootingModeAlbumType::PORTRAIT, PhotoColumn::PHOTO_SHOOTING_MODE_ALBUM_GENERAL_INDEX},
137 {ShootingModeAlbumType::WIDE_APERTURE, PhotoColumn::PHOTO_SHOOTING_MODE_ALBUM_GENERAL_INDEX},
138 {ShootingModeAlbumType::NIGHT_SHOT, PhotoColumn::PHOTO_SHOOTING_MODE_ALBUM_GENERAL_INDEX},
139 {ShootingModeAlbumType::MOVING_PICTURE, PhotoColumn::PHOTO_MOVING_PHOTO_ALBUM_INDEX},
140 {ShootingModeAlbumType::PRO_PHOTO, PhotoColumn::PHOTO_SHOOTING_MODE_ALBUM_GENERAL_INDEX},
141 {ShootingModeAlbumType::SLOW_MOTION, PhotoColumn::PHOTO_SHOOTING_MODE_ALBUM_GENERAL_INDEX},
142 {ShootingModeAlbumType::LIGHT_PAINTING, PhotoColumn::PHOTO_SHOOTING_MODE_ALBUM_GENERAL_INDEX},
143 {ShootingModeAlbumType::HIGH_PIXEL, PhotoColumn::PHOTO_SHOOTING_MODE_ALBUM_GENERAL_INDEX},
144 {ShootingModeAlbumType::SUPER_MACRO, PhotoColumn::PHOTO_SHOOTING_MODE_ALBUM_GENERAL_INDEX},
145 {ShootingModeAlbumType::PANORAMA_MODE, PhotoColumn::PHOTO_SHOOTING_MODE_ALBUM_GENERAL_INDEX},
146 {ShootingModeAlbumType::BURST_MODE_ALBUM, PhotoColumn::PHOTO_BURST_MODE_ALBUM_INDEX},
147 {ShootingModeAlbumType::FRONT_CAMERA_ALBUM, PhotoColumn::PHOTO_FRONT_CAMERA_ALBUM_INDEX},
148 {ShootingModeAlbumType::RAW_IMAGE_ALBUM, PhotoColumn::PHOTO_RAW_IMAGE_ALBUM_INDEX},
149 };
150 if (SHOOTING_MODE_INDEX_MAP.find(type) == SHOOTING_MODE_INDEX_MAP.end()) {
151 MEDIA_ERR_LOG("Shooting mode type %{public}d is not in the map", static_cast<int32_t>(type));
152 return "";
153 }
154 return SHOOTING_MODE_INDEX_MAP.at(type);
155 }
156
IsAssetInMovingPhotoAlbum(int32_t photoSubType,int32_t movingPhotoEffectMode)157 bool ShootingModeAlbum::IsAssetInMovingPhotoAlbum(int32_t photoSubType, int32_t movingPhotoEffectMode)
158 {
159 return photoSubType == static_cast<int32_t>(PhotoSubType::MOVING_PHOTO) ||
160 (photoSubType == static_cast<int32_t>(PhotoSubType::DEFAULT) &&
161 movingPhotoEffectMode == static_cast<int32_t>(MovingPhotoEffectMode::IMAGE_ONLY));
162 }
163
GetShootingModeAlbumOfAsset(int32_t photoSubType,const string & mimetype,int32_t movingPhotoEffectMode,const string & frontCamera,const string & shootingMode)164 vector<ShootingModeAlbumType> ShootingModeAlbum::GetShootingModeAlbumOfAsset(int32_t photoSubType,
165 const string& mimetype, int32_t movingPhotoEffectMode, const string& frontCamera, const string& shootingMode)
166 {
167 vector<ShootingModeAlbumType> result;
168 if (photoSubType == static_cast<int32_t>(PhotoSubType::BURST)) {
169 result.push_back(ShootingModeAlbumType::BURST_MODE_ALBUM);
170 }
171 if (mimetype == "image/x-adobe-dng") {
172 result.push_back(ShootingModeAlbumType::RAW_IMAGE_ALBUM);
173 }
174 if (IsAssetInMovingPhotoAlbum(photoSubType, movingPhotoEffectMode)) {
175 result.push_back(ShootingModeAlbumType::MOVING_PICTURE);
176 }
177 if (frontCamera == "1") { // "1" means photo is taken using front camera
178 result.push_back(ShootingModeAlbumType::FRONT_CAMERA_ALBUM);
179 }
180 if (!shootingMode.empty()) {
181 ShootingModeAlbumType type;
182 if (AlbumNameToShootingModeAlbumType(shootingMode, type) &&
183 type != ShootingModeAlbumType::MOVING_PICTURE &&
184 type != ShootingModeAlbumType::BURST_MODE_ALBUM &&
185 type != ShootingModeAlbumType::FRONT_CAMERA_ALBUM &&
186 type != ShootingModeAlbumType::RAW_IMAGE_ALBUM) {
187 result.push_back(type);
188 }
189 }
190 return result;
191 }
192
MapShootingModeTagToShootingMode(const string & tag)193 string ShootingModeAlbum::MapShootingModeTagToShootingMode(const string& tag)
194 {
195 static const std::unordered_map<std::string, std::string> SHOOTING_MODE_CAST_MAP = {
196 {PORTRAIT_ALBUM_TAG, to_string(static_cast<int>(ShootingModeAlbumType::PORTRAIT))},
197 {WIDE_APERTURE_ALBUM_TAG, to_string(static_cast<int>(ShootingModeAlbumType::WIDE_APERTURE))},
198 {NIGHT_SHOT_ALBUM_TAG, to_string(static_cast<int>(ShootingModeAlbumType::NIGHT_SHOT))},
199 {REAR_CAMERA_NIGHT_SHOT_TAG, to_string(static_cast<int>(ShootingModeAlbumType::NIGHT_SHOT))},
200 {MOVING_PICTURE_ALBUM_TAG, to_string(static_cast<int>(ShootingModeAlbumType::MOVING_PICTURE))},
201 {PRO_PHOTO_ALBUM_TAG, to_string(static_cast<int>(ShootingModeAlbumType::PRO_PHOTO))},
202 {TAIL_LIGHT_ALBUM_TAG, to_string(static_cast<int>(ShootingModeAlbumType::LIGHT_PAINTING))},
203 {LIGHT_GRAFFITI_TAG, to_string(static_cast<int>(ShootingModeAlbumType::LIGHT_PAINTING))},
204 {SILKY_WATER_TAG, to_string(static_cast<int>(ShootingModeAlbumType::LIGHT_PAINTING))},
205 {STAR_TRACK_TAG, to_string(static_cast<int>(ShootingModeAlbumType::LIGHT_PAINTING))},
206 {AI_HIGH_PIXEL_TAG, to_string(static_cast<int>(ShootingModeAlbumType::HIGH_PIXEL))},
207 {HIGH_PIXEL_ALBUM_TAG, to_string(static_cast<int>(ShootingModeAlbumType::HIGH_PIXEL))},
208 {SUPER_MACRO_ALBUM_TAG, to_string(static_cast<int>(ShootingModeAlbumType::SUPER_MACRO))},
209 {SLOW_MOTION_ALBUM_TAG, to_string(static_cast<int>(ShootingModeAlbumType::SLOW_MOTION))},
210 {SUPER_SLOW_MOTION_ALBUM_TAG, to_string(static_cast<int>(ShootingModeAlbumType::SLOW_MOTION))},
211 {CAMERA_CUSTOM_SM_PANORAMA, to_string(static_cast<int>(ShootingModeAlbumType::PANORAMA_MODE))},
212 {CAMERA_CUSTOM_SM_PHOTO_STITCHING, to_string(static_cast<int>(ShootingModeAlbumType::PANORAMA_MODE))},
213 };
214
215 auto it = SHOOTING_MODE_CAST_MAP.find(tag);
216 if (it != SHOOTING_MODE_CAST_MAP.end()) {
217 return it->second;
218 }
219 return "";
220 }
221
222 template void ShootingModeAlbum::GetMovingPhotoAlbumPredicates<DataShare::DataSharePredicates>(
223 DataShare::DataSharePredicates& predicates, const bool hiddenState);
224
225 template void ShootingModeAlbum::GetMovingPhotoAlbumPredicates<NativeRdb::RdbPredicates>(
226 NativeRdb::RdbPredicates& predicates, const bool hiddenState);
227
228 template void ShootingModeAlbum::GetBurstModeAlbumPredicates<DataShare::DataSharePredicates>(
229 DataShare::DataSharePredicates& predicates, const bool hiddenState);
230
231 template void ShootingModeAlbum::GetBurstModeAlbumPredicates<NativeRdb::RdbPredicates>(
232 NativeRdb::RdbPredicates& predicates, const bool hiddenState);
233
234 template void ShootingModeAlbum::GetFrontCameraAlbumPredicates<DataShare::DataSharePredicates>(
235 DataShare::DataSharePredicates& predicates, const bool hiddenState);
236
237 template void ShootingModeAlbum::GetFrontCameraAlbumPredicates<NativeRdb::RdbPredicates>(
238 NativeRdb::RdbPredicates& predicates, const bool hiddenState);
239
240 template void ShootingModeAlbum::GetRAWImageAlbumPredicates<DataShare::DataSharePredicates>(
241 DataShare::DataSharePredicates& predicates, const bool hiddenState);
242
243 template void ShootingModeAlbum::GetRAWImageAlbumPredicates<NativeRdb::RdbPredicates>(
244 NativeRdb::RdbPredicates& predicates, const bool hiddenState);
245
246 template void ShootingModeAlbum::GetGeneralShootingModeAlbumPredicates<DataShare::DataSharePredicates>(
247 const ShootingModeAlbumType type, DataShare::DataSharePredicates& predicates, const bool hiddenState);
248
249 template void ShootingModeAlbum::GetGeneralShootingModeAlbumPredicates<NativeRdb::RdbPredicates>(
250 const ShootingModeAlbumType type, NativeRdb::RdbPredicates& predicates, const bool hiddenState);
251
252 template void ShootingModeAlbum::GetShootingModeAlbumPredicates<DataShare::DataSharePredicates>(
253 const ShootingModeAlbumType type, DataShare::DataSharePredicates& predicates, const bool hiddenState);
254
255 template void ShootingModeAlbum::GetShootingModeAlbumPredicates<NativeRdb::RdbPredicates>(
256 const ShootingModeAlbumType type, NativeRdb::RdbPredicates& predicates, const bool hiddenState);
257
258 } // namespace OHOS::Media