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 <pixel_map.h>
20 
21 #include "thumbnail_const.h"
22 
23 namespace OHOS {
24 namespace Media {
25 #define EXPORT __attribute__ ((visibility ("default")))
26 enum class SourceState : int32_t {
27     BEGIN = -3,
28     LOCAL_THUMB,
29     LOCAL_LCD,
30     LOCAL_ORIGIN,
31     CLOUD_THUMB,
32     CLOUD_LCD,
33     CLOUD_ORIGIN,
34     ERROR,
35     FINISH,
36 };
37 
38 class ThumbnailData {
39 public:
40     struct GenerateStats {
41         std::string uri;
42         GenerateScene scene {GenerateScene::LOCAL};
43         int32_t openThumbCost {0};
44         int32_t openLcdCost {0};
45         int32_t openOriginCost {0};
46         LoadSourceType sourceType {LoadSourceType::LOCAL_PHOTO};
47         int32_t sourceWidth {0};
48         int32_t sourceHeight {0};
49         int32_t totalCost {0};
50         int32_t errorCode {0};
51         int64_t startTime {0};
52         int64_t finishTime {0};
53     };
54 
55     struct SourceLoaderOptions {
56         // if false, target decode size is LCD size
57         bool decodeInThumbSize {false};
58         bool needUpload {false};
59 
60         // if true, create HDR pixelmap
61         EXPORT bool isHdr {false};
62         std::unordered_map<SourceState, SourceState> loadingStates;
63     };
64 
65     EXPORT ThumbnailData() = default;
66 
~ThumbnailData()67     EXPORT virtual ~ThumbnailData()
68     {
69         source = nullptr;
70         thumbnail.clear();
71         lcd.clear();
72         monthAstc.clear();
73         yearAstc.clear();
74     }
75 
76     EXPORT int32_t mediaType {-1};
77     EXPORT int64_t dateModified {0};
78     EXPORT int32_t orientation {0};
79     EXPORT int32_t photoHeight {0};
80     EXPORT int32_t photoWidth {0};
81 
82     // Loaded lcd source can be resized to generate thumbnail in order
83     EXPORT bool needResizeLcd {false};
84     EXPORT bool isLocalFile {true};
85     EXPORT bool isOpeningCloudFile {false};
86     EXPORT bool isNeedStoreSize {true};
87     EXPORT std::shared_ptr<PixelMap> source;
88     EXPORT std::shared_ptr<PixelMap> sourceEx;
89     EXPORT std::vector<uint8_t> thumbnail;
90     EXPORT std::vector<uint8_t> thumbAstc;
91     EXPORT std::vector<uint8_t> monthAstc;
92     EXPORT std::vector<uint8_t> yearAstc;
93     EXPORT std::vector<uint8_t> lcd;
94     EXPORT std::string dateAdded;
95     EXPORT std::string dateTaken;
96     EXPORT std::string displayName;
97     EXPORT std::string fileUri;
98     EXPORT std::string id;
99     EXPORT std::string cloudId;
100     EXPORT std::string udid;
101     EXPORT std::string path;
102     EXPORT std::string thumbnailKey;
103     EXPORT std::string lcdKey;
104     EXPORT std::string tracks;
105     EXPORT std::string trigger;
106     EXPORT std::string frame;
107     EXPORT std::string timeStamp;
108     EXPORT Size lcdDesiredSize;
109     EXPORT Size thumbDesiredSize;
110     EXPORT GenerateStats stats;
111     EXPORT SourceLoaderOptions loaderOpts;
112 };
113 } // namespace Media
114 } // namespace OHOS
115 
116 #endif  // FRAMEWORKS_SERVICES_THUMBNAIL_SERVICE_INCLUDE_THUMBNAIL_DATA_H
117