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_change_effect.h"
17 #include "media_log.h"
18 #ifdef IMAGE_EFFECT_SUPPORT
19 #include "plugin/common/any.h"
20 #include "image_effect_inner.h"
21 #endif
22 #include <memory>
23
24 using std::string;
25
26 namespace OHOS {
27 namespace Media {
28
29 #ifdef IMAGE_EFFECT_SUPPORT
ParseInt(Effect::ErrorCode input)30 int32_t ParseInt(Effect::ErrorCode input)
31 {
32 return static_cast<int32_t>(input);
33 }
34 #endif
35
TakeEffect(const string & inputPath,const string & outputPath,string & editdata)36 int32_t MediaChangeEffect::TakeEffect(const string &inputPath, const string &outputPath, string &editdata)
37 {
38 #ifdef IMAGE_EFFECT_SUPPORT
39 Effect::ErrorCode ret = Effect::ErrorCode::ERR_UNKNOWN;
40 std::shared_ptr<Effect::ImageEffect> imageEffect = Effect::ImageEffect::Restore(editdata);
41 CHECK_AND_RETURN_RET(imageEffect != nullptr, ParseInt(ret));
42
43 ret = imageEffect->SetInputPath(inputPath);
44 CHECK_AND_RETURN_RET(ret == Effect::ErrorCode::SUCCESS, ParseInt(ret));
45
46 ret = imageEffect->SetOutputPath(outputPath);
47 CHECK_AND_RETURN_RET(ret == Effect::ErrorCode::SUCCESS, ParseInt(ret));
48
49 ret = imageEffect->Start();
50 CHECK_AND_RETURN_RET(ret == Effect::ErrorCode::SUCCESS, ParseInt(ret));
51 #endif
52 return 0;
53 }
54
TakeEffectForPicture(std::shared_ptr<Media::Picture> & inPicture,string & editData)55 int32_t MediaChangeEffect::TakeEffectForPicture(std::shared_ptr<Media::Picture> &inPicture, string &editData)
56 {
57 #ifdef IMAGE_EFFECT_SUPPORT
58 Effect::ErrorCode ret = Effect::ErrorCode::ERR_UNKNOWN;
59 std::shared_ptr<Effect::ImageEffect> imageEffect = Effect::ImageEffect::Restore(editData);
60 CHECK_AND_RETURN_RET(imageEffect != nullptr, ParseInt(ret));
61
62 ret = imageEffect->SetInputPicture(inPicture.get()); // 原图修改
63 CHECK_AND_RETURN_RET(ret == Effect::ErrorCode::SUCCESS, ParseInt(ret));
64
65 ret = imageEffect->Start();
66 CHECK_AND_RETURN_RET(ret == Effect::ErrorCode::SUCCESS, ParseInt(ret));
67 #endif
68 return 0;
69 }
70
71 } // end of namespace
72 }
73