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 std::unordered_map<SourceState, SourceState> loadingStates; 136 }; 137 138 EXPORT ThumbnailData() = default; 139 ~ThumbnailData()140 EXPORT virtual ~ThumbnailData() 141 { 142 source.ClearAllSource(); 143 thumbnail.clear(); 144 lcd.clear(); 145 monthAstc.clear(); 146 yearAstc.clear(); 147 } 148 149 EXPORT int32_t mediaType {-1}; 150 EXPORT int64_t dateModified {0}; 151 EXPORT int32_t orientation {0}; 152 EXPORT int32_t photoHeight {0}; 153 EXPORT int32_t photoWidth {0}; 154 155 // Loaded lcd source can be resized to generate thumbnail in order 156 EXPORT bool needResizeLcd {false}; 157 EXPORT bool isLocalFile {true}; 158 EXPORT bool isOpeningCloudFile {false}; 159 EXPORT ThumbnailSource source; 160 EXPORT std::vector<uint8_t> thumbnail; 161 EXPORT std::vector<uint8_t> thumbAstc; 162 EXPORT std::vector<uint8_t> monthAstc; 163 EXPORT std::vector<uint8_t> yearAstc; 164 EXPORT std::vector<uint8_t> lcd; 165 EXPORT std::string dateAdded; 166 EXPORT std::string dateTaken; 167 EXPORT std::string displayName; 168 EXPORT std::string fileUri; 169 EXPORT std::string id; 170 EXPORT std::string cloudId; 171 EXPORT std::string udid; 172 EXPORT std::string path; 173 EXPORT std::string thumbnailKey; 174 EXPORT std::string lcdKey; 175 EXPORT Size lcdDesiredSize; 176 EXPORT Size thumbDesiredSize; 177 EXPORT GenerateStats stats; 178 EXPORT SourceLoaderOptions loaderOpts; 179 EXPORT bool isThumbExisted {false}; 180 }; 181 } // namespace Media 182 } // namespace OHOS 183 184 #endif // FRAMEWORKS_SERVICES_THUMBNAIL_SERVICE_INCLUDE_THUMBNAIL_DATA_H 185