Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What is the gamma encoding and why are my color computations wrong?
#2
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 Big Grin 

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)
In Legacy mode(*):
  • 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.
Which gives:

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"):
.zip   GammaAndCompositingSpreadsheet.zip (Size: 118.16 KB / Downloads: 153)
  • 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
(*) For the curious, "Legacy" is a bit of a misnomer, because if Gimp indeed works on the raw sRGB data for the layer, it still converts the mask to a linear value. However, if you have the curiosity to save the file to 2.6 XCF and open it in 2.8, you expect something different since Gimp would use the direct mask values... but you get the very same visible result! But if you look closer, you find that the mask has been altered, and the 128 and 188 values in the example above have ben converted to 55 and 128, that are their linear values...
Reply


Messages In This Thread
RE: What is the gamma encoding and why are my color computations wrong? - by Ofnuts - 07-16-2024, 07:42 PM

Forum Jump: