• 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 "media_log.h"
17 #include "data_center/effect/effect_image_effect.h"
18 #include "render/graphics/graphics_render_info.h"
19 
20 namespace {
21 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_VIDEOEDITOR, "DataCenter"};
22 }
23 
24 namespace OHOS {
25 namespace Media {
26 
EffectImageEffect(uint64_t id,const std::string & description)27 EffectImageEffect::EffectImageEffect(uint64_t id, const std::string& description)
28     : Effect(id, EffectType::IMAGE_EFFECT), description_(description)
29 {
30 }
31 
Init()32 VEFError EffectImageEffect::Init()
33 {
34 #ifdef IMAGE_EFFECT_SUPPORT
35     OH_ImageEffect* imageEffect = OH_ImageEffect_Restore(description_.c_str());
36     if (imageEffect == nullptr) {
37         MEDIA_LOGE("OH_ImageEffect_Restore failed.");
38         return VEFError::ERR_INTERNAL_ERROR;
39     }
40     MEDIA_LOGI("OH_ImageEffect_Restore finish.");
41     imageEffectHandler_ = std::shared_ptr<OH_ImageEffect>(imageEffect, [](OH_ImageEffect *imageEffect) {
42         auto ret = OH_ImageEffect_Release(imageEffect);
43         if (ret != EFFECT_SUCCESS) {
44             MEDIA_LOGE("OH_ImageEffect_Release failed, ret = %{public}d.", ret);
45         }
46     });
47     return VEFError::ERR_OK;
48 #else
49     MEDIA_LOGE("image effect is not supported.");
50     return VEFError::ERR_EFFECT_IS_NOT_SUPPORTED;
51 #endif
52 }
53 
GetRenderInfo() const54 std::shared_ptr<EffectRenderInfo> EffectImageEffect::GetRenderInfo() const
55 {
56     auto info = std::make_shared<EffectRenderInfo>();
57     info->id = id_;
58     info->type = EffectType::IMAGE_EFFECT;
59 #ifdef IMAGE_EFFECT_SUPPORT
60     info->imageEffect = this->imageEffectHandler_;
61 #endif
62     return info;
63 }
64 
65 } // namespace Media
66 } // namespace OHOS
67