Mercurial > mplayer.hg
changeset 32261:0dd2b27940b5
vf_ass: avoid divisions in alpha blending.
On a test case, it speeds up the blending by about 20%.
author | cigaes |
---|---|
date | Thu, 23 Sep 2010 17:08:10 +0000 |
parents | 56dadca4f36d |
children | f67e85fc1f7a |
files | libmpcodecs/vf_ass.c |
diffstat | 1 files changed, 7 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/libmpcodecs/vf_ass.c Wed Sep 22 21:11:31 2010 +0000 +++ b/libmpcodecs/vf_ass.c Thu Sep 23 17:08:10 2010 +0000 @@ -306,11 +306,13 @@ unsigned char y = rgba2y(color); unsigned char u = rgba2u(color); unsigned char v = rgba2v(color); - unsigned char opacity = 255 - _a(color); + unsigned opacity = 255 - _a(color); unsigned char *src, *dsty, *dstu, *dstv; int i, j; mp_image_t *dmpi = vf->dmpi; + opacity = (0x10203 * opacity + 0x80) >> 8; /* 0x10203 = (1<<32)/(255*255) */ + /* 0 <= opacity <= 0x10101 */ src = bitmap; dsty = dmpi->planes[0] + dst_x + dst_y * dmpi->stride[0]; dstu = vf->priv->planes[1] + dst_x + dst_y * vf->priv->outw; @@ -320,10 +322,10 @@ unsigned k = src[j]; if (!k) continue; - k = k * opacity / 255; - dsty[j] = (k * y + (255 - k) * dsty[j]) / 255; - dstu[j] = (k * u + (255 - k) * dstu[j]) / 255; - dstv[j] = (k * v + (255 - k) * dstv[j]) / 255; + k *= opacity; /* 0 <= k <= 0xFFFFFF */ + dsty[j] = (k * y + (0xFFFFFF - k) * dsty[j] + 0x800000) >> 24; + dstu[j] = (k * u + (0xFFFFFF - k) * dstu[j] + 0x800000) >> 24; + dstv[j] = (k * v + (0xFFFFFF - k) * dstv[j] + 0x800000) >> 24; } src += stride; dsty += dmpi->stride[0];