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

Nicolas George nicolas.george at normalesup.org
Thu Sep 16 18:54:59 CEST 2010


Le decadi 30 fructidor, an CCXVIII, Grigori Goronzy a écrit :
> Interesting, but do we need bit-exact results here? I think no.

Probably not. Especially since the original formula was quite wrong to start
with. I did some tests about rounding methods for "a×b/255". Here are the
results:

                                #
                                #                   (i * j + 128) / 255
                        #   #   #   #   #            0.00 +- 0.29
                       ### ## ##### ## ###
                       ###################
                       ###################
                       ###################
                      #####################
                      #####################
                      #####################
--+---------|---------+---------|---------+---------|---------+--
           -1                   0                   1


                #   #   #   #
                ## ### ### ##   #                   i * j / 255
             ######### ##########                   -0.48 +- 0.29
             ####################
             ####################
             ####################
            #####################
            #####################
            #####################
            #####################
--+---------|---------+---------|---------+---------|---------+--
           -1                   0                   1


                                #
                                #                   (i * j + 255) >> 8
                                #   #               +0.24 +- 0.36
                                ### ## ##
                               ########### ##
                              ################
                            #####################
                           #######################
                        ###########################
                   #################################
--+---------|---------+---------|---------+---------|---------+--
           -1                   0                   1


                                #
                                #                   (i * j + 192) >> 8
                            #   #                   +0.01 +- 0.36
                           ## ####  #               ! 255,255 -> 254
                           ########### ##
                         #################
                        #####################
                     # #######################
                   ###########################
            #   ###############################
--+---------|---------+---------|---------+---------|---------+--
           -1                   0                   1

The histograms shows the difference between the exact value of i×j/255 and
the rounded value using different methods, for all pairs in [0;255]². The
mean and standard deviation are written on the right.

Obviously, the second one is the worst. Unfortunately, this is the one
currently in use.

I think the third one, the fast one Grigori suggested, is perfectly
acceptable.

Statistically speaking, the fourth one, with 192 instead of 255, would be
better, but it has a flaw: 255×255/255 rounds to 254 (and the same goes for
any i×255/255 if i>192), which is not acceptable, IMHO, for the code of an
alpha blending.

Therefore, attached:

- New version of the division-avoiding patch, using the shift method.
  +17% speed (4.62s ±0.047)

- Updated version of the test-if-zero-alpha patch.
  +3% speed from above, +20% total (4.50s ±0.047)

- Version of the same with the reindent made.
  (If I apply these changes myself, I'll stick to the rules and apply the
  reindent separately.)

Regards,

-- 
  Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mplayer-vfassnodiv-20100916.diff
Type: text/x-diff
Size: 1050 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/attachments/20100916/0da4b9c2/attachment.diff>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mplayer-vfasstestzero-20100916.diff
Type: text/x-diff
Size: 771 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/attachments/20100916/0da4b9c2/attachment-0001.diff>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mplayer-vfasstestzeroreindented-20100916.diff
Type: text/x-diff
Size: 984 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/attachments/20100916/0da4b9c2/attachment-0002.diff>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/attachments/20100916/0da4b9c2/attachment.pgp>


More information about the MPlayer-dev-eng mailing list