[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Pre-multiplied alpha



If you are just talking about alpha blending, you can blend raw color
values at exactly the same speed as pre-multiplied color values, when
you do a little trick where you blend by the difference between source
and dest ((dest - src)*alpha + dest for no pre-mult vs. dest*(1-alpha)
+ src with pre-mult), so there is no speed up at all for
pre-multiplied for the most common cases

Pre-multiplied only really helps on the performance front a little bit
with additive blending (you can save a multiply per pixel per
channel), or a whole lot when doing accurate color interpolation (like
bilinear filtering or gaussian blur where you end up saving a divide
per pixel channel)


... on a slightly related note, many bilinear filter implementations
don't do interpolation correctly (they interpolate color without
considering alpha), probably cause it's fast not to do it right - but
using pre-multiplied alpha color values works correctly in those cases


On 8/3/07, René Dudfield <renesd@xxxxxxxxx> wrote:
> Hi,
>
> on a slightly related note, a pre-multiplied alpha blitter would be a
> great a great speed up.
>
>
> On 8/4/07, Will McGugan <will@xxxxxxxxxxxxxxx> wrote:
> > Hi,
> >
> > Is there any way to pre-multiply a surface with its alpha channel? I
> > guess I could to it with surfarray, but I was wondering if there was
> > another way.
> >
> > Regards,
> >
> > Will McGugan
> >
>