[FFmpeg-cvslog] avcodec/wmv2: simplify cbp_table_index calculation

zhaoxiu.zeng git at videolan.org
Fri Feb 13 15:55:43 CET 2015


ffmpeg | branch: master | zhaoxiu.zeng <zhaoxiu.zeng at gmail.com> | Fri Feb 13 00:05:36 2015 +0800| [e4ea84e12e3ae2a2479615c363cbec93b6d57f7e] | committer: Michael Niedermayer

avcodec/wmv2: simplify cbp_table_index calculation

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

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

 libavcodec/wmv2.h    |   11 +++++++++++
 libavcodec/wmv2dec.c |   11 +----------
 libavcodec/wmv2enc.c |   11 +----------
 3 files changed, 13 insertions(+), 20 deletions(-)

diff --git a/libavcodec/wmv2.h b/libavcodec/wmv2.h
index cb5b14e..4fa5e9b 100644
--- a/libavcodec/wmv2.h
+++ b/libavcodec/wmv2.h
@@ -56,4 +56,15 @@ typedef struct Wmv2Context {
 
 void ff_wmv2_common_init(Wmv2Context *w);
 
+static av_always_inline int wmv2_get_cbp_table_index(MpegEncContext *s, int cbp_index)
+{
+    static const uint8_t map[3][3] = {
+        { 0, 2, 1 },
+        { 1, 0, 2 },
+        { 2, 1, 0 },
+    };
+
+    return map[(s->qscale > 10) + (s->qscale > 20)][cbp_index];
+}
+
 #endif /* AVCODEC_WMV2_H */
diff --git a/libavcodec/wmv2dec.c b/libavcodec/wmv2dec.c
index d9cbfd1..b1bcd09 100644
--- a/libavcodec/wmv2dec.c
+++ b/libavcodec/wmv2dec.c
@@ -173,16 +173,7 @@ int ff_wmv2_decode_secondary_picture_header(MpegEncContext *s)
 
         parse_mb_skip(w);
         cbp_index = decode012(&s->gb);
-        if (s->qscale <= 10) {
-            int map[3]         = { 0, 2, 1 };
-            w->cbp_table_index = map[cbp_index];
-        } else if (s->qscale <= 20) {
-            int map[3]         = { 1, 0, 2 };
-            w->cbp_table_index = map[cbp_index];
-        } else {
-            int map[3]         = {2,1,0};
-            w->cbp_table_index = map[cbp_index];
-        }
+        w->cbp_table_index = wmv2_get_cbp_table_index(s, cbp_index);
 
         if (w->mspel_bit)
             s->mspel = get_bits1(&s->gb);
diff --git a/libavcodec/wmv2enc.c b/libavcodec/wmv2enc.c
index 62e99c0..55ee089 100644
--- a/libavcodec/wmv2enc.c
+++ b/libavcodec/wmv2enc.c
@@ -111,16 +111,7 @@ int ff_wmv2_encode_picture_header(MpegEncContext *s, int picture_number)
         put_bits(&s->pb, 2, SKIP_TYPE_NONE);
 
         ff_msmpeg4_code012(&s->pb, cbp_index = 0);
-        if (s->qscale <= 10) {
-            int map[3]         = { 0, 2, 1 };
-            w->cbp_table_index = map[cbp_index];
-        } else if (s->qscale <= 20) {
-            int map[3]         = { 1, 0, 2 };
-            w->cbp_table_index = map[cbp_index];
-        } else {
-            int map[3]         = { 2, 1, 0 };
-            w->cbp_table_index = map[cbp_index];
-        }
+        w->cbp_table_index = wmv2_get_cbp_table_index(s, cbp_index);
 
         if (w->mspel_bit)
             put_bits(&s->pb, 1, s->mspel);



More information about the ffmpeg-cvslog mailing list