Can't seem to solve this thorny issue for creating new blending modes for Krita

This is a question for those who knows C++, Krita and QT. I’m getting negative values with a code I’m using, and I"m not seeing any possible way to fix it.

-Equations here - Pegtop delphi

See the picture. All negative values, and I do not know how to fix this issue. Freeze and Heat works just fine and dandy only in 8-bit integer. But elsewhere besides LAB? Don’t get me started.

I know that mathematically, there will be negative values, and I have tested to verify that’s the issue, but is there a way out of that? They function great on 8-bit.

On excel, I got a value of -11531356.75 with two different channel value.

If I can somehow force numbers to be at 0-255 range, and round digits to ,1. That would definitely solve the issue. There would less dark colors as a result and comes out looking a bit more like the 8-bit result.

EDIT: I believe I am one step closer to solving this. I figured out how to force numbers to be in 8-bit form. Also, I think I might create 1-bit, 2-bit, 3-bit,4-bit,5-bit… blending modes in light of this finding. I know using this will add into posterization, but that can be solved easily.

EDIT: Nope, I gotten -inf…

Since 2^16 = 65536 and 2^32 = 4294967296. In your formulae, depending on the 8 bit or 16 bit or 32 bit image, you will have to equate 1 with 65534 etc. Isn’t it? So, first one should see the bit depth and then use corresponding number as 1. That way getting negative values is eliminated (I think).

The thing is, I am not sure on how to code that. I would love to be able to apply conditional ruling based on color depth. Krita also support float values, so that is another problem. A universal way is to plugin 1/255*unitValue as step restriction.

In GIMP, if we duplicate a layer with say Screen blend mode, the effect gets multiplied. If the same applies to Krita, then you can use the 2^32 - 1 as the value of 1 in your formulas and then duplicate the layer and merge if it is 16 bit image and duplicate twice and merge if it is 8 bit. Does this make sense?

In Krita, formulas are always 0-1 form if I use unitValue, and the calculation are based on depth. It works the same in GIMP. I actually do not think that there is a real solution to this thorny issue besides having to program a lot more than just what’s in the code change listed in phabricator. I really like the freeze, and heat blend mode, and if I can force the blend modes to treat both layers as 8-bit, and use differences to take into account of numbers to match the requirement of 16-bit and 32-bit to avoid posterization, then these blending modes would be a godsend. Freeze is just a beautiful blend mode under 8-bit.

Now, I’m looking into combining different blend modes from existing ones to see if I can get similar effect. Once I do, I will code that in, and push the differential. It won’t be exact, but it is the best workaround. It also will be very difficult to code in since I’m using multiple blend modes over another.

EDIT: I think I am finding a solution here -

8-Bit -

16-Bit -

It’s not quite exact, but it’s getting there and the solution might be found.

EDIT: I believe I found the solution. Thing is, coding it will be a pain in the arse.

1 Like