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_INNERKITSIMPL_UTILS_INCLUDE_VPE_UTILS_H
17 #define FRAMEWORKS_INNERKITSIMPL_UTILS_INCLUDE_VPE_UTILS_H
18 
19 #include <mutex>
20 
21 #if !defined(IOS_PLATFORM) && !defined(ANDROID_PLATFORM)
22 #include "v1_0/cm_color_space.h"
23 #include "v1_0/hdr_static_metadata.h"
24 #include "surface_buffer.h"
25 #endif
26 
27 #include "hdr_type.h"
28 
29 namespace OHOS {
30 namespace Media {
31 constexpr int32_t VPE_ERROR_FAILED = -1;
32 constexpr int32_t VPE_ERROR_OK = 0;
33 
34 #if !defined(IOS_PLATFORM) && !defined(ANDROID_PLATFORM)
35 struct VpeSurfaceBuffers {
36     sptr<SurfaceBuffer> sdr;
37     sptr<SurfaceBuffer> gainmap;
38     sptr<SurfaceBuffer> hdr;
39 };
40 #endif
41 
42 class VpeUtils {
43 public:
44     VpeUtils();
45     ~VpeUtils();
46 #if !defined(_WIN32) && !defined(_APPLE) && !defined(IOS_PLATFORM) && !defined(ANDROID_PLATFORM)
47     int32_t ColorSpaceConverterComposeImage(VpeSurfaceBuffers& sb, bool legacy);
48     int32_t ColorSpaceConverterDecomposeImage(VpeSurfaceBuffers& sb);
49     int32_t ColorSpaceConverterImageProcess(sptr<SurfaceBuffer>& input, sptr<SurfaceBuffer>& output);
50     int32_t DetailEnhancerImageProcess(sptr<SurfaceBuffer>& input, sptr<SurfaceBuffer>& output, int32_t level);
51     static bool SetSbColorSpaceType(sptr<SurfaceBuffer>& buffer,
52         const HDI::Display::Graphic::Common::V1_0::CM_ColorSpaceType& colorSpaceType);
53     static bool GetSbColorSpaceType(const sptr<SurfaceBuffer>& buffer,
54         HDI::Display::Graphic::Common::V1_0::CM_ColorSpaceType& colorSpaceType);
55     static bool SetSbMetadataType(sptr<SurfaceBuffer>& buffer,
56         const HDI::Display::Graphic::Common::V1_0::CM_HDR_Metadata_Type& metadataType);
57     static bool GetSbMetadataType(const sptr<SurfaceBuffer>& buffer,
58         HDI::Display::Graphic::Common::V1_0::CM_HDR_Metadata_Type& metadataType);
59     static bool SetSbDynamicMetadata(sptr<SurfaceBuffer>& buffer, const std::vector<uint8_t>& dynamicMetadata);
60     static bool GetSbDynamicMetadata(const sptr<SurfaceBuffer>& buffer, std::vector<uint8_t>& dynamicMetadata);
61     static bool SetSbStaticMetadata(sptr<SurfaceBuffer>& buffer, const std::vector<uint8_t>& staticMetadata);
62     static bool GetSbStaticMetadata(const sptr<SurfaceBuffer>& buffer, std::vector<uint8_t>& staticMetadata);
63     static void SetSurfaceBufferInfo(sptr<SurfaceBuffer>& buffer, bool isGainmap, ImageHdrType type,
64         HDI::Display::Graphic::Common::V1_0::CM_ColorSpaceType color, HdrMetadata& metadata);
65     static void SetSurfaceBufferInfo(sptr<SurfaceBuffer>& buffer,
66         HDI::Display::Graphic::Common::V1_0::CM_ColorSpaceType color);
67     static bool SetSbColorSpaceDefault(sptr<SurfaceBuffer>& buffer);
68     static void CopySurfaceBufferInfo(sptr<SurfaceBuffer>& source, sptr<SurfaceBuffer>& dst);
69 #endif
70     static bool LoadLibVpe();
71     static void UnloadLibVpe();
72 
73 private:
74     int32_t ColorSpaceConverterCreate(void* handle, int32_t* instanceId);
75     int32_t ColorSpaceConverterDestory(void* handle, int32_t* instanceId);
76     int32_t DetailEnhancerCreate(void* handle, int32_t* instanceId);
77     int32_t DetailEnhancerDestory(void* handle, int32_t* instanceId);
78     std::mutex vpeMtx_;
79     static void* dlHandler_;
80 };
81 } // namespace Media
82 } // namespace OHOS
83 
84 #endif // FRAMEWORKS_INNERKITSIMPL_UTILS_INCLUDE_VPE_UTILS_H