Evan Martin (evan) wrote in evan_tech,
Evan Martin

premultiplied alpha

I've seen the term "premultiplied alpha" thrown around a lot -- basically, deciding whether the R,G,B components have been multiplied by alpha or not -- but a nice post by Bill Spitzak really made everything clear:
If you were not premultiplying, compositing color C over B with alpha a would be done with "Ca+B(1-a)".

In premultiplied images, the C pixel is replaced with A = Ca and the math is changed to "A+B(1-a)". Substituting Ca for A will show that this is identical.

So mathematically there is no difference.

Advantages of premultiplied:

1. This is what almost all rendering and painting programs produce. Correctly producing a non-premultiplied image would require tracking a "coverage" for each pixel that is seperate from the "transparency". Premultiplied allows you to combine these values very early.

2. Premultiplied images look correct when the rgb channels are viewed. Non-premultiplied images will have noisy and bright pixels at any antialiased edges.

3. Premultipled images are more convienent for other operations such as adding to simulate a double exposure.

4. Premultiplied images allow "glow" where the color is greater than the alpha.

5. Premultiplied over is available on Windows.

Advantages of non-premultiplied:

1. Supposedly this is what .png files are supposed to be, but everybody appears to be ignoring that.

2. The compositied result is always in the range 0-1, with no clamping needed.

3. An 8-bit image can antialias any 8-bit color accurately. A premultiplied image with 1/4 alpha, if added 4 times to get an opaque image, will only have 64 possible colors in 8 bits. This advantage is negated, however, because most implementations do not preserve intermediate results of more than 8 bits, thus the non-premultiplied version produces the same result.

I believe Cairo can do non-premultiplied, by setting the source pattern and the mask to the same image, then doing a copy operation. So you actually have both anyway.
Tags: graphics

  • münchen

    On that note: I'm living in Munich for the next week plus a few days. Do I know anyone around here? (PS: The LJ → PubSubHubbub → Reader…

  • deb/rpm diffing tools

    Dear Linux hackers, Chrome tends to push minor updates (often security) pretty frequently. We'd like to operate as a good member of the Linux…

  • emacs

    I've been using vim for a very long time -- over ten years -- but over those years I've envied more and more the way emacs integrates other software.…

  • Post a new comment


    default userpic
    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 1 comment