• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 FRAMEWORKS_SERVICES_THUMBNAIL_SERVICE_INCLUDE_THUMBNAIL_CONST_H_
17 #define FRAMEWORKS_SERVICES_THUMBNAIL_SERVICE_INCLUDE_THUMBNAIL_CONST_H_
18 
19 #include "medialibrary_db_const.h"
20 
21 #include <unordered_map>
22 #include <unordered_set>
23 
24 namespace OHOS {
25 namespace Media {
26 constexpr int32_t THUMBNAIL_VERSION = 0;
27 constexpr int32_t DEFAULT_YEAR_SIZE = 64;
28 constexpr int32_t DEFAULT_MTH_SIZE = 128;
29 constexpr int32_t DEFAULT_THUMB_SIZE = 256;
30 constexpr int32_t MAX_DEFAULT_THUMB_SIZE = 768;
31 constexpr int32_t DEFAULT_LCD_SIZE = 1080;
32 constexpr uint32_t INT32_MAX_VALUE_LENGTH = 10;
33 constexpr int32_t VERTICAL_ANGLE = 90;
34 constexpr int32_t STRAIGHT_ANGLE = 180;
35 enum class ThumbnailType : int32_t {
36     LCD,
37     THUMB,
38     MTH,
39     YEAR,
40     THUMB_ASTC,
41     MTH_ASTC,
42     YEAR_ASTC,
43     LCD_EX,
44     THUMB_EX,
45 };
46 
47 enum class GenerateScene : int32_t {
48     LOCAL = 0,
49     CLOUD,
50     BACKGROUND,
51     FOREGROUND,
52     RESTORE,
53     UPGRADE,
54 };
55 
56 enum class LoadSourceType : int32_t {
57     LOCAL_PHOTO = 0,
58     CLOUD_THUMB,
59     CLOUD_LCD,
60     CLOUD_PHOTO,
61 };
62 
63 enum class ThumbnailReady : int32_t {
64     GENERATE_THUMB_LATER,
65     GENERATE_THUMB_NOW,
66     GENERATE_THUMB_RETRY,
67     GENERATE_THUMB_COMPLETED,
68     THUMB_TO_UPLOAD,
69     THUMB_UPLOAD_COMPLETED,
70     THUMB_UPGRADE,
71 };
72 
73 enum class LcdReady : int64_t {
74     GENERATE_LCD_LATER,
75     GENERATE_LCD_FAILED,
76     GENERATE_LCD_COMPLETED,
77 };
78 
79 const std::unordered_map<ThumbnailType, std::string> TYPE_NAME_MAP = {
80     { ThumbnailType::LCD, "LCD" },
81     { ThumbnailType::THUMB, "THUMB" },
82     { ThumbnailType::MTH, "MTH" },
83     { ThumbnailType::YEAR, "YEAR" },
84     { ThumbnailType::THUMB_ASTC, "THUMB_ASTC" },
85     { ThumbnailType::MTH_ASTC, "MTH_ASTC" },
86     { ThumbnailType::YEAR_ASTC, "YEAR_ASTC" },
87 };
88 
89 constexpr uint32_t DEVICE_UDID_LENGTH = 65;
90 
91 constexpr int32_t THUMBNAIL_LCD_GENERATE_THRESHOLD = 5000;
92 constexpr int32_t THUMBNAIL_LCD_AGING_THRESHOLD = 10000;
93 constexpr int32_t WAIT_FOR_MS = 1000;
94 constexpr int32_t WAIT_FOR_SECOND = 3;
95 
96 constexpr float EPSILON = 1e-6;
97 constexpr int32_t SHORT_SIDE_THRESHOLD = 350;
98 constexpr int32_t MAXIMUM_SHORT_SIDE_THRESHOLD = 1050;
99 constexpr int32_t LCD_SHORT_SIDE_THRESHOLD = 512;
100 constexpr int32_t LCD_LONG_SIDE_THRESHOLD = 1920;
101 constexpr int32_t MAXIMUM_LCD_LONG_SIDE = 4096;
102 constexpr int32_t ASPECT_RATIO_THRESHOLD = 3;
103 constexpr int32_t MIN_COMPRESS_BUF_SIZE = 8192;
104 constexpr int32_t DECODE_SCALE_BASE = 2;
105 constexpr int32_t FLAT_ANGLE = 180;
106 constexpr int32_t THUMBNAIL_GENERATE_BATCH_COUNT = 200;
107 constexpr int32_t ASTC_GENERATE_COUNT_AFTER_RESTORE = 500;
108 constexpr int32_t READY_TEMPERATURE_LEVEL = 4;
109 constexpr int32_t EVEN_BASE_NUMBER = 2;
110 const std::string DEFAULT_EXIF_ORIENTATION = "1";
111 
112 const std::string THUMBNAIL_LCD_SUFFIX = "LCD";     // The size fit to screen
113 const std::string THUMBNAIL_THUMB_SUFFIX = "THM";   // The size which height is 256 and width is 256
114 const std::string THUMBNAIL_THUMBASTC_SUFFIX = "THM_ASTC";
115 const std::string THUMBNAIL_MTH_SUFFIX = "MTH";     // The size which height is 128 and width is 128
116 const std::string THUMBNAIL_YEAR_SUFFIX = "YEAR";   // The size which height is 64 and width is 64
117 const std::string THUMBNAIL_LCD_EX_SUFFIX = "THM_EX/LCD";
118 const std::string THUMBNAIL_THUMB_EX_SUFFIX = "THM_EX/THM";
119 
120 const std::string FILE_URI_PREX = "file://";
121 
122 const std::string PHOTO_URI_PREFIX = "file://media/Photo/";
123 
124 const std::string THUMBNAIL_FORMAT = "image/jpeg";
125 const std::string THUMBASTC_FORMAT = "image/astc/4*4";
126 constexpr uint8_t THUMBNAIL_EIGHTY = 80;
127 constexpr uint8_t THUMBNAIL_MID = 90;
128 constexpr uint8_t THUMBNAIL_HIGH = 100;
129 constexpr uint8_t ASTC_LOW_QUALITY = 20;
130 
131 constexpr uint32_t THUMBNAIL_QUERY_MAX = 2000;
132 constexpr int64_t AV_FRAME_TIME = 0;
133 
134 constexpr uint8_t NUMBER_HINT_1 = 1;
135 
136 constexpr int32_t DEFAULT_ORIGINAL = -1;
137 
138 const std::string DYNAMIC_RANGE = "decodeDynamicRange";
139 
140 const std::string THUMBNAIL_OPERN_KEYWORD = "operation";
141 const std::string THUMBNAIL_OPER = "oper";
142 const std::string THUMBNAIL_HEIGHT = "height";
143 const std::string THUMBNAIL_WIDTH = "width";
144 const std::string THUMBNAIL_PATH = "path";
145 
146 // create thumbnail in close operation
147 const std::string CLOSE_CREATE_THUMB_STATUS = "create_thumbnail_sync_status";
148 const int32_t CREATE_THUMB_SYNC_STATUS = 1;
149 const int32_t CREATE_THUMB_ASYNC_STATUS = 0;
150 
151 constexpr float FLOAT_EPSILON = 1e-6;
152 
153 // request photo type
154 const std::string REQUEST_PHOTO_TYPE = "requestPhotoType";
155 
156 const int32_t CLOUD_PHOTO_POSITION = 2;
157 const int32_t CLOUD_THUMB_STATUS_DOWNLOAD = 0;
158 const int32_t CLOUD_THUMBNAIL_DOWNLOAD_FINISH_NUMBER = 1000;
159 const std::string RDB_QUERY_COUNT = "count";
160 
161 const int32_t THUMBNAIL_READY_FAILED = 2;
162 
163 const int32_t THUMBNAIL_FREE_SIZE_LIMIT_1 = 1;
164 const int32_t THUMBNAIL_FREE_SIZE_LIMIT_10 = 10;
165 
166 // LCD that is over 2MB would not be uploaded
167 const size_t LCD_UPLOAD_LIMIT_SIZE = 2048000;
168 
169 // Only check the latest 3000 data to avoid opreation taking too long time
170 const uint32_t MAXIMUM_LCD_CHECK_NUM = 3000;
171 
172 const std::unordered_set<uint8_t> THUMBNAIL_QUALITY_SET = {
173     THUMBNAIL_EIGHTY,
174     THUMBNAIL_MID,
175     THUMBNAIL_HIGH,
176 };
177 
GetThumbnailPath(const std::string & path,const std::string & key)178 static inline std::string GetThumbnailPath(const std::string &path, const std::string &key)
179 {
180     if (path.length() < ROOT_MEDIA_DIR.length()) {
181         return "";
182     }
183     std::string suffix = (key == "THM_ASTC") ? ".astc" : ".jpg";
184     return ROOT_MEDIA_DIR + ".thumbs/" + path.substr(ROOT_MEDIA_DIR.length()) + "/" + key + suffix;
185 }
186 
GetThumbSuffix(ThumbnailType type)187 static std::string GetThumbSuffix(ThumbnailType type)
188 {
189     switch (type) {
190         case ThumbnailType::MTH:
191             return THUMBNAIL_MTH_SUFFIX;
192         case ThumbnailType::YEAR:
193             return THUMBNAIL_YEAR_SUFFIX;
194         case ThumbnailType::THUMB:
195             return THUMBNAIL_THUMB_SUFFIX;
196         case ThumbnailType::THUMB_ASTC:
197             return THUMBNAIL_THUMBASTC_SUFFIX;
198         case ThumbnailType::LCD:
199             return THUMBNAIL_LCD_SUFFIX;
200         default:
201             return "";
202     }
203 }
204 
205 static inline ThumbnailType GetThumbType(const int32_t width, const int32_t height, bool isAstc = false)
206 {
207     if (width == DEFAULT_ORIGINAL && height == DEFAULT_ORIGINAL) {
208         return ThumbnailType::LCD;
209     }
210 
211     if (std::min(width, height) <= DEFAULT_THUMB_SIZE &&
212         std::max(width, height) <= MAX_DEFAULT_THUMB_SIZE) {
213         return isAstc ? ThumbnailType::THUMB_ASTC : ThumbnailType::THUMB;
214     }
215 
216     return ThumbnailType::LCD;
217 }
218 
GetSandboxPath(const std::string & path,ThumbnailType type)219 static inline std::string GetSandboxPath(const std::string &path, ThumbnailType type)
220 {
221     if (path.length() < ROOT_MEDIA_DIR.length()) {
222         return "";
223     }
224     std::string suffix = (type == ThumbnailType::THUMB_ASTC) ? ".astc" : ".jpg";
225     std::string suffixStr = path.substr(ROOT_MEDIA_DIR.length()) + "/" + GetThumbSuffix(type) + suffix;
226     return ROOT_SANDBOX_DIR + ".thumbs/" + suffixStr;
227 }
228 
IsThumbnail(const int32_t width,const int32_t height)229 static inline bool IsThumbnail(const int32_t width, const int32_t height)
230 {
231     if (width == DEFAULT_ORIGINAL && height == DEFAULT_ORIGINAL) {
232         return false;
233     }
234     return std::min(width, height) <= DEFAULT_THUMB_SIZE &&
235            std::max(width, height) <= MAX_DEFAULT_THUMB_SIZE;
236 }
237 
238 } // namespace Media
239 } // namespace OHOS
240 
241 #endif  // FRAMEWORKS_SERVICES_THUMBNAIL_SERVICE_INCLUDE_THUMBNAIL_CONST_H_
242