From 7cc14e598ec2386e4175612bf63c7a250b67672c Mon Sep 17 00:00:00 2001
From: Dmitry Kovalev <dkovalev@google.com>
Date: Mon, 25 Mar 2013 14:24:26 -0700
Subject: [PATCH] Code cleanup.

Lower case variable names, code simplification by using already defined
clamp and read_le16 functions.

Change-Id: I8fd544365bd8d1daed86d7b2ae0843e4ef80df08
---
 vp9/common/vp9_loopfilter.c   | 24 ++++++--------
 vp9/common/vp9_quant_common.c | 59 ++++++-----------------------------
 vp9/common/vp9_quant_common.h | 15 +++++----
 vp9/decoder/vp9_decodframe.c  |  2 +-
 4 files changed, 27 insertions(+), 73 deletions(-)

diff --git a/vp9/common/vp9_loopfilter.c b/vp9/common/vp9_loopfilter.c
index 9ce5a6378e..5c846129a3 100644
--- a/vp9/common/vp9_loopfilter.c
+++ b/vp9/common/vp9_loopfilter.c
@@ -129,7 +129,7 @@ void vp9_loop_filter_frame_init(VP9_COMMON *cm,
         lvl_seg = vp9_get_segdata(xd, seg, SEG_LVL_ALT_LF);
       } else { /* Delta Value */
         lvl_seg += vp9_get_segdata(xd, seg, SEG_LVL_ALT_LF);
-        lvl_seg = (lvl_seg > 0) ? ((lvl_seg > 63) ? 63 : lvl_seg) : 0;
+        lvl_seg = clamp(lvl_seg, 0, 63);
       }
     }
 
@@ -152,13 +152,12 @@ void vp9_loop_filter_frame_init(VP9_COMMON *cm,
     /* Apply delta for Intra modes */
     mode = 0; /* B_PRED */
     /* Only the split mode BPRED has a further special case */
-    lvl_mode = lvl_ref +  xd->mode_lf_deltas[mode];
-    lvl_mode = (lvl_mode > 0) ? (lvl_mode > 63 ? 63 : lvl_mode) : 0; /* clamp */
+    lvl_mode = clamp(lvl_ref +  xd->mode_lf_deltas[mode], 0, 63);
 
     lfi->lvl[seg][ref][mode] = lvl_mode;
 
     mode = 1; /* all the rest of Intra modes */
-    lvl_mode = (lvl_ref > 0) ? (lvl_ref > 63 ? 63 : lvl_ref)  : 0; /* clamp */
+    lvl_mode = clamp(lvl_ref, 0, 63);
     lfi->lvl[seg][ref][mode] = lvl_mode;
 
     /* LAST, GOLDEN, ALT */
@@ -170,9 +169,7 @@ void vp9_loop_filter_frame_init(VP9_COMMON *cm,
 
       /* Apply delta for Inter modes */
       for (mode = 1; mode < 4; mode++) {
-        lvl_mode = lvl_ref + xd->mode_lf_deltas[mode];
-        lvl_mode = (lvl_mode > 0) ? (lvl_mode > 63 ? 63 : lvl_mode) : 0; /* clamp */
-
+        lvl_mode = clamp(lvl_ref + xd->mode_lf_deltas[mode], 0, 63);
         lfi->lvl[seg][ref][mode] = lvl_mode;
       }
     }
@@ -379,16 +376,13 @@ void vp9_loop_filter_partial_frame(VP9_COMMON *cm, MACROBLOCKD *xd,
    */
   if (alt_flt_enabled) {
     for (i = 0; i < MAX_MB_SEGMENTS; i++) {
-      /* Abs value */
       if (xd->mb_segment_abs_delta == SEGMENT_ABSDATA) {
+        // Abs value
         lvl_seg[i] = vp9_get_segdata(xd, i, SEG_LVL_ALT_LF);
-      }
-      /* Delta Value */
-      else {
-        lvl_seg[i] = default_filt_lvl +
-                     vp9_get_segdata(xd, i, SEG_LVL_ALT_LF);
-        lvl_seg[i] = (lvl_seg[i] > 0) ?
-                     ((lvl_seg[i] > 63) ? 63 : lvl_seg[i]) : 0;
+      } else {
+        // Delta Value
+        lvl_seg[i] = default_filt_lvl + vp9_get_segdata(xd, i, SEG_LVL_ALT_LF);
+        lvl_seg[i] = clamp(lvl_seg[i], 0, 63);
       }
     }
   }
diff --git a/vp9/common/vp9_quant_common.c b/vp9/common/vp9_quant_common.c
index 90eb88ed30..a94c772bea 100644
--- a/vp9/common/vp9_quant_common.c
+++ b/vp9/common/vp9_quant_common.c
@@ -8,7 +8,7 @@
  *  be found in the AUTHORS file in the root of the source tree.
  */
 
-
+#include "vp9/common/vp9_common.h"
 #include "vp9/common/vp9_quant_common.h"
 
 static int dc_qlookup[QINDEX_RANGE];
@@ -24,7 +24,7 @@ void vp9_init_quant_tables() {
 
   for (i = 0; i < QINDEX_RANGE; i++) {
     ac_qlookup[i] = current_val;
-    current_val = (int)((double)current_val * 1.02);
+    current_val = (int)(current_val * 1.02);
     if (current_val == last_val)
       current_val++;
     last_val = current_val;
@@ -38,57 +38,18 @@ void vp9_init_quant_tables() {
   }
 }
 
-int vp9_dc_quant(int QIndex, int Delta) {
-  int retval;
-
-  QIndex = QIndex + Delta;
-
-  if (QIndex > MAXQ)
-    QIndex = MAXQ;
-  else if (QIndex < 0)
-    QIndex = 0;
-
-  retval = dc_qlookup[ QIndex ];
-  return retval;
+int vp9_dc_quant(int qindex, int delta) {
+  return dc_qlookup[clamp(qindex + delta, 0, MAXQ)];
 }
 
-int vp9_dc_uv_quant(int QIndex, int Delta) {
-  int retval;
-
-  QIndex = QIndex + Delta;
-
-  if (QIndex > MAXQ)
-    QIndex = MAXQ;
-  else if (QIndex < 0)
-    QIndex = 0;
-
-  retval = dc_qlookup[ QIndex ];
-
-  return retval;
+int vp9_dc_uv_quant(int qindex, int delta) {
+  return dc_qlookup[clamp(qindex + delta, 0, MAXQ)];
 }
 
-int vp9_ac_yquant(int QIndex) {
-  int retval;
-
-  if (QIndex > MAXQ)
-    QIndex = MAXQ;
-  else if (QIndex < 0)
-    QIndex = 0;
-
-  retval = ac_qlookup[ QIndex ];
-  return retval;
+int vp9_ac_yquant(int qindex) {
+  return ac_qlookup[clamp(qindex, 0, MAXQ)];
 }
 
-int vp9_ac_uv_quant(int QIndex, int Delta) {
-  int retval;
-
-  QIndex = QIndex + Delta;
-
-  if (QIndex > MAXQ)
-    QIndex = MAXQ;
-  else if (QIndex < 0)
-    QIndex = 0;
-
-  retval = ac_qlookup[ QIndex ];
-  return retval;
+int vp9_ac_uv_quant(int qindex, int delta) {
+  return ac_qlookup[clamp(qindex + delta, 0, MAXQ)];
 }
diff --git a/vp9/common/vp9_quant_common.h b/vp9/common/vp9_quant_common.h
index 871c2b0357..1520c37977 100644
--- a/vp9/common/vp9_quant_common.h
+++ b/vp9/common/vp9_quant_common.h
@@ -11,16 +11,15 @@
 #ifndef VP9_COMMON_VP9_QUANT_COMMON_H_
 #define VP9_COMMON_VP9_QUANT_COMMON_H_
 
-#include "string.h"
 #include "vp9/common/vp9_blockd.h"
 #include "vp9/common/vp9_onyxc_int.h"
 
-extern void vp9_init_quant_tables(void);
-extern int vp9_ac_yquant(int QIndex);
-extern int vp9_dc_quant(int QIndex, int Delta);
-extern int vp9_dc2quant(int QIndex, int Delta);
-extern int vp9_ac2quant(int QIndex, int Delta);
-extern int vp9_dc_uv_quant(int QIndex, int Delta);
-extern int vp9_ac_uv_quant(int QIndex, int Delta);
+void vp9_init_quant_tables();
+int vp9_ac_yquant(int qindex);
+int vp9_dc_quant(int qindex, int delta);
+int vp9_dc2quant(int qindex, int delta);
+int vp9_ac2quant(int qindex, int delta);
+int vp9_dc_uv_quant(int qindex, int delta);
+int vp9_ac_uv_quant(int qindex, int delta);
 
 #endif  // VP9_COMMON_VP9_QUANT_COMMON_H_
diff --git a/vp9/decoder/vp9_decodframe.c b/vp9/decoder/vp9_decodframe.c
index c2d8e22a18..9d2f06ccfb 100644
--- a/vp9/decoder/vp9_decodframe.c
+++ b/vp9/decoder/vp9_decodframe.c
@@ -1281,7 +1281,7 @@ int vp9_decode_frame(VP9D_COMP *pbi, const unsigned char **p_data_end) {
     pc->version = (data[0] >> 1) & 7;
     pc->show_frame = (data[0] >> 4) & 1;
     scaling_active = (data[0] >> 5) & 1;
-    first_partition_length_in_bytes = data[1] | (data[2] << 8);
+    first_partition_length_in_bytes = read_le16(data + 1);
 
     if (!read_is_valid(data, first_partition_length_in_bytes, data_end))
       vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME,
-- 
GitLab