• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 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 FRAMEWORKS_SERVICES_THUMBNAIL_SERVICE_INCLUDE_THUMBNAIL_DATA_H
17 #define FRAMEWORKS_SERVICES_THUMBNAIL_SERVICE_INCLUDE_THUMBNAIL_DATA_H
18 
19 #include <picture.h>
20 #include <pixel_map.h>
21 
22 #include "medialibrary_rdb_utils.h"
23 #include "thumbnail_const.h"
24 
25 namespace OHOS {
26 namespace Media {
27 
28 struct ThumbRdbOpt {
29     EXPORT std::shared_ptr<MediaLibraryRdbStore> store;
30     EXPORT std::shared_ptr<AbilityRuntime::Context> context;
31     EXPORT std::string networkId;
32     EXPORT std::string path;
33     EXPORT std::string table;
34     EXPORT std::string udid;
35     EXPORT std::string row;
36     EXPORT std::string uri;
37     EXPORT std::string dateAdded;
38     EXPORT std::string dateTaken;
39     EXPORT std::string dateModified;
40     EXPORT std::string fileUri;
41     EXPORT std::string fileId;
42     EXPORT Size screenSize;
43 };
44 
45 #define EXPORT __attribute__ ((visibility ("default")))
46 enum class SourceState : int32_t {
47     BEGIN = -3,
48     LOCAL_THUMB,
49     LOCAL_LCD,
50     LOCAL_ORIGIN,
51     CLOUD_THUMB,
52     CLOUD_LCD,
53     CLOUD_ORIGIN,
54     ERROR,
55     FINISH,
56 };
57 
58 class ThumbnailSource {
59 public:
SetPixelMap(std::shared_ptr<PixelMap> & pixelMap)60     void SetPixelMap(std::shared_ptr<PixelMap> &pixelMap)
61     {
62         pixelMapSource_  = pixelMap;
63     }
64 
GetPixelMap()65     std::shared_ptr<PixelMap> GetPixelMap()
66     {
67         return pixelMapSource_;
68     }
69 
SetPixelMapEx(std::shared_ptr<PixelMap> & pixelMapEx)70     void SetPixelMapEx(std::shared_ptr<PixelMap> &pixelMapEx)
71     {
72         pixelMapSourceEx_  = pixelMapEx;
73     }
74 
GetPixelMapEx()75     std::shared_ptr<PixelMap> GetPixelMapEx()
76     {
77         return pixelMapSourceEx_;
78     }
79 
SetPicture(std::shared_ptr<Picture> & picture)80     void SetPicture(std::shared_ptr<Picture> &picture)
81     {
82         pictureSource_  = picture;
83         if (picture != nullptr) {
84             hasPictureSource_ = true;
85         }
86     }
87 
GetPicture()88     std::shared_ptr<Picture> GetPicture()
89     {
90         return pictureSource_;
91     }
92 
SetPictureEx(std::shared_ptr<Picture> & pictureEx)93     void SetPictureEx(std::shared_ptr<Picture> &pictureEx)
94     {
95         pictureSourceEx_  = pictureEx;
96     }
97 
GetPictureEx()98     std::shared_ptr<Picture> GetPictureEx()
99     {
100         return pictureSourceEx_;
101     }
102 
ClearAllSource()103     void ClearAllSource()
104     {
105         pixelMapSource_ = nullptr;
106         pixelMapSourceEx_ = nullptr;
107         pictureSource_ = nullptr;
108         pictureSourceEx_ = nullptr;
109         hasPictureSource_ = false;
110     }
111 
IsEmptySource()112     bool IsEmptySource()
113     {
114         return pixelMapSource_ == nullptr && pictureSource_ == nullptr;
115     }
116 
HasPictureSource()117     bool HasPictureSource()
118     {
119         return hasPictureSource_;
120     }
121 
122 private:
123     bool hasPictureSource_ {false};
124     std::shared_ptr<PixelMap> pixelMapSource_;
125     std::shared_ptr<PixelMap> pixelMapSourceEx_;
126     std::shared_ptr<Picture> pictureSource_;
127     std::shared_ptr<Picture> pictureSourceEx_;
128 };
129 
130 class ThumbnailData {
131 public:
132     struct GenerateStats {
133         std::string uri;
134         GenerateScene scene {GenerateScene::LOCAL};
135         int32_t openThumbCost {0};
136         int32_t openLcdCost {0};
137         int32_t openOriginCost {0};
138         LoadSourceType sourceType {LoadSourceType::LOCAL_PHOTO};
139         int32_t sourceWidth {0};
140         int32_t sourceHeight {0};
141         int32_t totalCost {0};
142         int32_t errorCode {0};
143         int64_t startTime {0};
144         int64_t finishTime {0};
145     };
146 
147     struct SourceLoaderOptions {
148         // if false, target decode size is LCD size
149         bool decodeInThumbSize {false};
150         bool needUpload {false};
151 
152         // if true, create HDR pixelmap
153         EXPORT bool isHdr {false};
154 
155         // largest thumbnail type for the source to generate
156         ThumbnailType desiredType {ThumbnailType::NOT_DEFINED};
157         std::unordered_map<SourceState, SourceState> loadingStates;
158     };
159 
160     EXPORT ThumbnailData() = default;
161 
~ThumbnailData()162     EXPORT virtual ~ThumbnailData()
163     {
164         source.ClearAllSource();
165         thumbnail.clear();
166         lcd.clear();
167         monthAstc.clear();
168         yearAstc.clear();
169     }
170 
171     EXPORT int32_t mediaType {-1};
172     EXPORT int32_t orientation {0};
173     EXPORT int32_t exifRotate {0};
174     EXPORT int32_t photoHeight {0};
175     EXPORT int32_t photoWidth {0};
176     EXPORT int32_t dirty {-1};
177     EXPORT ThumbnailQuality thumbnailQuality {ThumbnailQuality::DEFAULT};
178 
179     // Loaded lcd source can be resized to generate thumbnail in order
180     EXPORT bool needResizeLcd {false};
181     EXPORT bool isLocalFile {true};
182     EXPORT bool isOpeningCloudFile {false};
183     EXPORT bool isNeedStoreSize {true};
184     EXPORT bool isRegenerateStage {false};
185     EXPORT bool isUpgradeStage {false};
186     EXPORT bool needCheckWaitStatus {false};
187     EXPORT bool needUpdateDb {true};
188     EXPORT bool createLowQulityLcd {false};
189     EXPORT bool needGenerateExThumbnail {true};
190     EXPORT ThumbnailSource source;
191     EXPORT std::vector<uint8_t> thumbnail;
192     EXPORT std::vector<uint8_t> thumbAstc;
193     EXPORT std::vector<uint8_t> monthAstc;
194     EXPORT std::vector<uint8_t> yearAstc;
195     EXPORT std::vector<uint8_t> lcd;
196     EXPORT std::string dateAdded;
197     EXPORT std::string dateTaken;
198     EXPORT std::string dateModified;
199     EXPORT std::string displayName;
200     EXPORT std::string fileUri;
201     EXPORT std::string id;
202     EXPORT std::string cloudId;
203     EXPORT std::string udid;
204     EXPORT std::string path;
205     EXPORT std::string thumbnailKey;
206     EXPORT std::string lcdKey;
207     EXPORT std::string tracks;
208     EXPORT std::string trigger;
209     EXPORT std::string frame;
210     EXPORT std::string timeStamp;
211     EXPORT int32_t position;
212     EXPORT Size lcdDesiredSize;
213     EXPORT Size thumbDesiredSize;
214     EXPORT GenerateStats stats;
215     EXPORT SourceLoaderOptions loaderOpts;
216     EXPORT int64_t thumbnailReady { -1 };
217     EXPORT int64_t lcdVisitTime { -1 };
218     EXPORT std::shared_ptr<Picture> originalPhotoPicture = nullptr;
219     EXPORT NativeRdb::ValuesBucket rdbUpdateCache;
220     EXPORT SourceState lastLoadSource {SourceState::BEGIN};
221 };
222 
223 struct ThumbnailDataBatch {
224     EXPORT std::vector<std::string> ids;
225     EXPORT std::vector<std::string> paths;
226     EXPORT std::vector<std::string> dateTakens;
227 };
228 } // namespace Media
229 } // namespace OHOS
230 
231 #endif  // FRAMEWORKS_SERVICES_THUMBNAIL_SERVICE_INCLUDE_THUMBNAIL_DATA_H
232