If I have a bottom layer color and an alpha value (C&A) and want to create a custom C&A on the screen, what is the function to determine what C&A has to be added as a layer on top of the bottom layer?
edit:
I want to duplicate photoshop's "normal" mode so that I match a designer's graphic design.
For example:
BASE LAYER rgb: 255-0-0 alpha: 51/256
+
NEW LAYER rgb: ??? alpha: ???
=
DESIRED LAYER rgb: 114-0-141 alpha: 92/256
P.S.: the answer is 0-0-255 alpha: 51/256... but I only know this because I wrote the prob开发者_开发百科lem and verified it in photoshop.
This would depend on the Blend Mode used between the two layers (bottom and top). The wiki page lists some formulae that may be of interest to you.
The PDF Reference manual has a nice explanation too:
αrCr = [(1 - αs) * αb * Cb] + [(1 - αb) * αs * Cs] + αb * αs * B(Cb, Cs)
where
C = color, α = alpha value
and the subscripts
r = result, b = backdrop, s = source
Also,
B(Cb, Cs) = blend mode function
In case of Normal Blend Mode: B(Cb, Cs) = Cs
The blended alpha is given by:
αr = Union(αb, αs) and
Union(b, s) = b + s - (b * s )
I think that photoshop's "normal" mode implements Porter Duff "over" compositing. Then the wikipedia page is useful and lists the formulas, expecially for handling alpha.
Note that not all solutions are possible. I.e., the alpha of the desired layer must be larger than the alpha of the base layer.
The solution could go like this:
- determine alpha of new layer as
(alpha_desired - alpha_base) / (1 - alpha_base)
. Note that(alpha_desired - alpha_base)
must be positive. - determine color of new layer, which may be outside the available range -- then the operation is impossible.
精彩评论