shithub: libvpx

Download patch

ref: 3f611555d772baff1bd5975c5acf002a1f04a4a2
parent: d007446b3f4c9b9552a16fea4e8b2541e8ed5b95
author: Dmitry Kovalev <dkovalev@google.com>
date: Mon Aug 5 08:26:15 EDT 2013

Changing the order switchable filter enum constants.

This changeset allows to remove vp9_switchable_interp and
vp9_switchable_interp_map arrays and make code much clear. Actually we
still have to use these mapping but only inside read_interp_filter_type and
write_interp_filter_type functions.

Change-Id: I4026c6f8c4acefba6c81421b7bacbaa52cc45f50

--- a/vp9/common/vp9_blockd.h
+++ b/vp9/common/vp9_blockd.h
@@ -56,11 +56,11 @@
 } FRAME_TYPE;
 
 typedef enum {
-  EIGHTTAP_SMOOTH,
-  EIGHTTAP,
-  EIGHTTAP_SHARP,
-  BILINEAR,
-  SWITCHABLE  /* should be the last one */
+  EIGHTTAP = 0,
+  EIGHTTAP_SMOOTH = 1,
+  EIGHTTAP_SHARP = 2,
+  BILINEAR = 3,
+  SWITCHABLE = 4  /* should be the last one */
 } INTERPOLATIONFILTERTYPE;
 
 typedef enum {
--- a/vp9/common/vp9_entropymode.c
+++ b/vp9/common/vp9_entropymode.c
@@ -339,13 +339,10 @@
 }
 
 const vp9_tree_index vp9_switchable_interp_tree[VP9_SWITCHABLE_FILTERS*2-2] = {
-  -0, 2,
-  -1, -2
+  -EIGHTTAP, 2,
+  -EIGHTTAP_SMOOTH, -EIGHTTAP_SHARP
 };
 struct vp9_token vp9_switchable_interp_encodings[VP9_SWITCHABLE_FILTERS];
-const INTERPOLATIONFILTERTYPE vp9_switchable_interp[VP9_SWITCHABLE_FILTERS] = {
-  EIGHTTAP, EIGHTTAP_SMOOTH, EIGHTTAP_SHARP};
-const int vp9_switchable_interp_map[SWITCHABLE + 1] = {1, 0, 2, -1, -1};
 
 void vp9_entropy_mode_init() {
   vp9_tokens_from_tree(vp9_intra_mode_encodings, vp9_intra_mode_tree);
--- a/vp9/common/vp9_entropymode.h
+++ b/vp9/common/vp9_entropymode.h
@@ -49,11 +49,6 @@
 extern const vp9_tree_index vp9_partition_tree[];
 extern struct vp9_token vp9_partition_encodings[PARTITION_TYPES];
 
-extern const INTERPOLATIONFILTERTYPE vp9_switchable_interp
-                 [VP9_SWITCHABLE_FILTERS];
-
-extern const int vp9_switchable_interp_map[SWITCHABLE + 1];
-
 extern const vp9_tree_index vp9_switchable_interp_tree
                  [2 * (VP9_SWITCHABLE_FILTERS - 1)];
 
--- a/vp9/common/vp9_pred_common.c
+++ b/vp9/common/vp9_pred_common.c
@@ -29,18 +29,16 @@
   // The prediction flags in these dummy entries are initialised to 0.
   // left
   const int left_mv_pred = is_inter_mode(left_mbmi->mode);
-  const int left_interp = left_in_image && left_mv_pred ?
-          vp9_switchable_interp_map[left_mbmi->interp_filter] :
-          VP9_SWITCHABLE_FILTERS;
+  const int left_interp = left_in_image && left_mv_pred
+                              ? left_mbmi->interp_filter
+                              : VP9_SWITCHABLE_FILTERS;
 
   // above
   const int above_mv_pred = is_inter_mode(above_mbmi->mode);
-  const int above_interp = above_in_image && above_mv_pred ?
-          vp9_switchable_interp_map[above_mbmi->interp_filter] :
-          VP9_SWITCHABLE_FILTERS;
+  const int above_interp = above_in_image && above_mv_pred
+                               ? above_mbmi->interp_filter
+                               : VP9_SWITCHABLE_FILTERS;
 
-  assert(left_interp != -1);
-  assert(above_interp != -1);
 
   if (left_interp == above_interp)
     return left_interp;
--- a/vp9/decoder/vp9_decodemv.c
+++ b/vp9/decoder/vp9_decodemv.c
@@ -371,10 +371,10 @@
   VP9_COMMON *const cm = &pbi->common;
   MACROBLOCKD *const xd = &pbi->mb;
   const vp9_prob *probs = vp9_get_pred_probs_switchable_interp(cm, xd);
-  const int index = treed_read(r, vp9_switchable_interp_tree, probs);
+  const int type = treed_read(r, vp9_switchable_interp_tree, probs);
   const int ctx = vp9_get_pred_context_switchable_interp(xd);
-  ++cm->counts.switchable_interp[ctx][index];
-  return vp9_switchable_interp[index];
+  ++cm->counts.switchable_interp[ctx][type];
+  return type;
 }
 
 static void read_intra_block_mode_info(VP9D_COMP *pbi, MODE_INFO *mi,
--- a/vp9/decoder/vp9_decodframe.c
+++ b/vp9/decoder/vp9_decodframe.c
@@ -497,8 +497,11 @@
 
 static INTERPOLATIONFILTERTYPE read_interp_filter_type(
     struct vp9_read_bit_buffer *rb) {
+  const INTERPOLATIONFILTERTYPE literal_to_type[] = { EIGHTTAP_SMOOTH,
+                                                      EIGHTTAP,
+                                                      EIGHTTAP_SHARP };
   return vp9_rb_read_bit(rb) ? SWITCHABLE
-                             : vp9_rb_read_literal(rb, 2);
+                             : literal_to_type[vp9_rb_read_literal(rb, 2)];
 }
 
 static void read_frame_size(struct vp9_read_bit_buffer *rb,
@@ -836,7 +839,7 @@
       pbi->refresh_frame_flags = vp9_rb_read_literal(rb, NUM_REF_FRAMES);
       setup_frame_size(pbi, rb);
     } else {
-       pbi->refresh_frame_flags = vp9_rb_read_literal(rb, NUM_REF_FRAMES);
+      pbi->refresh_frame_flags = vp9_rb_read_literal(rb, NUM_REF_FRAMES);
 
       for (i = 0; i < ALLOWED_REFS_PER_FRAME; ++i) {
         const int ref = vp9_rb_read_literal(rb, NUM_REF_FRAMES_LOG2);
--- a/vp9/encoder/vp9_bitstream.c
+++ b/vp9/encoder/vp9_bitstream.c
@@ -479,8 +479,7 @@
     if (cpi->common.mcomp_filter_type == SWITCHABLE) {
       write_token(bc, vp9_switchable_interp_tree,
                   vp9_get_pred_probs_switchable_interp(&cpi->common, xd),
-                  vp9_switchable_interp_encodings +
-                  vp9_switchable_interp_map[mi->interp_filter]);
+                  &vp9_switchable_interp_encodings[mi->interp_filter]);
     } else {
       assert(mi->interp_filter == cpi->common.mcomp_filter_type);
     }
@@ -1072,9 +1071,11 @@
 
 static void write_interp_filter_type(INTERPOLATIONFILTERTYPE type,
                                      struct vp9_write_bit_buffer *wb) {
+  const int type_to_literal[] = { 1, 0, 2 };
+
   vp9_wb_write_bit(wb, type == SWITCHABLE);
   if (type != SWITCHABLE)
-    vp9_wb_write_literal(wb, type, 2);
+    vp9_wb_write_literal(wb, type_to_literal[type], 2);
 }
 
 static void fix_mcomp_filter_type(VP9_COMP *cpi) {
@@ -1094,7 +1095,7 @@
       // Only one filter is used. So set the filter at frame level
       for (i = 0; i < VP9_SWITCHABLE_FILTERS; ++i) {
         if (count[i]) {
-          cm->mcomp_filter_type = vp9_switchable_interp[i];
+          cm->mcomp_filter_type = i;
           break;
         }
       }
--- a/vp9/encoder/vp9_encodeframe.c
+++ b/vp9/encoder/vp9_encodeframe.c
@@ -439,8 +439,7 @@
     if (cpi->common.mcomp_filter_type == SWITCHABLE
         && is_inter_mode(mbmi->mode)) {
       ++cpi->common.counts.switchable_interp[
-          vp9_get_pred_context_switchable_interp(xd)]
-            [vp9_switchable_interp_map[mbmi->interp_filter]];
+          vp9_get_pred_context_switchable_interp(xd)][mbmi->interp_filter];
     }
 
     cpi->rd_comp_pred_diff[SINGLE_PREDICTION_ONLY] += ctx->single_pred_diff;
@@ -2385,15 +2384,15 @@
             cpi->rd_filter_threshes[frame_type][2] &&
         cpi->rd_filter_threshes[frame_type][1] >
             cpi->rd_filter_threshes[frame_type][VP9_SWITCHABLE_FILTERS]) {
-      filter_type = vp9_switchable_interp[1];
+      filter_type = EIGHTTAP_SMOOTH;
     } else if (cpi->rd_filter_threshes[frame_type][2] >
             cpi->rd_filter_threshes[frame_type][0] &&
         cpi->rd_filter_threshes[frame_type][2] >
             cpi->rd_filter_threshes[frame_type][VP9_SWITCHABLE_FILTERS]) {
-      filter_type = vp9_switchable_interp[2];
+      filter_type = EIGHTTAP_SHARP;
     } else if (cpi->rd_filter_threshes[frame_type][0] >
                   cpi->rd_filter_threshes[frame_type][VP9_SWITCHABLE_FILTERS]) {
-      filter_type = vp9_switchable_interp[0];
+      filter_type = EIGHTTAP;
     } else {
       filter_type = SWITCHABLE;
     }
--- a/vp9/encoder/vp9_rdopt.c
+++ b/vp9/encoder/vp9_rdopt.c
@@ -2003,7 +2003,7 @@
         }
 
         if (mbmi->ref_frame[1] > 0 && this_mode == NEWMV &&
-            mbmi->interp_filter == vp9_switchable_interp[0]) {
+            mbmi->interp_filter == EIGHTTAP) {
           if (seg_mvs[i][mbmi->ref_frame[1]].as_int == INVALID_MV ||
               seg_mvs[i][mbmi->ref_frame[0]].as_int == INVALID_MV)
             continue;
@@ -2456,7 +2456,7 @@
   MB_MODE_INFO *const mbmi = &xd->mode_info_context->mbmi;
 
   const int c = vp9_get_pred_context_switchable_interp(xd);
-  const int m = vp9_switchable_interp_map[mbmi->interp_filter];
+  const int m = mbmi->interp_filter;
   return SWITCHABLE_INTERP_RATE_FACTOR * x->switchable_interp_costs[c][m];
 }
 
@@ -2882,9 +2882,8 @@
     for (i = 0; i < VP9_SWITCHABLE_FILTERS; ++i) {
       int j;
       int64_t rs_rd;
-      const INTERPOLATIONFILTERTYPE filter = vp9_switchable_interp[i];
       const int is_intpel_interp = intpel_mv;
-      mbmi->interp_filter = filter;
+      mbmi->interp_filter = i;
       vp9_setup_interp_filters(xd, mbmi->interp_filter, cm);
       rs = get_switchable_rate(x);
       rs_rd = RDCOST(x->rdmult, x->rddiv, rs, 0);
@@ -3593,8 +3592,7 @@
            ++switchable_filter_index) {
         int newbest, rs;
         int64_t rs_rd;
-        mbmi->interp_filter =
-            vp9_switchable_interp[switchable_filter_index];
+        mbmi->interp_filter = switchable_filter_index;
         vp9_setup_interp_filters(xd, mbmi->interp_filter, &cpi->common);
 
         tmp_rd = rd_pick_best_mbsegmentation(cpi, x,
@@ -3927,8 +3925,7 @@
     if (!mode_excluded && !disable_skip && ref_frame != INTRA_FRAME &&
         cm->mcomp_filter_type != BILINEAR) {
       int64_t ref = cpi->rd_filter_cache[cm->mcomp_filter_type == SWITCHABLE ?
-                              VP9_SWITCHABLE_FILTERS :
-                              vp9_switchable_interp_map[cm->mcomp_filter_type]];
+                              VP9_SWITCHABLE_FILTERS : cm->mcomp_filter_type];
       for (i = 0; i <= VP9_SWITCHABLE_FILTERS; i++) {
         int64_t adj_rd;
         // In cases of poor prediction, filter_cache[] can contain really big