shithub: libvpx

Download patch

ref: df13e01665dfee1de9527b980262bed216554834
parent: 15a23c8131ba567e614982df8dff3199bf1b48bd
parent: 021a15fe9f6465ca2122ca1ea14f09b2e1b1e383
author: Dmitry Kovalev <dkovalev@google.com>
date: Fri Dec 13 06:19:04 EST 2013

Merge "Renaming treed_write() to vp9_write_tree()."

--- a/vp9/encoder/vp9_bitstream.c
+++ b/vp9/encoder/vp9_bitstream.c
@@ -63,14 +63,14 @@
 
 static void write_intra_mode(vp9_writer *w, MB_PREDICTION_MODE mode,
                              const vp9_prob *probs) {
-  write_token(w, vp9_intra_mode_tree, probs, &intra_mode_encodings[mode]);
+  vp9_write_token(w, vp9_intra_mode_tree, probs, &intra_mode_encodings[mode]);
 }
 
 static void write_inter_mode(vp9_writer *w, MB_PREDICTION_MODE mode,
                              const vp9_prob *probs) {
   assert(is_inter_mode(mode));
-  write_token(w, vp9_inter_mode_tree, probs,
-              &inter_mode_encodings[INTER_OFFSET(mode)]);
+  vp9_write_token(w, vp9_inter_mode_tree, probs,
+                  &inter_mode_encodings[INTER_OFFSET(mode)]);
 }
 
 static INLINE void write_be32(uint8_t *p, int value) {
@@ -179,12 +179,12 @@
     if (t >= TWO_TOKEN && t < EOB_TOKEN) {
       int len = UNCONSTRAINED_NODES - p->skip_eob_node;
       int bits = v >> (n - len);
-      treed_write(w, vp9_coef_tree, p->context_tree, bits, len, i);
-      treed_write(w, vp9_coef_con_tree,
-                  vp9_pareto8_full[p->context_tree[PIVOT_NODE] - 1], v, n - len,
-                  0);
+      vp9_write_tree(w, vp9_coef_tree, p->context_tree, bits, len, i);
+      vp9_write_tree(w, vp9_coef_con_tree,
+                     vp9_pareto8_full[p->context_tree[PIVOT_NODE] - 1],
+                     v, n - len, 0);
     } else {
-      treed_write(w, vp9_coef_tree, p->context_tree, v, n, i);
+      vp9_write_tree(w, vp9_coef_tree, p->context_tree, v, n, i);
     }
 
     if (b->base_val) {
@@ -214,7 +214,7 @@
 static void write_segment_id(vp9_writer *w, const struct segmentation *seg,
                              int segment_id) {
   if (seg->enabled && seg->update_map)
-    treed_write(w, vp9_segment_tree, seg->tree_probs, segment_id, 3, 0);
+    vp9_write_tree(w, vp9_segment_tree, seg->tree_probs, segment_id, 3, 0);
 }
 
 // This function encodes the reference frame
@@ -332,16 +332,15 @@
     if (!vp9_segfeature_active(seg, segment_id, SEG_LVL_SKIP)) {
       if (bsize >= BLOCK_8X8) {
         write_inter_mode(bc, mode, mv_ref_p);
-        ++cm->counts.inter_mode[mi->mode_context[rf]]
-                               [INTER_OFFSET(mode)];
+        ++cm->counts.inter_mode[mi->mode_context[rf]][INTER_OFFSET(mode)];
       }
     }
 
     if (cm->mcomp_filter_type == SWITCHABLE) {
       const int ctx = vp9_get_pred_context_switchable_interp(xd);
-      write_token(bc, vp9_switchable_interp_tree,
-                  cm->fc.switchable_interp_prob[ctx],
-                  &switchable_interp_encodings[mi->interp_filter]);
+      vp9_write_token(bc, vp9_switchable_interp_tree,
+                      cm->fc.switchable_interp_prob[ctx],
+                      &switchable_interp_encodings[mi->interp_filter]);
     } else {
       assert(mi->interp_filter == cm->mcomp_filter_type);
     }
@@ -470,7 +469,7 @@
   const int has_cols = (mi_col + hbs) < cm->mi_cols;
 
   if (has_rows && has_cols) {
-    write_token(w, vp9_partition_tree, probs, &partition_encodings[p]);
+    vp9_write_token(w, vp9_partition_tree, probs, &partition_encodings[p]);
   } else if (!has_rows && has_cols) {
     assert(p == PARTITION_SPLIT || p == PARTITION_HORZ);
     vp9_write(w, p == PARTITION_SPLIT, probs[1]);
--- a/vp9/encoder/vp9_boolhuff.h
+++ b/vp9/encoder/vp9_boolhuff.h
@@ -111,5 +111,6 @@
     vp9_write_bit(w, 1 & (data >> bit));
 }
 
+#define vp9_write_prob(w, v) vp9_write_literal((w), (v), 8)
 
 #endif  // VP9_ENCODER_VP9_BOOLHUFF_H_
--- a/vp9/encoder/vp9_encodemv.c
+++ b/vp9/encoder/vp9_encodemv.c
@@ -47,13 +47,13 @@
   vp9_write(w, sign, mvcomp->sign);
 
   // Class
-  write_token(w, vp9_mv_class_tree, mvcomp->classes,
-              &mv_class_encodings[mv_class]);
+  vp9_write_token(w, vp9_mv_class_tree, mvcomp->classes,
+                  &mv_class_encodings[mv_class]);
 
   // Integer bits
   if (mv_class == MV_CLASS_0) {
-    write_token(w, vp9_mv_class0_tree, mvcomp->class0,
-                &mv_class0_encodings[d]);
+    vp9_write_token(w, vp9_mv_class0_tree, mvcomp->class0,
+                    &mv_class0_encodings[d]);
   } else {
     int i;
     const int n = mv_class + CLASS0_BITS - 1;  // number of bits
@@ -62,9 +62,9 @@
   }
 
   // Fractional bits
-  write_token(w, vp9_mv_fp_tree,
-              mv_class == MV_CLASS_0 ?  mvcomp->class0_fp[d] : mvcomp->fp,
-              &mv_fp_encodings[fr]);
+  vp9_write_token(w, vp9_mv_fp_tree,
+                  mv_class == MV_CLASS_0 ?  mvcomp->class0_fp[d] : mvcomp->fp,
+                  &mv_fp_encodings[fr]);
 
   // High precision bit
   if (usehp)
@@ -209,7 +209,7 @@
   const MV_JOINT_TYPE j = vp9_get_mv_joint(&diff);
   usehp = usehp && vp9_use_mv_hp(ref);
 
-  write_token(w, vp9_mv_joint_tree, mvctx->joints, &mv_joint_encodings[j]);
+  vp9_write_token(w, vp9_mv_joint_tree, mvctx->joints, &mv_joint_encodings[j]);
   if (mv_joint_vertical(j))
     encode_mv_component(w, diff.row, &mvctx->comps[0], usehp);
 
--- a/vp9/encoder/vp9_treewriter.h
+++ b/vp9/encoder/vp9_treewriter.h
@@ -8,19 +8,12 @@
  *  be found in the AUTHORS file in the root of the source tree.
  */
 
-
 #ifndef VP9_ENCODER_VP9_TREEWRITER_H_
 #define VP9_ENCODER_VP9_TREEWRITER_H_
 
-/* Trees map alphabets into huffman-like codes suitable for an arithmetic
-   bit coder.  Timothy S Murphy  11 October 2004 */
-
 #include "vp9/common/vp9_treecoder.h"
-
 #include "vp9/encoder/vp9_boolhuff.h"       /* for now */
 
-#define vp9_write_prob(w, v) vp9_write_literal((w), (v), 8)
-
 #define vp9_cost_zero(prob) (vp9_prob_cost[prob])
 
 #define vp9_cost_one(prob) vp9_cost_zero(vp9_complement(prob))
@@ -33,31 +26,6 @@
   return ct[0] * vp9_cost_zero(p) + ct[1] * vp9_cost_one(p);
 }
 
-static INLINE void treed_write(vp9_writer *w,
-                               vp9_tree tree, const vp9_prob *probs,
-                               int bits, int len,
-                               vp9_tree_index i) {
-  do {
-    const int bit = (bits >> --len) & 1;
-    vp9_write(w, bit, probs[i >> 1]);
-    i = tree[i + bit];
-  } while (len);
-}
-
-struct vp9_token {
-  int value;
-  int len;
-};
-
-
-void vp9_tokens_from_tree(struct vp9_token*, const vp9_tree_index *);
-
-static INLINE void write_token(vp9_writer *w, vp9_tree tree,
-                               const vp9_prob *probs,
-                               const struct vp9_token *token) {
-  treed_write(w, tree, probs, token->value, token->len, 0);
-}
-
 static INLINE int treed_cost(vp9_tree tree, const vp9_prob *probs,
                              int bits, int len) {
   int cost = 0;
@@ -78,5 +46,28 @@
 void vp9_tree_probs_from_distribution(vp9_tree tree,
                                       unsigned int branch_ct[ /* n - 1 */ ][2],
                                       const unsigned int num_events[ /* n */ ]);
+
+struct vp9_token {
+  int value;
+  int len;
+};
+
+void vp9_tokens_from_tree(struct vp9_token*, const vp9_tree_index *);
+
+static INLINE void vp9_write_tree(vp9_writer *w, const vp9_tree_index *tree,
+                                  const vp9_prob *probs, int bits, int len,
+                                  vp9_tree_index i) {
+  do {
+    const int bit = (bits >> --len) & 1;
+    vp9_write(w, bit, probs[i >> 1]);
+    i = tree[i + bit];
+  } while (len);
+}
+
+static INLINE void vp9_write_token(vp9_writer *w, const vp9_tree_index *tree,
+                                   const vp9_prob *probs,
+                                   const struct vp9_token *token) {
+  vp9_write_tree(w, tree, probs, token->value, token->len, 0);
+}
 
 #endif  // VP9_ENCODER_VP9_TREEWRITER_H_