The patch looks almost correct, except the fact that the values may become denormalized for integer color spaces during multiplications and divisions. Please use functions from Arithmetc namespace for all the operations that involve multiplication and division. It will make the code support all the types of color spaces.

Instead of direct multiplication and division operations (and pow() function), one should use functions from Arithmetic namespace here. Otherwise, the values may become denormalized (e.g. int8 colorspaces are normalized in range 0...255 instead of standard 0...1.0). E.e. this line should look like:

-I have attempted to solve the issue of code formatting by using a helper blending mode, and the formatting goes on the line of inv(x) where x is the base equation used for blending mode calculation. So, thus, it fit the code requirement. There is no other approach that doesn't have the issue of not fitting the code and avoids long long int error.

What's next? It is to solve the discrepancies between color depth for Heat, and Freeze as it's pretty severe now. And then, the testing phase can continue.

I'm not sure how to fix this issue, but if it can be fixed, then I believe the discrepancies between depth would be gone. Some even dip to -150, but this doesn't happen with 8-bit integer.

A theoretical way to solve this issue is to somehow have src and dst on the range of 0,255 with decimals restricted to .5 steps. Like src and dst are forced in those range, and estimated to .5 steps. I am not sure how to code that.

I have made a small patch (should be applied on the top of your patch) that fixes a few issues in the code. Please check if it behaves correct. If so, I will push it either to master or to some branch so painters could test it.

The changes are based on the dkazakov's patch with a slight change. I removed the additional line of glow as it leads to 0,1,1 result on areas where they are not supposed to show up on. I also applied the break bracket on Glow, and Heat to make the code faster. Everything works as expected.

-Finally, there's a comment on the code as there are issues with Heat, and Freeze.

Sidenote: Now, I learned how to get inv(with long formula here) working thanks to Dmitry.

The main thing we need to calibrate is the .04 number. I am leaning to Formula 2. I'll start on working on making 2 new blending modes, and they'll be called F-Heat, and F-Freeze. F should indicates that they can be used for 16-bit and higher.

I decided to remove this as there was issues with the rendering result that leads to undesirable result like 0, 1, 1 among many areas. Now, I followed your suggestion of (Code()) {return;} for heat and freeze during the meantime.