• 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 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 ColorSpaceCalGainmap(VpeSurfaceBuffers& sb);
50     int32_t ColorSpaceConverterImageProcess(sptr<SurfaceBuffer>& input, sptr<SurfaceBuffer>& output);
51     int32_t DetailEnhancerImageProcess(sptr<SurfaceBuffer>& input, sptr<SurfaceBuffer>& output, int32_t level);
52     static bool SetSbColorSpaceType(sptr<SurfaceBuffer>& buffer,
53         const HDI::Display::Graphic::Common::V1_0::CM_ColorSpaceType& colorSpaceType);
54     static bool GetSbColorSpaceType(const sptr<SurfaceBuffer>& buffer,
55         HDI::Display::Graphic::Common::V1_0::CM_ColorSpaceType& colorSpaceType);
56     static bool SetSbMetadataType(sptr<SurfaceBuffer>& buffer,
57         const HDI::Display::Graphic::Common::V1_0::CM_HDR_Metadata_Type& metadataType);
58     static bool GetSbMetadataType(const sptr<SurfaceBuffer>& buffer,
59         HDI::Display::Graphic::Common::V1_0::CM_HDR_Metadata_Type& metadataType);
60     static bool SetSbDynamicMetadata(sptr<SurfaceBuffer>& buffer, const std::vector<uint8_t>& dynamicMetadata);
61     static bool GetSbDynamicMetadata(const sptr<SurfaceBuffer>& buffer, std::vector<uint8_t>& dynamicMetadata);
62     static bool SetSbStaticMetadata(sptr<SurfaceBuffer>& buffer, const std::vector<uint8_t>& staticMetadata);
63     static bool GetSbStaticMetadata(const sptr<SurfaceBuffer>& buffer, std::vector<uint8_t>& staticMetadata);
64     static void SetSurfaceBufferInfo(sptr<SurfaceBuffer>& buffer, bool isGainmap, ImageHdrType type,
65         HDI::Display::Graphic::Common::V1_0::CM_ColorSpaceType color, HdrMetadata& metadata);
66     static void SetSurfaceBufferInfo(sptr<SurfaceBuffer>& buffer,
67         HDI::Display::Graphic::Common::V1_0::CM_ColorSpaceType color);
68     static bool SetSbColorSpaceDefault(sptr<SurfaceBuffer>& buffer);
69     static void CopySurfaceBufferInfo(sptr<SurfaceBuffer>& source, sptr<SurfaceBuffer>& dst);
70 #endif
71     static bool LoadLibVpe();
72     static void UnloadLibVpe();
73 
74 private:
75     int32_t ColorSpaceConverterCreate(void* handle, int32_t* instanceId);
76     int32_t ColorSpaceConverterDestory(void* handle, int32_t* instanceId);
77     int32_t DetailEnhancerCreate(void* handle, int32_t* instanceId);
78     int32_t DetailEnhancerDestory(void* handle, int32_t* instanceId);
79     std::mutex vpeMtx_;
80     static void* dlHandler_;
81 };
82 } // namespace Media
83 } // namespace OHOS
84 
85 #endif // FRAMEWORKS_INNERKITSIMPL_UTILS_INCLUDE_VPE_UTILS_H