I have experience with image processing, but I am fairly new to GIMP. I was experimenting combining layers that have transparency, and the pixel values that GIMP computes do not agree with the equation I've seen posted on GIMP and photoshop web sites.

Here's a specific example. The math here applies to a single pixel, but for convenience I'll assume that I have images with the same pixel value everywhere. Start with a 4-band image, where the RGB values are all 128, and the alpha layer is all 255, or as a fraction 1.0. Use that as your base layer. Now put on top of that another layer that has RGB values of 0 and an alpha value of 191, or as a fraction, 191/255 = 0.749. When those layers get combined in GIMP, I thought it was done mathematically using the following equation: output value = basePixel*(1 - topAlpha) + topPixel*(topAlpha) = 128*(1 - 0.749) + 0*0.749 = 32. That's not what I get with GIMP. I get a value of 66. Apparently I'm using the wrong equation. Does anyone know the answer?

I should point out that the equation seems to work when the top layer is 255, but it does not work when the top layer is dark, e.g. 0, like in my example. This suggests to me that GIMP is not using the equation presented above.

For what it's worth, the blend mode is set to normal.

Here's a screen shot.128 gray alpha 255 base, 0 black top layer opacity 75%

The comments you made about Legacy, Default, and Gamma are foreign to me. It's not clear to me how they would affect the answer.

1 Answer 1


Better use 0.0 ... 1.0 values for the RGB channels. So putting a white layer (1.0,1.0,1.0) (aka (255,255,255)) with opacity 0.75 above a (0.5,0.5,0.5) (aka (127,127,127)) layer:

output= 0.5*(1.00-0.75) + 1.00*0.75
      = 0.5*0.25 + 0.75
      = 0.125 + 0.750
      = 0.875

And 0.875 in the 0..255 range is 223. But even using the 0 ... 255 range:

output= 128*(1.00-0.75) + 255*0.75
      = 128*0.25 + 191.5
      = 32 + 191.25
      = 223

And the Pointer tool agrees:

enter image description here

With black and alpha=0.75 on top of 128:

output= 128*(1.00-0.75) + 0*0.75
      = 128*0.25 + 0.0
      = 32 + 0
      = 32

And the pointer tools agrees with this:

enter image description here

PS: also depends which Gimp we talk about. The above is true for:

  • Gimp 2.8
  • Gimp 2.10 in Legacy Normal mode in a gamma image
  • Gimp 2.10 in Default Normal mode in a linear-light image

And works as you report in 2.10 using Default Normal on a gamma image, which must imply a conversion to linear, then the composition, and then a conversion back to gamma.

  • Yes, this works when the top layer is 255, like in your example, but it does not work when the top layer is dark, e.g. 0, like in my example. This suggests to me that GIMP is using a different equation.
    – henders64
    Feb 7, 2019 at 23:39
  • It sill works with a black top layer, see edited answer. Can you add a screenshot similar to mine in your question?
    – xenoid
    Feb 7, 2019 at 23:58
  • Also depends if Default/Legacy vs Gamma/Linear in Gimp 2.10.
    – xenoid
    Feb 8, 2019 at 0:08
  • I'm new to stack exchange. I'm not sure if I answer with comments or by adding to the original question. Also trying to figure out how to attach an image.
    – henders64
    Feb 8, 2019 at 4:24
  • When I change from Perceptual gamma to Linear light, the 66 changes to a 14. You're getting a 32. Interesting. I'll look for the Legacy and Normal buttons.
    – henders64
    Feb 8, 2019 at 4:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.