Given color and alpha, what color and alpha should I add to create the color I want?

If I have a color for the bottom layer and an alpha value (C & A) and you want to create custom C & A on the screen, what is the function to determine what C & A needs to be added as a layer to the top of the bottom layer?

edit:

I want to duplicate the “regular” Photoshop mode to fit the graphic design of the designer.

For instance:

BASE LAYER rgb: 255-0-0 alpha: 51/256 + NEW LAYER rgb: ??? alpha: ??? = DESIRED LAYER rgb: 114-0-141 alpha: 92/256 

PS: answer 0-0-255 alpha: 51/256 ... but I only know this because I wrote the problem and checked it in Photoshop.

+4
source share
2 answers

This will depend on the Blend Mode used between the two layers (bottom and top). The wiki page lists some formulas that may interest you.

The PDF reference manual also has a nice explanation:

α r C r = [(1 - α s ) * α b * C b ] + [(1 - α b ) * α s * C s ] + α b * α s * B (C b, C s )

Where

  C = color, α = alpha value 

and indices

r = result, b = backdrop, s = source

Besides,

B (C b , C s ) = blend mode function

In the case of the normal blending mode: B (C b , C s ) = C s

Mixed alpha is given as follows:

α r = Union (α b , α s ) and

Union (b, s) = b + s - (b * s)

+2
source

I think that the “normal” Photoshop mode implements the composition “Porter Duff”. Then wikipedia is useful and lists the formulas, especially for alpha processing.

Please note that not all solutions are possible. I. The alpha of the desired layer should be larger than the alpha of the base layer.

The solution may look like this:

  • define the alpha of the new layer as (alpha_desired - alpha_base) / (1 - alpha_base) . Note: (alpha_desired - alpha_base) must be positive.
  • determine the color of a new layer, which may be outside the available range - then the operation is impossible.
0
source

All Articles