07-16-2024, 07:42 PM
Going next level... how is opacity/transparency handled?
The usual Normal more is what is known as the over operator in computer graphics. The general formula or pixel A over pixel B is:
alphaOut = alphaA + alphaB * (1 - alphaA)
channelOut = ( channelA * alphaA + channelB * alphaB * (1 - alphaA) ) / alphaOut
In the frequent case where the bottom is fullly opaque (alphaB = 1), this simplifies to:
alphaOut = 1
channelOut = channelA * alphaA + channel B * (1 - alphaA)
Of course Gimp uses these formulas, but the question is, what are the actual input values... and the answer is, it depends
The great distinction is between Default and Legacy blend modes:
In Default mode:
The computations:
Augmented spreadsheet with three macros/functions (all inputs and outputs are assumed "linear"):
GammaAndCompositingSpreadsheet.zip (Size: 118.16 KB / Downloads: 154)
The usual Normal more is what is known as the over operator in computer graphics. The general formula or pixel A over pixel B is:
alphaOut = alphaA + alphaB * (1 - alphaA)
channelOut = ( channelA * alphaA + channelB * alphaB * (1 - alphaA) ) / alphaOut
In the frequent case where the bottom is fullly opaque (alphaB = 1), this simplifies to:
alphaOut = 1
channelOut = channelA * alphaA + channel B * (1 - alphaA)
Of course Gimp uses these formulas, but the question is, what are the actual input values... and the answer is, it depends
The great distinction is between Default and Legacy blend modes:
In Default mode:
- The alpha is the product of the opacity slider (50% opacity: 0.50) and the linear value of the mask. In other words, to achieve the same opacity as a 50% opacity slider, the mask should be set to 188 (#BC) to obtain a linear value of 50% (50.2% in practice).
- The channel inputs are the linear values (and of course the output is converted back to sRGB)
- The alpha is the product of the opacity slider (50% opacity: 0.50) and the linear value of the mask, like in standard mode. So a 50% opacity is still obtained with a mask value of 188 (#BC).
- The channel inputs are the sRGB values.
The computations:
The results in Default mode:
The results in Legacy mode (where the outcome is the average of the two layers)
Augmented spreadsheet with three macros/functions (all inputs and outputs are assumed "linear"):
GammaAndCompositingSpreadsheet.zip (Size: 118.16 KB / Downloads: 154)
- OverOpaqueChannel(topValue,topAlpha,bottomValue): computes the result of compositing a pixel over another fully opaque pixel
- OverAlpha(topAlpha,bottomAlpha): computes the resulting alpha of two pixels
- OverChannel(topValue,topAlpha,bottomValue,bottomAlpha): computes the resulting color of two pixels