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 #ifndef BLOOM_JS_H 16 #define BLOOM_JS_H 17 #include <napi_api.h> 18 #include <scene/interface/intf_scene.h> 19 class BloomConfiguration { 20 public: 21 enum class Quality : uint32_t { LOW = 1, NORMAL = 2, HIGH = 3 }; 22 enum class Type : uint32_t { NORMAL = 1, HORIZONTAL = 2, VERTICAL = 3, BILATERAL = 4 }; 23 24 BloomConfiguration(); 25 ~BloomConfiguration(); 26 void SetFrom(NapiApi::Object obj); 27 28 static BloomConfiguration* Unwrap(NapiApi::Object obj); 29 30 NapiApi::StrongRef Wrap(NapiApi::Object obj); 31 32 void SetTo(NapiApi::Object obj); 33 void SetFrom(SCENE_NS::IBloom::Ptr bloom); 34 void SetTo(SCENE_NS::IBloom::Ptr bloom); 35 SCENE_NS::IPostProcess::Ptr GetPostProc(); 36 void SetPostProc(SCENE_NS::IPostProcess::Ptr postproc); 37 38 private: 39 napi_value Dispose(NapiApi::FunctionContext<>& ctx); 40 void Detach(); 41 napi_value GetAmount(NapiApi::FunctionContext<>& ctx); 42 void SetAmount(NapiApi::FunctionContext<float>& ctx); 43 napi_value GetThresholdSoft(NapiApi::FunctionContext<>& ctx); 44 void SetThresholdSoft(NapiApi::FunctionContext<float>& ctx); 45 napi_value GetThresholdHard(NapiApi::FunctionContext<>& ctx); 46 void SetThresholdHard(NapiApi::FunctionContext<float>& ctx); 47 48 napi_value GetScatter(NapiApi::FunctionContext<>& ctx); 49 void SetScatter(NapiApi::FunctionContext<float>& ctx); 50 napi_value GetScaleFactor(NapiApi::FunctionContext<>& ctx); 51 void SetScaleFactor(NapiApi::FunctionContext<float>& ctx); 52 53 napi_value GetType(NapiApi::FunctionContext<>& ctx); 54 void SetType(NapiApi::FunctionContext<uint32_t>& ctx); 55 napi_value GetQuality(NapiApi::FunctionContext<>& ctx); 56 void SetQuality(NapiApi::FunctionContext<uint32_t>& ctx); 57 58 template<napi_value (BloomConfiguration::*F)(NapiApi::FunctionContext<>&)> 59 static napi_value Method(napi_env env, napi_callback_info info); 60 61 template<napi_value (BloomConfiguration::*F)(NapiApi::FunctionContext<>&)> 62 static napi_value Getter(napi_env env, napi_callback_info info); 63 template<typename Type, void (BloomConfiguration::*F)(NapiApi::FunctionContext<Type>&)> 64 static inline napi_value Setter(napi_env env, napi_callback_info info); 65 SCENE_NS::IPostProcess::Ptr postproc_; // postprocess object owning the bloom 66 SCENE_NS::IBloom::Ptr bloom_; // bloom object from postproc_ 67 napi_ref ref_ { nullptr }; 68 float thresholdHard_ { 1.0f }; 69 float thresholdSoft_ { 2.0f }; 70 float amountCoefficient_ { 0.25f }; 71 float scatter_ { 1.0f }; 72 float scaleFactor_ { 1.0f }; 73 BloomConfiguration::Type type_ { BloomConfiguration::Type::NORMAL }; 74 BloomConfiguration::Quality quality_ { BloomConfiguration::Quality::NORMAL }; 75 SCENE_NS::EffectQualityType GetQuality(BloomConfiguration::Quality bloomQualityType); 76 BloomConfiguration::Quality SetQuality(SCENE_NS::EffectQualityType bloomQualityType); 77 78 SCENE_NS::BloomType GetType(BloomConfiguration::Type bloomType); 79 BloomConfiguration::Type SetType(SCENE_NS::BloomType bloomTypeIn); 80 }; 81 82 #endif 83