[MPlayer-dev-eng] [PATCH] vf_ass: avoid a division

Reimar Döffinger Reimar.Doeffinger at gmx.de
Fri Sep 17 08:06:04 CEST 2010


On Thu, Sep 16, 2010 at 06:54:59PM +0200, Nicolas George wrote:
> diff --git a/libmpcodecs/vf_ass.c b/libmpcodecs/vf_ass.c
> index 3ff9218..6f0beff 100644
> --- a/libmpcodecs/vf_ass.c
> +++ b/libmpcodecs/vf_ass.c
> @@ -317,10 +317,10 @@ static void my_draw_bitmap(struct vf_instance *vf, unsigned char *bitmap,
>      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 = (((unsigned) 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;

Why aren't you using the method from the original patch anymore?
It would still remove one shift and one add and should reduce
the rounding errors that appear with above code for small k.


More information about the MPlayer-dev-eng mailing list