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