I wanted to try using Blend Algebra to recreate Gimp's blend types inside CinGG. I couldn't because I don't really understand the formulas used by Gimp, or rather, what I understand less are the formulas used by CinGG. I understand that these are pre-multiplied while Gimp's are normal (“straight”). But even without taking this into account, I don't really understand how to compare the formulas (https://docs.gimp.org/3.0/en/gimp-concepts-layer-modes-legacy.html). For example, for the “Multiply” blend we have two different formulas, even though the manual says that the CinGG formula is the same as the Gimp formula: Gimp E = 1/255*(M*I) where “M” (foreground), if I understand correctly, corresponds to our “D” and “I” (background) corresponds to our “S” so it could be written: E = 1/255*(D*S) Instead, CinGG's formula is: [(Sa+Da-Sa*Da), Sc*(1-Da)+Dc*(1-Sa)+Sc*Dc] I cannot compare the two formulas, there is one too many Sc*(1-Da) and one too many Dc*(1-Sa), and a 1/255 is missing. Note: The presence of the parentheses like (1-Sa) is what makes me suspect that CinGG's formulas are “pre-multiplied” (https://en.wikipedia.org/wiki/Alpha_compositing#Straight_versus_premultiplie....) There are three types of blends whose formulas differ (and which I wanted to implement via Blend Algebra): (Normal); Addition; Subtract and Divide. Then there are Gimp blends that CinGG doesn't have, but they don't seem interesting to me. PS: I tried to look for the formulas used by CinCV but I don't know where to find them; do they exist anywhere?
On Tue, 25 Mar 2025, Andrea paz via Cin wrote:
Gimp
E = 1/255*(D*S)
Instead, CinGG's formula is:
[(Sa+Da-Sa*Da), Sc*(1-Da)+Dc*(1-Sa)+Sc*Dc]
I cannot compare the two formulas, there is one too many Sc*(1-Da) and one too many Dc*(1-Sa), and a 1/255 is missing.
Andrea, 1/255 is just the normalization coefficient to bring the unsigned byte range [0-255] to the normalized range [0.0-1.0]. This coefficient is correct for (and only for) the color model RGB 8-bit. For CinGG the things are more variative. For example, if we have RGB-10bit, RGB-12bit, etc. than the 1/255 coefficient is not valid any more. In addition, CinGG has color model RGB-float whose range is [0.0-1.0] already and requires no normalization coefficient at all. To make it easier and more consistent, Blend Algebra transforms the actual color model to float and brings it in the range [0.0-1.0] before executing user's function. Thus, the 1/255, or whatever normalization coefficient in Blend Algebra is taken into account intrinsically.
There are three types of blends whose formulas differ (and which I wanted to implement via Blend Algebra): (Normal); Addition; Subtract and Divide.
Andrea, you can just try your own Blend Algebra functions according to formula of Gimp, modify them and test the resulting look. In Blend Algebra you do not need 1/255, nor any other normalization, it is intrinsic there. Also pay attention, what are source and destination, and the track order in the dialog, sometimes it can be counterintuitive:(
PS: I tried to look for the formulas used by CinCV but I don't know where to find them; do they exist anywhere?
Don't search the working formula in Cinelerra's (any branch) source code, they are horrible. _______________________________________________________________________________ Georgy Salnikov NMR Group Novosibirsk Institute of Organic Chemistry Lavrentjeva, 9, 630090 Novosibirsk, Russia Phone +7-383-3307864 Email [email protected] _______________________________________________________________________________
I tried Multiply blend in Blend Algebra whit the gimp's formula (based on arith_multiply.ba, which I called gimp_multiply.ba). It works without the normalization (which, as you said, is implicit in CinGG): R_OUT = (R(s) * R(d)); G_OUT = (G(s) * G(d)); B_OUT = (B(s) * B(d)); A_OUT = A(s) + A(d) - A(s) * A(d); The result is the same as CinGG's formula and Patchbay's overlay. This seems normal to me since they should be the same formula. The alpha channel line is irrelevant, everything works with or without this line. So gimp_multiply.ba is equivalent to arith_multiply.ba. I don't understand why, though. Adam or GG must have used a “way” to translate the Gimp formulas into their own formulas in CinGG, but I don't understand this way. I tried to create the Divide, Addition and Subtract formulas (which, I recall, are different in CinGG from those in Gimp): Divide(gimp): E = (S * 256) / (D + S) Addition(gimp): E = min((D + S), 255) Subtract(gimp): E = max((S - D), 0) I created gimp_addition.ba and gimp_subtract.ba and they work, but they are useless because you get the exact same result as the ones in CinGG. I thought that since the formulas are different you get slightly different results. I attach them for those who want to test or as a curiosity, but I repeat that they are useless. Instead I don't know how to do gimp_divide.ba because of the parameter “256” which I don't know how to use.
On Wed, 26 Mar 2025, Andrea paz wrote:
Divide(gimp): E = (S * 256) / (D + S)
Addition(gimp): E = min((D + S), 255)
Subtract(gimp): E = max((S - D), 0)
know how to do gimp_divide.ba because of the parameter \u201c256\u201d which I don't know how to use.
When adapting blend formula taken from somewhere, to CinGG's Blend Algebra, in each place where you find either 256 or 255, change it to 1.0, and in every place where you see 128 or 127, with either plus or minus sign, change it to 0.5 with the same sign. These all digits are nothing else than normalization coefficients to convert 8-bit integers to floats, which are preconverted in Blend Algebra. _______________________________________________________________________________ Georgy Salnikov NMR Group Novosibirsk Institute of Organic Chemistry Lavrentjeva, 9, 630090 Novosibirsk, Russia Phone +7-383-3307864 Email [email protected] _______________________________________________________________________________
participants (2)
-
Andrea paz -
Georgy Salnikov