Opacity formula in GIMP 2.10.0

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 C.

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.

With Precision 8-bit Linear Light I came up with these results:

C:       102 74 60
Legacy:  102 75 61
Default: 102 75 61

With 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.


When you use the 0..255 range you are likely in a gamma-corrected image. To compute the resulting color, Gimp converts the 0..255 value to “linear light” applies your composition formula, and reapplies the gamma correction. So the composition is really applied with darker colors.

However, since Gimp 2.10 you can work in gamma-corrected or “linear” light. This has an effect on blend modes so you have the choice between “default” and “legacy” modes (this is the small selector on the right of the blend mode selector). In practice, if you work in linear light, the legacy modes don’t perform any gamma correction, and using “Normal (legacy)” will produce the output you computed:

Top: “default” mode, bottom: “legacy” mode.

enter image description here

Source : Link , Question Author : Russell Teapot , Answer Author : xenoid

Leave a Comment