• 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 #include "image_processing_native_base.h"
17 
18 #include "common/native_mfmagic.h"
19 #include "pixelmap_native_impl.h"
20 
21 #include "image_environment_native.h"
22 #include "vpe_log.h"
23 
24 using namespace OHOS;
25 using namespace OHOS::Media::VideoProcessingEngine;
26 
ImageProcessingNativeBase()27 ImageProcessingNativeBase::ImageProcessingNativeBase()
28 {
29 }
30 
Initialize()31 ImageProcessing_ErrorCode ImageProcessingNativeBase::Initialize()
32 {
33     CHECK_AND_RETURN_RET_LOG(!isInitialized_.load(), IMAGE_PROCESSING_ERROR_OPERATION_NOT_PERMITTED,
34         "Already init!");
35     std::lock_guard<std::mutex> lock(lock_);
36     CHECK_AND_RETURN_RET_LOG(!isInitialized_.load(), IMAGE_PROCESSING_ERROR_OPERATION_NOT_PERMITTED,
37         "Already init!");
38     auto result = InitializeInner();
39     isInitialized_ = true;
40     return result;
41 }
42 
Deinitialize()43 ImageProcessing_ErrorCode ImageProcessingNativeBase::Deinitialize()
44 {
45     CHECK_AND_RETURN_RET_LOG(isInitialized_.load(), IMAGE_PROCESSING_ERROR_OPERATION_NOT_PERMITTED,
46         "Already deinit!");
47     std::lock_guard<std::mutex> lock(lock_);
48     CHECK_AND_RETURN_RET_LOG(isInitialized_.load(), IMAGE_PROCESSING_ERROR_OPERATION_NOT_PERMITTED,
49         "Already deinit!");
50     auto result = DeinitializeInner();
51     isInitialized_ = false;
52     return result;
53 }
54 
SetParameter(const OH_AVFormat * parameter)55 ImageProcessing_ErrorCode ImageProcessingNativeBase::SetParameter(const OH_AVFormat* parameter)
56 {
57     CHECK_AND_RETURN_RET_LOG(parameter != nullptr, IMAGE_PROCESSING_ERROR_INVALID_PARAMETER, "parameter is null!");
58     return SetParameter(parameter->format_);
59 }
60 
GetParameter(OH_AVFormat * parameter)61 ImageProcessing_ErrorCode ImageProcessingNativeBase::GetParameter(OH_AVFormat* parameter)
62 {
63     CHECK_AND_RETURN_RET_LOG(parameter != nullptr, IMAGE_PROCESSING_ERROR_INVALID_PARAMETER, "parameter is null!");
64     return GetParameter(parameter->format_);
65 }
66 
Process(OH_PixelmapNative * sourceImage,OH_PixelmapNative * destinationImage)67 ImageProcessing_ErrorCode ImageProcessingNativeBase::Process(OH_PixelmapNative* sourceImage,
68     OH_PixelmapNative* destinationImage)
69 {
70     CHECK_AND_RETURN_RET_LOG(sourceImage != nullptr && destinationImage != nullptr,
71         IMAGE_PROCESSING_ERROR_INVALID_PARAMETER, "parameter is null!");
72     auto destPixelmap = destinationImage->GetInnerPixelmap();
73     auto sourePixelmap = sourceImage->GetInnerPixelmap();
74     return Process(sourePixelmap, destPixelmap);
75 }
76 
ConvertColorSpace(OH_PixelmapNative * sourceImage,OH_PixelmapNative * destinationImage)77 ImageProcessing_ErrorCode ImageProcessingNativeBase::ConvertColorSpace(OH_PixelmapNative* sourceImage,
78     OH_PixelmapNative* destinationImage)
79 {
80     CHECK_AND_RETURN_RET_LOG(sourceImage != nullptr && destinationImage != nullptr,
81         IMAGE_PROCESSING_ERROR_INVALID_PARAMETER, "parameter is null!");
82     auto destPixelmap = destinationImage->GetInnerPixelmap();
83     return ConvertColorSpace(sourceImage->GetInnerPixelmap(), destPixelmap);
84 }
85 
Compose(OH_PixelmapNative * sourceImage,OH_PixelmapNative * sourceGainmap,OH_PixelmapNative * destinationImage)86 ImageProcessing_ErrorCode ImageProcessingNativeBase::Compose(OH_PixelmapNative* sourceImage,
87     OH_PixelmapNative* sourceGainmap, OH_PixelmapNative* destinationImage)
88 {
89     CHECK_AND_RETURN_RET_LOG(sourceImage != nullptr && destinationImage != nullptr && sourceGainmap != nullptr,
90         IMAGE_PROCESSING_ERROR_INVALID_PARAMETER, "parameter is null!");
91     auto destPixelmap = destinationImage->GetInnerPixelmap();
92     return Compose(sourceImage->GetInnerPixelmap(), sourceGainmap->GetInnerPixelmap(), destPixelmap);
93 }
94 
Decompose(OH_PixelmapNative * sourceImage,OH_PixelmapNative * destinationImage,OH_PixelmapNative * destinationGainmap)95 ImageProcessing_ErrorCode ImageProcessingNativeBase::Decompose(OH_PixelmapNative* sourceImage,
96     OH_PixelmapNative* destinationImage, OH_PixelmapNative* destinationGainmap)
97 {
98     CHECK_AND_RETURN_RET_LOG(sourceImage != nullptr && destinationImage != nullptr && destinationGainmap != nullptr,
99         IMAGE_PROCESSING_ERROR_INVALID_PARAMETER, "parameter is null!");
100     auto destPixelmap = destinationImage->GetInnerPixelmap();
101     auto destGainmapPixelmap = destinationGainmap->GetInnerPixelmap();
102     return Decompose(sourceImage->GetInnerPixelmap(), destPixelmap, destGainmapPixelmap);
103 }
104 
GenerateMetadata(OH_PixelmapNative * sourceImage)105 ImageProcessing_ErrorCode ImageProcessingNativeBase::GenerateMetadata(OH_PixelmapNative* sourceImage)
106 {
107     CHECK_AND_RETURN_RET_LOG(sourceImage != nullptr,
108         IMAGE_PROCESSING_ERROR_INVALID_PARAMETER, "parameter is null!");
109     return GenerateMetadata(sourceImage->GetInnerPixelmap());
110 }
111 
EnhanceDetail(OH_PixelmapNative * sourceImage,OH_PixelmapNative * destinationImage)112 ImageProcessing_ErrorCode ImageProcessingNativeBase::EnhanceDetail(OH_PixelmapNative* sourceImage,
113     OH_PixelmapNative* destinationImage)
114 {
115     CHECK_AND_RETURN_RET_LOG(sourceImage != nullptr && destinationImage != nullptr,
116         IMAGE_PROCESSING_ERROR_INVALID_PARAMETER, "parameter is null!");
117     auto destPixelmap = destinationImage->GetInnerPixelmap();
118     return EnhanceDetail(sourceImage->GetInnerPixelmap(), destPixelmap);
119 }
120 
InitializeInner()121 ImageProcessing_ErrorCode ImageProcessingNativeBase::InitializeInner()
122 {
123     return ImageEnvironmentNative::Get().InitializeByDefault();
124 }
125 
DeinitializeInner()126 ImageProcessing_ErrorCode ImageProcessingNativeBase::DeinitializeInner()
127 {
128     return ImageEnvironmentNative::Get().DeinitializeByDefault();
129 }
130 
SetParameter(const OHOS::Media::Format & parameter)131 ImageProcessing_ErrorCode ImageProcessingNativeBase::SetParameter([[maybe_unused]] const OHOS::Media::Format& parameter)
132 {
133     return IMAGE_PROCESSING_SUCCESS;
134 }
135 
GetParameter(OHOS::Media::Format & parameter)136 ImageProcessing_ErrorCode ImageProcessingNativeBase::GetParameter([[maybe_unused]] OHOS::Media::Format& parameter)
137 {
138     return IMAGE_PROCESSING_SUCCESS;
139 }
140 
Process(const std::shared_ptr<OHOS::Media::PixelMap> & sourceImage,std::shared_ptr<OHOS::Media::PixelMap> & destinationImage)141 ImageProcessing_ErrorCode ImageProcessingNativeBase::Process(
142     [[maybe_unused]] const std::shared_ptr<OHOS::Media::PixelMap>& sourceImage,
143     [[maybe_unused]] std::shared_ptr<OHOS::Media::PixelMap>& destinationImage)
144 {
145     return IMAGE_PROCESSING_SUCCESS;
146 }
147 
ConvertColorSpace(const std::shared_ptr<OHOS::Media::PixelMap> & sourceImage,std::shared_ptr<OHOS::Media::PixelMap> & destinationImage)148 ImageProcessing_ErrorCode ImageProcessingNativeBase::ConvertColorSpace(
149     [[maybe_unused]] const std::shared_ptr<OHOS::Media::PixelMap>& sourceImage,
150     [[maybe_unused]] std::shared_ptr<OHOS::Media::PixelMap>& destinationImage)
151 {
152     return IMAGE_PROCESSING_ERROR_UNSUPPORTED_PROCESSING;
153 }
154 
Compose(const std::shared_ptr<OHOS::Media::PixelMap> & sourceImage,const std::shared_ptr<OHOS::Media::PixelMap> & sourceGainmap,std::shared_ptr<OHOS::Media::PixelMap> & destinationImage)155 ImageProcessing_ErrorCode ImageProcessingNativeBase::Compose(
156     [[maybe_unused]] const std::shared_ptr<OHOS::Media::PixelMap>& sourceImage,
157     [[maybe_unused]] const std::shared_ptr<OHOS::Media::PixelMap>& sourceGainmap,
158     [[maybe_unused]] std::shared_ptr<OHOS::Media::PixelMap>& destinationImage)
159 {
160     return IMAGE_PROCESSING_ERROR_UNSUPPORTED_PROCESSING;
161 }
162 
Decompose(const std::shared_ptr<OHOS::Media::PixelMap> & sourceImage,std::shared_ptr<OHOS::Media::PixelMap> & destinationImage,std::shared_ptr<OHOS::Media::PixelMap> & destinationGainmap)163 ImageProcessing_ErrorCode ImageProcessingNativeBase::Decompose(
164     [[maybe_unused]] const std::shared_ptr<OHOS::Media::PixelMap>& sourceImage,
165     [[maybe_unused]] std::shared_ptr<OHOS::Media::PixelMap>& destinationImage,
166     [[maybe_unused]] std::shared_ptr<OHOS::Media::PixelMap>& destinationGainmap)
167 {
168     return IMAGE_PROCESSING_ERROR_UNSUPPORTED_PROCESSING;
169 }
170 
GenerateMetadata(const std::shared_ptr<OHOS::Media::PixelMap> & sourceImage)171 ImageProcessing_ErrorCode ImageProcessingNativeBase::GenerateMetadata(
172     [[maybe_unused]] const std::shared_ptr<OHOS::Media::PixelMap>& sourceImage)
173 {
174     return IMAGE_PROCESSING_ERROR_UNSUPPORTED_PROCESSING;
175 }
176 
EnhanceDetail(const std::shared_ptr<OHOS::Media::PixelMap> & sourceImage,std::shared_ptr<OHOS::Media::PixelMap> & destinationImage)177 ImageProcessing_ErrorCode ImageProcessingNativeBase::EnhanceDetail(
178     [[maybe_unused]] const std::shared_ptr<OHOS::Media::PixelMap>& sourceImage,
179     [[maybe_unused]] std::shared_ptr<OHOS::Media::PixelMap>& destinationImage)
180 {
181     return IMAGE_PROCESSING_ERROR_UNSUPPORTED_PROCESSING;
182 }
183