• 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 IMAGE_PROCESSING_LOADER_H
17 #define IMAGE_PROCESSING_LOADER_H
18 
19 #include <atomic>
20 #include <functional>
21 #include <mutex>
22 #include <string>
23 
24 #include "image_processing_capi_interface.h"
25 
26 class ImageProcessingNdkLoader {
27 public:
28     static ImageProcessingNdkLoader& Get();
29 
30     bool LoadLibrary();
31     void UnloadLibrary();
32     bool IsValid() const;
33 
34     // Interface
35     ImageProcessing_ErrorCode InitializeEnvironment();
36     ImageProcessing_ErrorCode DeinitializeEnvironment();
37     bool IsColorSpaceConversionSupported(
38         const ImageProcessing_ColorSpaceInfo* sourceImageInfo,
39         const ImageProcessing_ColorSpaceInfo* destinationImageInfo);
40     bool IsCompositionSupported(
41         const ImageProcessing_ColorSpaceInfo* sourceImageInfo,
42         const ImageProcessing_ColorSpaceInfo* sourceGainmapInfo,
43         const ImageProcessing_ColorSpaceInfo* destinationImageInfo);
44     bool IsDecompositionSupported(
45         const ImageProcessing_ColorSpaceInfo* sourceImageInfo,
46         const ImageProcessing_ColorSpaceInfo* destinationImageInfo,
47         const ImageProcessing_ColorSpaceInfo* destinationGainmapInfo);
48     bool IsMetadataGenerationSupported(const ImageProcessing_ColorSpaceInfo* sourceImageInfo);
49     ImageProcessing_ErrorCode Create(OH_ImageProcessing** imageProcessor, int32_t type);
50     ImageProcessing_ErrorCode Destroy(OH_ImageProcessing* imageProcessor);
51     ImageProcessing_ErrorCode SetParameter(OH_ImageProcessing* imageProcessor, const OH_AVFormat* parameter);
52     ImageProcessing_ErrorCode GetParameter(OH_ImageProcessing* imageProcessor, OH_AVFormat* parameter);
53     ImageProcessing_ErrorCode ConvertColorSpace(OH_ImageProcessing* imageProcessor, OH_PixelmapNative* sourceImage,
54         OH_PixelmapNative* destinationImage);
55     ImageProcessing_ErrorCode Compose(OH_ImageProcessing* imageProcessor, OH_PixelmapNative* sourceImage,
56         OH_PixelmapNative* sourceGainmap, OH_PixelmapNative* destinationImage);
57     ImageProcessing_ErrorCode Decompose(OH_ImageProcessing* imageProcessor, OH_PixelmapNative* sourceImage,
58         OH_PixelmapNative* destinationImage, OH_PixelmapNative* destinationGainmap);
59     ImageProcessing_ErrorCode GenerateMetadata(OH_ImageProcessing* imageProcessor, OH_PixelmapNative* sourceImage);
60     ImageProcessing_ErrorCode EnhanceDetail(OH_ImageProcessing* imageProcessor, OH_PixelmapNative* sourceImage,
61         OH_PixelmapNative* destinationImage);
62 
63 private:
64     using createNdkFunc = IImageProcessingNdk* (*)();
65     using destroyNdkFunc = void (*)(IImageProcessingNdk* obj);
66 
67     ImageProcessingNdkLoader() = default;
68     virtual ~ImageProcessingNdkLoader() = default;
69     ImageProcessingNdkLoader(const ImageProcessingNdkLoader&) = delete;
70     ImageProcessingNdkLoader& operator=(const ImageProcessingNdkLoader&) = delete;
71     ImageProcessingNdkLoader(ImageProcessingNdkLoader&&) = delete;
72     ImageProcessingNdkLoader& operator=(ImageProcessingNdkLoader&&) = delete;
73 
74     bool LoadLibraryLocked();
75     void UnloadLibraryLocked();
76     bool OpenLibraryLocked(const std::string& path);
77     bool LoadInterfaceLocked(IImageProcessingNdk*& interface, destroyNdkFunc& destroyFunc,
78         const std::string& createFuncName, const std::string& destroyFuncName, const std::string& path);
79 
80     bool CallSupportNdk(std::function<bool(IImageProcessingNdk*)>&& operation);
81     ImageProcessing_ErrorCode CallNdk(std::function<ImageProcessing_ErrorCode(IImageProcessingNdk*)>&& operation);
82 
83     std::mutex lock_{};
84     // Guarded by lock_ begin
85     std::atomic<bool> isValid_{};
86     uint32_t refCount_{0};
87     IImageProcessingNdk* imageProcessing_{};
88     destroyNdkFunc destroyImageProcessingFunc_{};
89     void* libHandle_{};
90     // Guarded by lock_ end
91 };
92 
93 #endif // IMAGE_PROCESSING_LOADER_H
94