[FFmpeg-devel] [PATCH 3/3] avcodec/wmalosslessdec: cleanup

zhaoxiu.zeng zhaoxiu.zeng at gmail.com
Fri Feb 13 17:53:12 CET 2015


>From 4096d5565e55bdbc3dbe3b0aa3be920f73c00aa8 Mon Sep 17 00:00:00 2001
From: Zeng Zhaoxiu <zhaoxiu.zeng at gmail.com>
Date: Sat, 14 Feb 2015 00:27:03 +0800
Subject: [PATCH 3/3] avcodec/wmalosslessdec: cleanup

Signed-off-by: Zeng Zhaoxiu <zhaoxiu.zeng at gmail.com>
---
 libavcodec/wmalosslessdec.c | 24 ++++++++----------------
 1 file changed, 8 insertions(+), 16 deletions(-)

diff --git a/libavcodec/wmalosslessdec.c b/libavcodec/wmalosslessdec.c
index 1916594..bce0d6a 100644
--- a/libavcodec/wmalosslessdec.c
+++ b/libavcodec/wmalosslessdec.c
@@ -553,10 +553,7 @@ static int decode_channel_residues(WmallDecodeCtx *s, int ch, int tile_size)
         s->ave_sum[ch] = residue + s->ave_sum[ch] -
                          (s->ave_sum[ch] >> s->movave_scaling);
 
-        if (residue & 1)
-            residue = -(residue >> 1) - 1;
-        else
-            residue = residue >> 1;
+        residue = (residue >> 1) ^ -(residue & 1);
         s->channel_residues[ch][i] = residue;
     }
 
@@ -644,14 +641,10 @@ static void mclms_update(WmallDecodeCtx *s, int icoef, int *pred)
         }
     }
 
-    for (ich = num_channels - 1; ich >= 0; ich--) {
+    for (ich = num_channels; ich-- > 0; ) {
         s->mclms_recent--;
-        s->mclms_prevvalues[s->mclms_recent] = s->channel_residues[ich][icoef];
-        if (s->channel_residues[ich][icoef] > range - 1)
-            s->mclms_prevvalues[s->mclms_recent] = range - 1;
-        else if (s->channel_residues[ich][icoef] < -range)
-            s->mclms_prevvalues[s->mclms_recent] = -range;
-
+        s->mclms_prevvalues[s->mclms_recent] = av_clip(s->channel_residues[ich][icoef],
+            -range, range - 1);
         s->mclms_updates[s->mclms_recent] = WMASIGN(s->channel_residues[ich][icoef]);
     }
 
@@ -726,7 +719,7 @@ static void lms_update(WmallDecodeCtx *s, int ich, int ilms, int input)
 static void use_high_update_speed(WmallDecodeCtx *s, int ich)
 {
     int ilms, recent, icoef;
-    for (ilms = s->cdlms_ttl[ich] - 1; ilms >= 0; ilms--) {
+    for (ilms = s->cdlms_ttl[ich]; ilms-- > 0; ) {
         recent = s->cdlms[ich][ilms].recent;
         if (s->update_speed[ich] == 16)
             continue;
@@ -744,7 +737,7 @@ static void use_high_update_speed(WmallDecodeCtx *s, int ich)
 static void use_normal_update_speed(WmallDecodeCtx *s, int ich)
 {
     int ilms, recent, icoef;
-    for (ilms = s->cdlms_ttl[ich] - 1; ilms >= 0; ilms--) {
+    for (ilms = s->cdlms_ttl[ich]; ilms-- > 0; ) {
         recent = s->cdlms[ich][ilms].recent;
         if (s->update_speed[ich] == 8)
             continue;
@@ -764,7 +757,7 @@ static void revert_cdlms(WmallDecodeCtx *s, int ch,
     int icoef, pred, ilms, num_lms, residue, input;
 
     num_lms = s->cdlms_ttl[ch];
-    for (ilms = num_lms - 1; ilms >= 0; ilms--) {
+    for (ilms = num_lms; ilms-- > 0; ) {
         for (icoef = coef_begin; icoef < coef_end; icoef++) {
             pred = 1 << (s->cdlms[ch][ilms].scaling - 1);
             residue = s->channel_residues[ch][icoef];
@@ -1073,8 +1066,7 @@ static int decode_frame(WmallDecodeCtx *s)
 
     av_dlog(s->avctx, "Frame done\n");
 
-    if (s->skip_frame)
-        s->skip_frame = 0;
+    s->skip_frame = 0;
 
     if (s->len_prefix) {
         if (len != (get_bits_count(gb) - s->frame_offset) + 2) {
-- 
2.1.0



More information about the ffmpeg-devel mailing list