[FFmpeg-cvslog] mss12: avoid unnecessary division in arith*_get_bit()

Alberto Delmás git at videolan.org
Fri Sep 7 13:50:45 CEST 2012


ffmpeg | branch: master | Alberto Delmás <adelmas at gmail.com> | Mon Sep  3 17:32:01 2012 +0200| [9699b3a2d7ebc62ae58c4e70997190f5f7b45d27] | committer: Kostya Shishkov

mss12: avoid unnecessary division in arith*_get_bit()

That division can be replaced with a comparison:
((c->value - c->low) << 1) + 1 >= range

By expanding 'range' definition and simplifying this inequation we obtain
the final expression.

Suggested by Michael Niedermayer <michaelni at gmx.at>

Signed-off-by: Kostya Shishkov <kostya.shishkov at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=9699b3a2d7ebc62ae58c4e70997190f5f7b45d27
---

 libavcodec/mss12.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/mss12.h b/libavcodec/mss12.h
index 678a0c0..f5d0366 100644
--- a/libavcodec/mss12.h
+++ b/libavcodec/mss12.h
@@ -103,7 +103,7 @@ av_cold int ff_mss12_decode_end(MSS12Context *ctx);
 static int arith ## VERSION ## _get_bit(ArithCoder *c)                  \
 {                                                                       \
     int range = c->high - c->low + 1;                                   \
-    int bit   = (((c->value - c->low) << 1) + 1) / range;               \
+    int bit   = 2 * c->value - c->low >= c->high;                       \
                                                                         \
     if (bit)                                                            \
         c->low += range >> 1;                                           \



More information about the ffmpeg-cvslog mailing list