Professional Web Applications Themes

Alpha blending - Mac Programming

This bit me last night; don't let it bite you. When preparing images for compositing, pre-multiply r, g, and b with alpha. There are two means of blending commonly used on the Mac, interpolated and pre-multiplied. (Well, there's also a third, but it isn't used much.) With interpolated blending, a source color (c_s) painted over a colored destination (c_d) with source alpha (a_s) gives a final color (c_f): c_f = a_s * c_s + (1 - a_s) * c_d In premultiplied blending, it's c_f = c_s + (1 - a_s) * c_d Which means that c_s must be premultiplied with ...

  1. #1

    Default Alpha blending

    This bit me last night; don't let it bite you.

    When preparing images for compositing, pre-multiply r, g, and b with alpha.

    There are two means of blending commonly used on the Mac, interpolated
    and pre-multiplied. (Well, there's also a third, but it isn't used much.)

    With interpolated blending, a source color (c_s) painted over a colored
    destination (c_d) with source alpha (a_s) gives a final color (c_f):

    c_f = a_s * c_s + (1 - a_s) * c_d

    In premultiplied blending, it's

    c_f = c_s + (1 - a_s) * c_d

    Which means that c_s must be premultiplied with c_a beforehand
    relative to the c_s in the interpolated case.

    It's obvious why Apple chose this, because making c_s bigger than
    that lets you put specular highlights on glass. But, like many things
    that are obvious, it isn't necessarily obvious when you're working on
    something else.
    Eric Pepke Guest

  2. #2

    Default Re: Alpha blending

    In <ef37f531.0309041713.10abdd41posting.google.com > Eric Pepke wrote:
    > This bit me last night; don't let it bite you.
    >
    > When preparing images for compositing, pre-multiply r, g, and b with
    > alpha.
    >
    > There are two means of blending commonly used on the Mac, interpolated
    > and pre-multiplied. (Well, there's also a third, but it isn't used
    > much.)
    >
    > With interpolated blending, a source color (c_s) painted over a
    > colored destination (c_d) with source alpha (a_s) gives a final color (
    > c_f):
    >
    > c_f = a_s * c_s + (1 - a_s) * c_d
    >
    > In premultiplied blending, it's
    >
    > c_f = c_s + (1 - a_s) * c_d
    >
    > Which means that c_s must be premultiplied with c_a beforehand
    > relative to the c_s in the interpolated case.
    >
    > It's obvious why Apple chose this, because making c_s bigger than
    > that lets you put specular highlights on glass. But, like many things
    > that are obvious, it isn't necessarily obvious when you're working on
    > something else.
    Is this related to the stuff in the docs that says stuff like "Cocoa and
    Quartz expect bitmaps with alpha to have the color values premultiplied"?
    m.

    --
    matt neuburg, phd = [email]matttidbits.com[/email], [url]http://www.tidbits.com/matt[/url]
    REALbasic: The Definitive Guide! 2nd edition!
    [url]http://www.amazon.com/exec/obidos/ASIN/0596001770/somethingsbymatt[/url]
    Subscribe to TidBITS. It's free and smart.
    matt neuburg Guest

  3. #3

    Default Re: Alpha blending

    matt neuburg <matttidbits.com> wrote in message news:<20030905074827438-0700news.la.sbcglobal.net>...
    > Is this related to the stuff in the docs that says stuff like "Cocoa and
    > Quartz expect bitmaps with alpha to have the color values premultiplied"?
    > m.
    Yes. But the only reference I've seen is in [NSBitmapImageRep
    getBitmapDataPlanes], which I only found afterward.
    Eric Pepke Guest

  4. #4

    Default Re: Alpha blending

    in article google.com, Eric Pepke at
    org wrote on 05/09/2003 04:13:
     

    Please clarify, how exactly? And what exactly do you mean
    by "specular highlights", white?

    Why can't you do the same with the first method (interpolated
    blending), e.g. like this:

    a_s = 1 (fully opaque)
    c_s = 1 (white)
    c_f = a_s * c_s + (1 - a_s) * c_d = 1 * 1 + (1 - 1) * c_d = 1 (white)

    Mike

    --
    Mike Kluev
    PS. Remove "-DELETE-." part of my address to reply

    Mike Guest

  5. #5

    Default Re: Alpha blending

    Mike Kluev <-DELETE-.org> writes:
     
    >
    > Please clarify, how exactly? And what exactly do you mean
    > by "specular highlights", white?
    >
    > Why can't you do the same with the first method (interpolated
    > blending), e.g. like this:
    >
    > a_s = 1 (fully opaque)
    > c_s = 1 (white)
    > c_f = a_s * c_s + (1 - a_s) * c_d = 1 * 1 + (1 - 1) * c_d = 1 (white)[/ref]

    The difference is that a real highlight isn't opaque. Imagine looking
    through a window from a dark room. Does the view get darker when you
    turn the lights on? It doesn't, because there's no way the light
    hitting the front of the glass can attenuate the light coming through
    it. It just adds.

    Another example is a flame: it adds light without really obscuring
    what's behind it. That's why flames don't cast shadows.

    --
    -Stephen H. Westin
    Any information or opinions in this message are mine: they do not
    represent the position of Cornell University or any of its sponsors.
    Stephen Guest

  6. #6

    Default Re: Alpha blending

    in article cornell.edu, Stephen H. Westin at
    westin*cornell.edu wrote on 29/10/2003 20:06:
     
    >>
    >> Please clarify, how exactly? And what exactly do you mean
    >> by "specular highlights", white?
    >>
    >> Why can't you do the same with the first method (interpolated
    >> blending), e.g. like this:
    >>
    >> a_s = 1 (fully opaque)
    >> c_s = 1 (white)
    >> c_f = a_s * c_s + (1 - a_s) * c_d = 1 * 1 + (1 - 1) * c_d = 1 (white)[/ref]
    >
    > The difference is that a real highlight isn't opaque. Imagine looking
    > through a window from a dark room. Does the view get darker when you
    > turn the lights on? It doesn't, because there's no way the light
    > hitting the front of the glass can attenuate the light coming through
    > it. It just adds.
    >
    > Another example is a flame: it adds light without really obscuring
    > what's behind it. That's why flames don't cast shadows.[/ref]

    Let's see. Let a_s be 0.5 (half transparent) and c_s be 1 (white).

    c_f = 0.5 * 1 + 0.5 * c_d = (1 + c_d)/2 >= c_d
    (because 0 <= c_d <= 1)

    So, source image is not fully opaque and result is not getting
    darker than it was. Am I missing something? Give some concrete
    example (numeric values of c_s, a_s, c_d) that shows advantage
    of premultiplying (i.e. what is the destination color c_d and
    what result do we want to get c_f).

    --
    Mike Kluev
    PS. Remove "-DELETE-." part of my address to reply

    Mike Guest

  7. #7

    Default Re: Alpha blending

    Mike Kluev <-DELETE-.org> wrote in message news:<BBC6C0CD.7891%-DELETE-.org>... 

    (shrug) The cardinal rule in graphics is, if it looks good, do it.
    Try it if you like. The highlights just don't look as good; they
    look more like a smear than a highlight. I've probably tried
    every conceivable alpha combination going back to the SGI days:
    some look good, and some don't.
    Eric Guest

  8. #8

    Default Re: Alpha blending

    In Article google.com, Eric Pepke wrote:
     
    >
    > (shrug) The cardinal rule in graphics is, if it looks good, do it.
    > Try it if you like. The highlights just don't look as good; they
    > look more like a smear than a highlight. I've probably tried
    > every conceivable alpha combination going back to the SGI days:
    > some look good, and some don't.[/ref]

    Not sure how to try. The icon of "Preview" app has some descent
    (for me anyway) highlight on glass. This icon is almost fully
    opaque where this highlight is (checked with Icon Browser), so
    the "traditional" (interpolated) blending should work:

    c_f = a_s * c_s + (1 - a_s) * c_d = 1 * 1 + (1 - 1) * c_d = 1

    If someone knows the answer to the below, please post it here:
     [/ref]

    --
    Mike Kluev

    PS. Remove "-DELETE-." part of my e-mail address to reply.

    Mike Guest

Similar Threads

  1. ADDITIVE BLENDING
    By DANGH_b in forum Macromedia Director 3D
    Replies: 4
    Last Post: March 7th, 01:31 PM
  2. blending on meshes
    By HomeBrewer in forum Macromedia Director 3D
    Replies: 2
    Last Post: July 27th, 02:55 PM
  3. blending between 2 textures
    By michael voeller in forum Macromedia Director 3D
    Replies: 3
    Last Post: June 8th, 04:00 AM
  4. Blending 2 exposures
    By dan brady in forum Adobe Photoshop 7, CS, CS2 & CS3
    Replies: 1
    Last Post: August 22nd, 09:28 PM
  5. blending? Fading?
    By Thundercat webforumsuser@macromedia.com in forum Macromedia Freehand
    Replies: 1
    Last Post: July 15th, 11:09 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139