[cairo] LCD Alpha Blending Formulas [Repost from AGG]

Petr Kobalíček kobalicek.petr at gmail.com
Mon Feb 7 04:30:46 PST 2011


Hi devs,

[Repost from the AGG mailing list]

this post is not strictly related to agg. I'm playing with one problem
related to image compositing and I only need to confirm whether my
solution is correct.

I abstracted image compositing into following two functions:

 CompositeC(Dca, Da, Sca, Sa) - Function that produces color component
(premultiplied).
 CompositeA(Dca, Da, Sca, Sa) - Function that produces alpha component.

Where:

 Dca = destination color * destination alpha (RGB*A)
 Da = destination alpha (A)
 Sca = source color * source alpha (RGB*A)
 Sa = source alpha (A)

Can be written as (svg):

 Dca' = CompositeC(Dca, Da, Sca, Sa)
 Da'  = CompositeA(Dca, Da, Sca, Sa)

Where:

 Dca' - new destination color component value
 Da' - new destination alpha value

Now when mask (Ma) is used the formula can be simply extended to (LERP):

 Dca' = CompositeC(Dca, Da, Sca, Sa).Ma + Dca.(1 - Ma)
 Da'  = CompositeA(Dca, Da, Sca, Sa).Ma + Dca.(1 - Ma)

My problem is with ARGB mask, usually used for LCD-subpixel alpha blending.

So my question is, can I use the following formula?:

 Dca' = CompositeC(Dca, Da, Sca, Sa).Mc + Dca.(1 - Mc)
 Da'  = CompositeA(Dca, Da, Sca, Sa).Ma + Dca.(1 - Ma)

Where:

 Ma - Alpha component from the ARGB mask, this should be equal to max(R, G, B).
 Mc - Color component from the ARGB mask (individual component for R, G, B).

It seems that cairo graphics library is using this formula, but skia not.

BTW 1: Here is link to skia code, I don't understand why they used
saturated addition:

  http://code.google.com/p/skia/source/browse/trunk/src/core/SkBlitter_ARGB32_Subpixel.cpp

Thanks for ideas
Petr


More information about the cairo mailing list