PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Speeding up by Alpha-premultiplying RGB?

Hello Johan,

Based on my experience with GapiDraw 3.6 and AlphaBlt() and AlphaBltFast(), the RGB value expected is in its full value with not Alpha-premultiplied RGB.

However, one very popular optimization technique is premultiplying RGB by its Alpha value and thus reducing one multiplication per each pixel during rendering semi-transparent pixels. Let me explain:

Rendering sprites with non Alpha-premultipied RGB(this is used by AlphaBlt() and AlphaBltFast()):

FinalRGB = RGB * Alpha + (1 - Alpha)*Background;


If we use Alpha-premultiplied RGB (.PNG files support this), the final semi-transparent pixels could be rendered as follows:

FinalRGB = RGB + (1-Alpha)*Background;


As far as I know, all 3D and 2D graphics packages support generating Alpha-premultiplied RGB(that is ready for compositing). Therefore, is there any chance, that in the following release of GapiDraw Alpha-premultiplied RGB would be supported by AlphaBlt() and AlphaBltFast()? This could be easily accomplished by adding a flag to every function, that woud specify whether Alpha-premultiplied RGB is used.

It would not really be a lot of work, and would significantly speed up alpha computations - a great optimization technique.

With regards,
Rene.
Hello,

Thanks for the tip! I will look into to see if we can integrate this in some nice way for the next release.

Cheers
Johan
Yeah,

I assume, this could speed up alpha blitting by 30% maybe, and thats not bad at all. All it requires is not to multiply RGB by Alpha value on render time, because alpha premultiplied RGB is already delivered in imported image.

To see that this is a standard and frequently used approach, Google proves that:

http://www.google.com/search?hl=en&lr=& ... iplication

With regards,
Rene.
InexorableTash · 04 Jan 2011, 02:22 UTC
I've been away from GapiDraw for a few years; I just updated my hobby project from 3.7 to 4.2, which went smoothly (unfortunately my architecture propagated the Create*Surfaces calls down the hierarchy so I needed to change many signatures). But back on topic:

Did anything ever become of this request? I have some textures with premultiplied alpha baked in and have been living with the black fringes; I don't see anything in the .H files that would indicate that this went in.

(You can see the effect in http://www.youtube.com/watch?v=Yjmn7WTLZPY at around 3:45 - obviously, this is only a hobby project and would never be released.)
Hello there,

No, this feature never made it to GapiDraw.

Sincerely
Johan