/* * Copyright (C) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef FRAMEWORKS_SERVICES_THUMBNAIL_SERVICE_INCLUDE_THUMBNAIL_DATA_H #define FRAMEWORKS_SERVICES_THUMBNAIL_SERVICE_INCLUDE_THUMBNAIL_DATA_H #include #include #include "thumbnail_const.h" namespace OHOS { namespace Media { #define EXPORT __attribute__ ((visibility ("default"))) enum class SourceState : int32_t { BEGIN = -3, LOCAL_THUMB, LOCAL_LCD, LOCAL_ORIGIN, CLOUD_THUMB, CLOUD_LCD, CLOUD_ORIGIN, ERROR, FINISH, }; class ThumbnailSource { public: void SetPixelMap(std::shared_ptr &pixelMap) { pixelMapSource_ = pixelMap; } std::shared_ptr GetPixelMap() { return pixelMapSource_; } void SetPixelMapEx(std::shared_ptr &pixelMapEx) { pixelMapSourceEx_ = pixelMapEx; } std::shared_ptr GetPixelMapEx() { return pixelMapSourceEx_; } void SetPicture(std::shared_ptr &picture) { pictureSource_ = picture; if (picture != nullptr) { hasPictureSource_ = true; } } std::shared_ptr GetPicture() { return pictureSource_; } void SetPictureEx(std::shared_ptr &pictureEx) { pictureSourceEx_ = pictureEx; } std::shared_ptr GetPictureEx() { return pictureSourceEx_; } void ClearAllSource() { pixelMapSource_ = nullptr; pixelMapSourceEx_ = nullptr; pictureSource_ = nullptr; pictureSourceEx_ = nullptr; hasPictureSource_ = false; } bool IsEmptySource() { return pixelMapSource_ == nullptr && pictureSource_ == nullptr; } bool HasPictureSource() { return hasPictureSource_; } private: bool hasPictureSource_ {false}; std::shared_ptr pixelMapSource_; std::shared_ptr pixelMapSourceEx_; std::shared_ptr pictureSource_; std::shared_ptr pictureSourceEx_; }; class ThumbnailData { public: struct GenerateStats { std::string uri; GenerateScene scene {GenerateScene::LOCAL}; int32_t openThumbCost {0}; int32_t openLcdCost {0}; int32_t openOriginCost {0}; LoadSourceType sourceType {LoadSourceType::LOCAL_PHOTO}; int32_t sourceWidth {0}; int32_t sourceHeight {0}; int32_t totalCost {0}; int32_t errorCode {0}; int64_t startTime {0}; int64_t finishTime {0}; }; struct SourceLoaderOptions { // if false, target decode size is LCD size bool decodeInThumbSize {false}; bool needUpload {false}; // if true, create HDR pixelmap EXPORT bool isHdr {false}; std::unordered_map loadingStates; }; EXPORT ThumbnailData() = default; EXPORT virtual ~ThumbnailData() { source.ClearAllSource(); thumbnail.clear(); lcd.clear(); monthAstc.clear(); yearAstc.clear(); } EXPORT int32_t mediaType {-1}; EXPORT int64_t dateModified {0}; EXPORT int32_t orientation {0}; EXPORT int32_t photoHeight {0}; EXPORT int32_t photoWidth {0}; // Loaded lcd source can be resized to generate thumbnail in order EXPORT bool needResizeLcd {false}; EXPORT bool isLocalFile {true}; EXPORT bool isOpeningCloudFile {false}; EXPORT ThumbnailSource source; EXPORT std::vector thumbnail; EXPORT std::vector thumbAstc; EXPORT std::vector monthAstc; EXPORT std::vector yearAstc; EXPORT std::vector lcd; EXPORT std::string dateAdded; EXPORT std::string dateTaken; EXPORT std::string displayName; EXPORT std::string fileUri; EXPORT std::string id; EXPORT std::string cloudId; EXPORT std::string udid; EXPORT std::string path; EXPORT std::string thumbnailKey; EXPORT std::string lcdKey; EXPORT Size lcdDesiredSize; EXPORT Size thumbDesiredSize; EXPORT GenerateStats stats; EXPORT SourceLoaderOptions loaderOpts; EXPORT bool isThumbExisted {false}; }; } // namespace Media } // namespace OHOS #endif // FRAMEWORKS_SERVICES_THUMBNAIL_SERVICE_INCLUDE_THUMBNAIL_DATA_H