Maybe this exists somewhere in the FastLED code but I couldn't find it...

Maybe this exists somewhere in the FastLED code but I couldn’t find it… Does anyone know an int math only color blend algorithm? I’m used to using the screen algorithm ( 1.0 - (1.0 - a)*(1.0 - b)) but it is very dependent on the values being 0.0 - 1.0. I would like to be able to take pre-existing RGB pixel colors and blend them with a new color for overlays and such. But, the above version is quite slow.

Check out the wiki in the Github about… Either high performance math, or pixel reference, I forget which and I’m on my phone. Theres examples of tinting, color addition, as well as interpolation, which was discussed in another post recently :slight_smile:

That does have adding of color values, but not really what I was looking for. It’s too basic. Screen blend will result in a brighter color, however, blending two of the same color should result in effectively the same color value. But if I added 50% green and 50% green with the methods on that wiki page I would end up with 100% green.
It doesn’t have to been a screen blend, even multiple would be close enough if it gave me a performance boost.

Try for each channel r g b:

New = 255 - scale8( 255 - A, 255 - B);

Hmmm… looks like that could work. Will give it a shot and compare to pre-existing float code :slight_smile:

It does the same thing, but about 20X faster. I’m guessing :slight_smile:

That worked! Thanks so much!
Side note… also needing to use that blending in python. Will be a huge help to not need float math :slight_smile:

You could use the nblend() in FastLED, which basically does the same scale8() calls for each channel. It’s defined in ColorUtils.cpp

Well, nblend uses a different algorithm from the one described in the OP. nblend let’s you specify what fraction of each you want to mix. This newer algorithm is more of a pure this-plus-that, but not at all using “plus”. It’s interesting and I’m going to want to look at it. Maybe wrap it into the library if it makes sense.

Good to know about, but yeah, not what I was looking for.
For reference, this is a great resource for blending algorithms: http://en.wikipedia.org/wiki/Blend_modes
I write photoshop plugins for a living, so it’s stuff I deal with on a daily basis. The most typical are screen and multiply. Just different approaches, but screen usually results in the same brightness maybe a tiny bit more and multiply (Despite its name) typically ends with less brightness.
Functions like those built into FastLED would be super useful, in my opinion :slight_smile:

Sorry about that, I should learn not to answer if I don’t read the question properly!
The reference link on the wiki resource you posted has some interesting macros for blending, most of which work in the integer domain: http://stackoverflow.com/questions/5919663/how-does-photoshop-blend-two-images-together