From a00e54e762aa8500ba997444fd8750421b19f67d Mon Sep 17 00:00:00 2001 From: profezzorn Date: Sun, 13 Oct 2024 18:26:07 -0500 Subject: [PATCH] saves a little memory, cpu and ram --- styles/alpha.h | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/styles/alpha.h b/styles/alpha.h index af0a8b4cd..66e30fa94 100644 --- a/styles/alpha.h +++ b/styles/alpha.h @@ -41,7 +41,32 @@ class AlphaL { }; // To enable Gradient/Mixes constricted within Bump<> and SmoothStep<> layers -// Example: AlphaMixL,Int<16384>>,Red,Green,Blue> will produce a gradient within the Bump -template using AlphaMixL = AlphaL, MIX>; +// Example: AlphaMixL,Int<16384>>,Red,Green,Blue> will produce a gradient within the Bump +// template using AlphaMixL = AlphaL, MIX>; + +template +class AlphaMixL { +private: + PONUA MixHelper colors_; + PONUA MIX f_; +public: + LayerRunResult run(BladeBase* blade) { + f_.run(blade); + colors_.run(blade); + FunctionRunResult ret = RunFunction(&f_, blade); + if (ret == FunctionRunResult::ZERO_UNTIL_IGNITION) + return LayerRunResult::TRANSPARENT_UNTIL_IGNITION; + return LayerRunResult::UNKNOWN; + } + auto getColor(int led) -> decltype(colors_.getColor(1,1) * 1) { + int alpha = f_.getInteger(led); + if (alpha == 0) return RGBA_um_nod::Transparent(); + int x = alpha * (sizeof...(COLORS) + 1); + auto a = colors_.getColor(x >> 15, led); + auto b = colors_.getColor((x >> 15) + 1, led); + auto ret = MixColors(a, b, x & 0x7fff, 15); + return ret * alpha; + } +}; #endif