Let's say I have a background layer (
B) filled with
RGB 255 115 0, and a foreground layer (
F) filled with
RGB 64 64 64. Both layers are in
Normal blending mode, the opacity on
F is 80%. The resulting color is
RGB 135 78 57.
I would like to calculate the color with a script, so I searched about the formula used to interpolate between the two colors, and found this (linear interpolation)
C = F*alpha + B*(1-alpha)
So, I normalized the values to be in the range
0..1, by dividing the three color channels by 255 and the opacity by 100. Then I applied the formula above and multipied the channels of the resulting color by 255, rounding to the nearest integer, to obtain the RGB values of the resulting color
However, the values calculated by me are
102 74 51, which are different from those obtained by creating the color in GIMP.
Am I making wrong assumptions, or is the actual formula used by GIMP different?
Thanks to @xenoid, I made my own experiments and I can confirm: if I switch to
Legacy the values are the same as what I have computed.
Searching about linear light I stumbled upon this: Image Precision, and found some slight differences. Let's assume that
F is the top layer filled with
RGB 64 64 64 at 80% opacity and
B is the bottom layer filled with
RGB 255 115 46.
C will be the color computed by the formula given above.
Precision 8-bit Linear Light I came up with these results:
C: 102 74 60 Legacy: 102 75 61 Default: 102 75 61
Precision 8-bit Perceptual Gamma (sRGB):
C: 102 74 60 Legacy: 102 74 60 Default: 135 78 61
It seems that working with
Perceptual Gamma and using
Legacy mode gives an exact match with the values computed with the formula.