[MPlayer-dev-eng] Help with MMX asm code
Billy Biggs
vektor at dumbterm.net
Thu Oct 23 15:13:46 CEST 2003
Jason Tackaberry (tack at auc.ca):
> I want to overlay on top of mpi, and an alpha channel (alpha). The
> calculation looks like this:
>
> mpi_plane[pos] = ((255 - alpha[pos]) * mpi_plane[pos] +
> alpha[pos] * img_plane[pos]) >> 8;
This is actually wrong, since you're dividing by 256 when you should
be dividing by 255. The fast and accurate way to estimate division by
255 is to do this (from Jim Blinn's 'dirty pixels'):
static inline __attribute__ ((always_inline,const)) int multiply_alpha( int a, int r )
{
int temp;
temp = (r * a) + 0x80;
return ((temp + (temp >> 8)) >> 8);
}
There's another way to do this that's a little faster in MMX though.
I have a bunch of MMX'ed compositing routines if you like but you will
likely have to adapt them for your code. I usually go from like 4:4:4:4
onto 4:2:2 or from 4:4:4:4 onto 4:4:4:4. See speedy.[h,c] in CVS at
sourceforge.net/projects/tvtime/
-Billy
More information about the MPlayer-dev-eng
mailing list