Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6081873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:13:30+00:00 2026-05-23T11:13:30+00:00

I am trying to implement pre-multiplied alpha blending. On this page : What Is

  • 0

I am trying to implement pre-multiplied alpha blending. On this page : What Is Color Blending?, they do explain standard alpha blending but not for pre-multiplied values.

Alpha Blending : (source × Blend.SourceAlpha) + (destination × Blend.InvSourceAlpha)

According formula, it translates to this :

  a = ((srcA * srcA) >> 8) + ((tgtA * (255 - srcA)) >> 8);
  r = ((srcR * srcA) >> 8) + ((tgtR * (255 - srcA)) >> 8);
  g = ((srcG * srcA) >> 8) + ((tgtG * (255 - srcA)) >> 8);
  b = ((srcB * srcA) >> 8) + ((tgtB * (255 - srcA)) >> 8);
                         

It works, obviously …

Now how do I convert this to process pre-multiplied values ?

  a = ((srcA)) + ((tgtA * (255 - srcA)) >> 8);
  r = ((srcR)) + ((tgtR * (255 - srcA)) >> 8);
  g = ((srcG)) + ((tgtG * (255 - srcA)) >> 8);
  b = ((srcB)) + ((tgtB * (255 - srcA)) >> 8);
                          

Since it has been pre-multiplied, I discard the multiplication in the first term … right !?
But the result is between alpha blending and additive blending, tending more to additive. In the end it doesn’t really look too blended. It’s probably wrong since it should look exactly like classic alpha blending; or is this expected behavior ?

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T11:13:31+00:00Added an answer on May 23, 2026 at 11:13 am

    The reason pre-multiplying works is because it actually ends up squaring the alpha for the target before it adds the source image to the target

    eg. Without pre multiplying, we get this for the source image data:

    srcA = origA
    srcR = origR
    srcG = origG
    srcB = origB
    

    And we get this for the resulting image when applied to a target:

    a = ((srcA * srcA) >> 8) + ((tgtA * (255 - srcA)) >> 8)
    r = ((srcR * srcA) >> 8) + ((tgtR * (255 - srcA)) >> 8)
    g = ((srcG * srcA) >> 8) + ((tgtG * (255 - srcA)) >> 8)
    b = ((srcB * srcA) >> 8) + ((tgtB * (255 - srcA)) >> 8)
    

    Expanding this out we get:

    a = ((origA * origA) >> 8) + ((tgtA * (255 - origA)) >> 8)
    r = ((origR * origA) >> 8) + ((tgtR * (255 - origA)) >> 8)
    g = ((origG * origA) >> 8) + ((tgtG * (255 - origA)) >> 8)
    b = ((origB * origA) >> 8) + ((tgtB * (255 - origA)) >> 8)
    

    No surprises there…

    Now for the pre-multiplied source image data we get:

    srcA = (origA * origA) >> 8
    srcR = (origR * origA) >> 8
    srcG = (origG * origA) >> 8
    srcB = (origB * origA) >> 8
    

    Which, when applied to a target is:

    a = (srcA >> 8) + ((tgtA * (255 - srcA)) >> 8);
    r = (srcR >> 8) + ((tgtR * (255 - srcA)) >> 8);
    g = (srcG >> 8) + ((tgtG * (255 - srcA)) >> 8);
    b = (srcB >> 8) + ((tgtB * (255 - srcA)) >> 8);
    

    Ok, so we know this, but if we expand this out you will see the difference:

    a = (origA * origA) >> 8 + ((tgtA * (255 – ((origA * origA) >> 8))) >> 8);
    r = (origR * origA) >> 8 + ((tgtR * (255 - ((origA * origA) >> 8))) >> 8);
    g = (origG * origA) >> 8 + ((tgtG * (255 – ((origA * origA) >> 8))) >> 8);
    b = (origB * origA) >> 8 + ((tgtB * (255 – ((origA * origA) >> 8))) >> 8);
    

    Compare that to the NON Pre-Multiplied expansion of:

    a = ((origA * origA) >> 8) + ((tgtA * (255 - origA)) >> 8)
    r = ((origR * origA) >> 8) + ((tgtR * (255 - origA)) >> 8)
    g = ((origG * origA) >> 8) + ((tgtG * (255 - origA)) >> 8)
    b = ((origB * origA) >> 8) + ((tgtB * (255 - origA)) >> 8)
    

    And straight away you can see that we are squaring the origA value when applying it to the target, this means that more of the target will come through to the resulting color values.

    By squaring it you are saying, I want more of the target to come through.

    This is why when pre-multiplying it removes the amount of banding around transparent blocks, because those pixels with lower Alpha values get more of the target pixels than you would if you didn’t pre-multiply and this happens on an exponential scale.

    I hope this clears it up.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im trying to implement a custom error page, what i want to be able
I have been trying to implement the delete BST function but I don't know
I'm trying to implement a generic view that performs some pre-processing and redirects to
I am trying to implement a simple merge, without the use of anything pre-defined.
I am trying to implement a file upload to a pre-existing form that I
I'm trying to implement svnperms into a repository, but am having difficulty with a
I'm trying to implement a countdown timer into a pre-existing public class and I
I'm trying implement a custom login page to use in my JSF 2.0 application.
All I am currently trying implement something along the lines of dim l_stuff as
trying to implement a dialog-box style behaviour using a separate div section with all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.