• 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 namespace OHOS {
22 namespace Media {
23 constexpr int32_t DEFAULT_YEAR_SIZE = 64;
24 constexpr int32_t DEFAULT_MTH_SIZE = 128;
25 constexpr int32_t DEFAULT_THUMB_SIZE = 256;
26 constexpr int32_t MAX_DEFAULT_THUMB_SIZE = 768;
27 constexpr int32_t DEFAULT_LCD_SIZE = 1080;
28 
29 enum class ThumbnailType : int32_t {
30     LCD,
31     THUMB,
32     MTH,
33     YEAR,
34     THUMB_ASTC,
35     MTH_ASTC,
36     YEAR_ASTC,
37 };
38 
39 constexpr uint32_t DEVICE_UDID_LENGTH = 65;
40 
41 constexpr int32_t THUMBNAIL_LCD_GENERATE_THRESHOLD = 5000;
42 constexpr int32_t THUMBNAIL_LCD_AGING_THRESHOLD = 10000;
43 constexpr int32_t WAIT_FOR_MS = 1000;
44 constexpr int32_t WAIT_FOR_SECOND = 3;
45 
46 const std::string THUMBNAIL_LCD_SUFFIX = "LCD";     // The size fit to screen
47 const std::string THUMBNAIL_THUMB_SUFFIX = "THM";   // The size which height is 256 and width is 256
48 const std::string THUMBNAIL_THUMBASTC_SUFFIX = "THM_ASTC";
49 const std::string THUMBNAIL_MTH_SUFFIX = "MTH";     // The size which height is 128 and width is 128
50 const std::string THUMBNAIL_YEAR_SUFFIX = "YEAR";   // The size which height is 64 and width is 64
51 
52 const std::string FILE_URI_PREX = "file://";
53 
54 const std::string PHOTO_URI_PREFIX = "file://media/Photo/";
55 
56 const std::string THUMBNAIL_FORMAT = "image/jpeg";
57 const std::string THUMBASTC_FORMAT = "image/astc/4*4";
58 constexpr uint8_t THUMBNAIL_MID = 90;
59 constexpr uint8_t THUMBNAIL_HIGH = 100;
60 constexpr uint8_t ASTC_LOW_QUALITY = 20;
61 
62 constexpr uint32_t THUMBNAIL_QUERY_MAX = 2000;
63 constexpr int64_t AV_FRAME_TIME = 0;
64 
65 constexpr uint8_t NUMBER_HINT_1 = 1;
66 
67 constexpr int32_t DEFAULT_ORIGINAL = -1;
68 
69 const std::string THUMBNAIL_OPERN_KEYWORD = "operation";
70 const std::string THUMBNAIL_OPER = "oper";
71 const std::string THUMBNAIL_HEIGHT = "height";
72 const std::string THUMBNAIL_WIDTH = "width";
73 const std::string THUMBNAIL_PATH = "path";
74 
75 // create thumbnail in close operation
76 const std::string CLOSE_CREATE_THUMB_STATUS = "create_thumbnail_sync_status";
77 const int32_t CREATE_THUMB_SYNC_STATUS = 1;
78 const int32_t CREATE_THUMB_ASYNC_STATUS = 0;
79 
80 constexpr float FLOAT_EPSILON = 1e-6;
81 
82 // request photo type
83 const std::string REQUEST_PHOTO_TYPE = "requestPhotoType";
84 
GetThumbnailPath(const std::string & path,const std::string & key)85 static inline std::string GetThumbnailPath(const std::string &path, const std::string &key)
86 {
87     if (path.length() < ROOT_MEDIA_DIR.length()) {
88         return "";
89     }
90     std::string suffix = (key == "THM_ASTC") ? ".astc" : ".jpg";
91     return ROOT_MEDIA_DIR + ".thumbs/" + path.substr(ROOT_MEDIA_DIR.length()) + "/" + key + suffix;
92 }
93 
GetThumbSuffix(ThumbnailType type)94 static std::string GetThumbSuffix(ThumbnailType type)
95 {
96     switch (type) {
97         case ThumbnailType::MTH:
98             return THUMBNAIL_MTH_SUFFIX;
99         case ThumbnailType::YEAR:
100             return THUMBNAIL_YEAR_SUFFIX;
101         case ThumbnailType::THUMB:
102             return THUMBNAIL_THUMB_SUFFIX;
103         case ThumbnailType::THUMB_ASTC:
104             return THUMBNAIL_THUMBASTC_SUFFIX;
105         case ThumbnailType::LCD:
106             return THUMBNAIL_LCD_SUFFIX;
107         default:
108             return "";
109     }
110 }
111 
112 static inline ThumbnailType GetThumbType(const int32_t width, const int32_t height, bool isAstc = false)
113 {
114     if (width == DEFAULT_ORIGINAL && height == DEFAULT_ORIGINAL) {
115         return ThumbnailType::LCD;
116     }
117 
118     if (width == DEFAULT_MTH_SIZE && height == DEFAULT_MTH_SIZE) {
119         return ThumbnailType::MTH;
120     }
121 
122     if (width == DEFAULT_YEAR_SIZE && height == DEFAULT_YEAR_SIZE) {
123         return ThumbnailType::YEAR;
124     }
125 
126     if (std::min(width, height) <= DEFAULT_THUMB_SIZE &&
127         std::max(width, height) <= MAX_DEFAULT_THUMB_SIZE) {
128         return isAstc ? ThumbnailType::THUMB_ASTC : ThumbnailType::THUMB;
129     }
130 
131     return ThumbnailType::LCD;
132 }
133 
GetSandboxPath(const std::string & path,ThumbnailType type)134 static inline std::string GetSandboxPath(const std::string &path, ThumbnailType type)
135 {
136     if (path.length() < ROOT_MEDIA_DIR.length()) {
137         return "";
138     }
139     std::string suffix = (type == ThumbnailType::THUMB_ASTC) ? ".astc" : ".jpg";
140     std::string suffixStr = path.substr(ROOT_MEDIA_DIR.length()) + "/" + GetThumbSuffix(type) + suffix;
141     return ROOT_SANDBOX_DIR + ".thumbs/" + suffixStr;
142 }
143 
IsThumbnail(const int32_t width,const int32_t height)144 static inline bool IsThumbnail(const int32_t width, const int32_t height)
145 {
146     if (width == DEFAULT_ORIGINAL && height == DEFAULT_ORIGINAL) {
147         return false;
148     }
149     return std::min(width, height) <= DEFAULT_THUMB_SIZE &&
150            std::max(width, height) <= MAX_DEFAULT_THUMB_SIZE;
151 }
152 
153 } // namespace Media
154 } // namespace OHOS
155 
156 #endif  // FRAMEWORKS_SERVICES_THUMBNAIL_SERVICE_INCLUDE_THUMBNAIL_CONST_H_
157