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_CUSTOM_EFILTER_H 17 #define IMAGE_EFFECT_CUSTOM_EFILTER_H 18 19 #include <string> 20 #include <mutex> 21 22 #include "any.h" 23 #include "effect_log.h" 24 #include "efilter_factory.h" 25 #include "error_code.h" 26 27 namespace OHOS { 28 namespace Media { 29 namespace Effect { 30 class CustomEFilter : public EFilter { 31 public: CustomEFilter(const std::string & name)32 explicit CustomEFilter(const std::string &name) : EFilter(name) 33 { 34 EFFECT_LOGI("CustomEFilter Constructor name = %{public}s", name.c_str()); 35 delegate_ = EFilterFactory::Instance()->GetDelegate(name); 36 } 37 38 ~CustomEFilter() override = default; 39 40 ErrorCode Render(EffectBuffer *buffer, std::shared_ptr<EffectContext> &context) override; 41 42 ErrorCode Render(EffectBuffer *src, EffectBuffer *dst, std::shared_ptr<EffectContext> &context) override; 43 44 ErrorCode SetValue(const std::string &key, Plugin::Any &value) override; 45 46 ErrorCode Save(EffectJsonPtr &res) override; 47 48 ErrorCode Restore(const EffectJsonPtr &value) override; 49 50 static void SetEffectInfo(const std::string &name, const std::shared_ptr<EffectInfo> &effectInfo); 51 52 static std::shared_ptr<EffectInfo> GetEffectInfo(const std::string &name); 53 SetHandler(void * handler)54 void SetHandler(void *handler) 55 { 56 handler_ = handler; 57 } 58 59 private: 60 std::shared_ptr<IFilterDelegate> delegate_; 61 void *handler_ = nullptr; 62 static std::map<std::string, std::shared_ptr<EffectInfo>> effectInfos_; 63 static std::mutex effectInfosMutex_; 64 }; 65 } // namespace Effect 66 } // namespace Media 67 } // namespace OHOS 68 69 #endif // IMAGE_EFFECT_CUSTOM_EFILTER_H