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