>From a9bd336e769dee9150ae461ff0c662c7e36119d7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Alberto=20Delm=C3=A1s?= <[email protected]>
Date: Mon, 3 Sep 2012 17:32:01 +0200
Subject: [PATCH 2/2] mss12 and mss2: Avoid unnecessary division and loop

Suggested by Michael Niedermayer <[email protected]>
---
 libavcodec/mss12.h |    2 +-
 libavcodec/mss2.c  |    3 +--
 2 files changed, 2 insertions(+), 3 deletions(-)

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;                                           \
diff --git a/libavcodec/mss2.c b/libavcodec/mss2.c
index 9914562..fbdc72c 100644
--- a/libavcodec/mss2.c
+++ b/libavcodec/mss2.c
@@ -335,8 +335,7 @@ static int decode_rle(GetBitContext *gb, uint8_t *pal_dst, 
int pal_stride,
                     else
                         repeat = get_bits(gb, b);
 
-                    while (b--)
-                        repeat += 1 << b;
+                    repeat += (1 << b) - 1;
 
                     if (last_symbol == -2) {
                         int skip = FFMIN(repeat, pal_dst + w - pp);
-- 
1.7.5.1

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to