1 /* 2 * Copyright (c) 2025 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 PIXELMAP_LOADER 17 #define PIXELMAP_LOADER 18 19 #include <functional> 20 #include <memory> 21 #include <optional> 22 #include "pixel_map.h" 23 24 namespace OHOS::UDMF { 25 26 struct PixelMapDetails { 27 int32_t width = 0; 28 int32_t height = 0; 29 int32_t pixelFormat = 0; 30 int32_t alphaType = 0; 31 // Use as an input parameter. To avoid copying, pass a reference. 32 std::optional<std::reference_wrapper<std::vector<uint8_t>>> rawData; 33 // Use as an output parameter. 34 std::optional<std::vector<uint8_t>> rawDataResult; 35 }; 36 37 typedef OHOS::Media::PixelMap *(*LoadDecodeTlv)(const PixelMapDetails); 38 typedef bool (*LoadEncodeTlv)(const OHOS::Media::PixelMap *, PixelMapDetails *); 39 typedef OHOS::Media::PixelMap *(*LoadGetPixelMapFromRawData)(const PixelMapDetails); 40 typedef PixelMapDetails *(*LoadParseInfoFromPixelMap)(OHOS::Media::PixelMap *); 41 42 class PixelMapLoader { 43 public: 44 PixelMapLoader(); 45 46 std::shared_ptr<OHOS::Media::PixelMap> DecodeTlv(std::vector<uint8_t> &buff); 47 bool EncodeTlv(const std::shared_ptr<OHOS::Media::PixelMap> pixelmap, std::vector<uint8_t> &buff); 48 std::shared_ptr<OHOS::Media::PixelMap> GetPixelMapFromRawData(const PixelMapDetails &details); 49 std::shared_ptr<PixelMapDetails> ParseInfoFromPixelMap(const std::shared_ptr<OHOS::Media::PixelMap> pixelMap); 50 51 private: 52 class SoAutoUnloadManager { 53 public: 54 static std::shared_ptr<void> GetHandler(); 55 private: 56 static std::weak_ptr<void> weakHandler_; 57 static std::mutex mutex_; 58 }; 59 60 std::shared_ptr<void> handler_; 61 }; 62 63 } // namespace OHOS::UDMF 64 65 #endif // PIXELMAP_LOADER