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 #ifndef IMAGE_EFFECT_NATIVE_BASE_H
17 #define IMAGE_EFFECT_NATIVE_BASE_H
18 
19 #include <memory>
20 #include <utility>
21 #include <unordered_set>
22 
23 #include "efilter.h"
24 #include "image_effect_inner.h"
25 #include "image_effect_filter.h"
26 
27 struct OH_EffectFilter {
28     std::shared_ptr<OHOS::Media::Effect::EFilter> filter_ = nullptr;
29     void SetParameter(const std::string &key, OHOS::Media::Plugin::Any &param);
30     OHOS::Media::Effect::ErrorCode GetParameter(const std::string &key, OHOS::Media::Plugin::Any &param);
31     void RemoveParameter(const std::string &key);
32     bool isCreatedBySystem_ = false;
33 private:
34     std::unordered_map<std::string, OHOS::Media::Plugin::Any&> params_;
35 };
36 
37 struct OH_ImageEffect {
38     OH_ImageEffect() = default;
39     std::shared_ptr<OHOS::Media::Effect::ImageEffect> imageEffect_ = nullptr;
40     char *saveJson = nullptr;
41     std::vector<std::pair<OH_EffectFilter *, std::string>> filters_;
~OH_ImageEffectOH_ImageEffect42     ~OH_ImageEffect()
43     {
44         if (saveJson != nullptr) {
45             delete saveJson;
46             saveJson = nullptr;
47         }
48         for (const auto &filter : filters_) {
49             auto ohEFilter = filter.first;
50             if (ohEFilter != nullptr && ohEFilter->isCreatedBySystem_) {
51                 OH_EffectFilter_Release(filter.first);
52             }
53         }
54         filters_.clear();
55     }
56 };
57 
58 struct OH_EffectFilterInfo {
59     OH_EffectFilterInfo() = default;
60     ~OH_EffectFilterInfo();
61     std::string filterName = "";
62     std::unordered_set<ImageEffect_BufferType> supportedBufferTypes;
63     std::unordered_set<ImageEffect_Format> supportedFormats;
64 
65     ImageEffect_BufferType *effectBufferType = nullptr;
66     uint32_t bufferTypeArraySize = 0;
67     ImageEffect_Format *effectFormat = nullptr;
68     uint32_t formatArraySize = 0;
69 };
70 
71 struct OH_EffectBufferInfo {
72     void *addr = nullptr;
73     int32_t width = 0;
74     int32_t height = 0;
75     int32_t rowSize = 0;
76     ImageEffect_Format format = ImageEffect_Format::EFFECT_PIXEL_FORMAT_UNKNOWN;
77     int64_t timestamp = 0;
78 };
79 
80 #endif // IMAGE_EFFECT_NATIVE_BASE_H