• 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 "colorspace_manager.h"
17 
18 #include "effect_log.h"
19 #include "colorspace_converter.h"
20 
21 namespace OHOS {
22 namespace Media {
23 namespace Effect {
ColorSpaceManager()24 ColorSpaceManager::ColorSpaceManager()
25 {
26     strategy_ = std::make_shared<ColorSpaceStrategy>();
27 }
28 
IsNeedConvertColorSpace(EffectColorSpace colorSpace)29 bool ColorSpaceManager::IsNeedConvertColorSpace(EffectColorSpace colorSpace)
30 {
31     return ColorSpaceStrategy::IsNeedConvertColorSpace(colorSpace);
32 }
33 
IsSupportedColorSpace(EffectColorSpace colorSpace)34 bool ColorSpaceManager::IsSupportedColorSpace(EffectColorSpace colorSpace)
35 {
36     return ColorSpaceStrategy::IsSupportedColorSpace(colorSpace);
37 }
38 
GetAllSupportedColorSpaces()39 std::unordered_set<EffectColorSpace> ColorSpaceManager::GetAllSupportedColorSpaces()
40 {
41     return ColorSpaceStrategy::GetAllSupportedColorSpaces();
42 }
43 
Init(std::shared_ptr<EffectBuffer> & src,std::shared_ptr<EffectBuffer> & dst)44 void ColorSpaceManager::Init(std::shared_ptr<EffectBuffer> &src, std::shared_ptr<EffectBuffer> &dst)
45 {
46     strategy_->Init(src, dst);
47 }
48 
ApplyColorSpace(EffectBuffer * effectBuffer,const EffectColorSpace & colorSpace,EffectColorSpace & outputColorSpace)49 ErrorCode ColorSpaceManager::ApplyColorSpace(EffectBuffer *effectBuffer, const EffectColorSpace &colorSpace,
50     EffectColorSpace &outputColorSpace)
51 {
52     CHECK_AND_RETURN_RET_LOG(effectBuffer != nullptr, ErrorCode::ERR_INPUT_NULL,
53         "ApplyColorSpace: effectBuffer is null!");
54     if (!IsNeedConvertColorSpace(colorSpace)) {
55         outputColorSpace = colorSpace;
56         return ErrorCode::SUCCESS;
57     }
58 
59     EffectColorSpace targetColorSpace = ColorSpaceStrategy::GetTargetColorSpace(colorSpace);
60     ErrorCode res = strategy_->CheckConverterColorSpace(targetColorSpace);
61     CHECK_AND_RETURN_RET_LOG(res == ErrorCode::SUCCESS, res,
62         "ApplyColorSpace: CheckConverterColorSpace fail! res=%{public}d", res);
63 
64     res = ColorSpaceConverter::ApplyColorSpace(effectBuffer, targetColorSpace);
65     CHECK_AND_RETURN_RET_LOG(res == ErrorCode::SUCCESS, res, "ApplyColorSpace: convert fail! "
66         "res=%{public}d, colorSpace=%{public}d, targetColorSpace=%{public}d", res, colorSpace, targetColorSpace);
67     outputColorSpace = targetColorSpace;
68 
69     return ErrorCode::SUCCESS;
70 }
71 
ChooseColorSpace(const std::unordered_set<EffectColorSpace> & filtersSupportedColorSpace,const EffectColorSpace & srcRealColorSpace,EffectColorSpace & outputColorSpace)72 ErrorCode ColorSpaceManager::ChooseColorSpace(const std::unordered_set<EffectColorSpace> &filtersSupportedColorSpace,
73     const EffectColorSpace &srcRealColorSpace, EffectColorSpace &outputColorSpace)
74 {
75     return strategy_->ChooseColorSpace(filtersSupportedColorSpace, srcRealColorSpace, outputColorSpace);
76 }
77 
Deinit()78 void ColorSpaceManager::Deinit()
79 {
80     strategy_->Deinit();
81 }
82 
83 } // namespace Effect
84 } // namespace Media
85 } // namespace OHOS