summaryrefslogtreecommitdiffstats
path: root/libmpcodecs
diff options
context:
space:
mode:
authorUoti Urpala <uau@symbol.nonexistent.invalid>2008-07-23 01:47:30 +0300
committerUoti Urpala <uau@symbol.nonexistent.invalid>2008-07-23 02:05:55 +0300
commit4dab4347f5d7bb3642a2c5918fc29855f8f62482 (patch)
tree4f1f572dcd5cfee177658d28de3e1c3ce015dd65 /libmpcodecs
parent2d4656e070697cebe8cb66568b3e8dd8919b5eed (diff)
downloadmpv-4dab4347f5d7bb3642a2c5918fc29855f8f62482.tar.bz2
mpv-4dab4347f5d7bb3642a2c5918fc29855f8f62482.tar.xz
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.
Diffstat (limited to 'libmpcodecs')
-rw-r--r--libmpcodecs/vf_ass.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/libmpcodecs/vf_ass.c b/libmpcodecs/vf_ass.c
index 2f7a188246..bbe3bea371 100644
--- a/libmpcodecs/vf_ass.c
+++ b/libmpcodecs/vf_ass.c
@@ -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];