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 #include "image_effect_marco_define.h" 23 #include "efilter.h" 24 #include "image_effect_inner.h" 25 #include "image_effect_filter.h" 26 #include "effect_log.h" 27 28 /** 29 * @struct OH_EffectFilter 30 * @brief Structure representing an effect filter. 31 */ 32 struct OH_EffectFilter { 33 std::shared_ptr<OHOS::Media::Effect::EFilter> filter_ = nullptr; // Shared pointer to EFilter object 34 void SetParameter(const std::string &key, OHOS::Media::Any ¶m); // Sets a filter parameter 35 OHOS::Media::Effect::ErrorCode GetParameter(const std::string &key, OHOS::Media::Any ¶m); 36 void RemoveParameter(const std::string &key); // Removes a filter parameter 37 bool isCreatedBySystem_ = false; // Flag indicating if the filter was created by the system 38 private: 39 std::unordered_map<std::string, OHOS::Media::Any&> params_; // Map of filter parameters 40 }; 41 42 /** 43 * @struct OH_ImageEffect 44 * @brief Structure representing an image effect. 45 */ 46 struct OH_ImageEffect { 47 OH_ImageEffect() = default; 48 std::shared_ptr<OHOS::Media::Effect::ImageEffect> imageEffect_ = nullptr; 49 char *saveJson = nullptr; 50 std::vector<std::pair<OH_EffectFilter *, std::string>> filters_; ~OH_ImageEffectOH_ImageEffect51 ~OH_ImageEffect() 52 { 53 EFFECT_LOGI("OH_ImageEffect release enter"); 54 if (saveJson != nullptr) { 55 delete[] saveJson; 56 saveJson = nullptr; 57 } 58 for (const auto &filter : filters_) { 59 auto ohEFilter = filter.first; 60 if (ohEFilter != nullptr && ohEFilter->isCreatedBySystem_) { 61 OH_EffectFilter_Release(filter.first); 62 } 63 } 64 filters_.clear(); 65 EFFECT_LOGI("OH_ImageEffect release end"); 66 } 67 }; 68 69 /** 70 * @struct OH_EffectFilterInfo 71 * @brief Structure representing information about an effect filter. 72 */ 73 struct OH_EffectFilterInfo { 74 OH_EffectFilterInfo() = default; 75 IMAGE_EFFECT_EXPORT ~OH_EffectFilterInfo(); 76 std::string filterName = ""; 77 std::unordered_set<ImageEffect_BufferType> supportedBufferTypes; 78 std::unordered_set<ImageEffect_Format> supportedFormats; 79 80 ImageEffect_BufferType *effectBufferType = nullptr; 81 uint32_t bufferTypeArraySize = 0; 82 ImageEffect_Format *effectFormat = nullptr; 83 uint32_t formatArraySize = 0; 84 }; 85 86 /** 87 * @struct OH_EffectBufferInfo 88 * @brief Structure representing information about an effect buffer. 89 */ 90 struct OH_EffectBufferInfo { 91 void *addr = nullptr; 92 int32_t width = 0; 93 int32_t height = 0; 94 int32_t rowSize = 0; 95 ImageEffect_Format format = ImageEffect_Format::EFFECT_PIXEL_FORMAT_UNKNOWN; 96 int64_t timestamp = 0; 97 int32_t textureId = 0; 98 }; 99 100 #endif // IMAGE_EFFECT_NATIVE_BASE_H