1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-25 16:33:02 +00:00

vf_ass: Optimize alpha multiply

The effect of alpha blending was calculated as
color = orig_color * alpha / 255
where alpha and color range from 0 to 255.
Change this to
color = (orig_color * alpha + 255) / 256
where the "/ 256" can be expressed as a shift whereas the compiler
would probably generate a multiply+shift for the original "/ 255".
This formula gives a result that is too high by 1 for some inputs.
However it gives the exact result if alpha is 0 or 255 which is
probably the case where small errors would matter most.
This commit is contained in:
Uoti Urpala 2008-07-23 01:47:30 +03:00
parent 2d4656e070
commit 4dab4347f5

View File

@ -296,10 +296,10 @@ static void my_draw_bitmap(struct vf_instance* vf, unsigned char* bitmap, int bi
dstv = vf->priv->planes[2] + dst_x + dst_y * vf->priv->outw;
for (i = 0; i < bitmap_h; ++i) {
for (j = 0; j < bitmap_w; ++j) {
unsigned k = ((unsigned)src[j]) * 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;
unsigned k = (src[j] * opacity + 255) >> 8;
dsty[j] = (k*y + (255-k)*dsty[j] + 255) >> 8;
dstu[j] = (k*u + (255-k)*dstu[j] + 255) >> 8;
dstv[j] = (k*v + (255-k)*dstv[j] + 255) >> 8;
}
src += stride;
dsty += dmpi->stride[0];