]> granicus.if.org Git - libvpx/commitdiff
Tie the bit cost scale to a define.
authorAlex Converse <aconverse@google.com>
Fri, 15 Jan 2016 22:32:52 +0000 (14:32 -0800)
committerAlex Converse <aconverse@google.com>
Fri, 15 Jan 2016 23:59:31 +0000 (15:59 -0800)
This is a pure-refactor in preparation to potentially raise the bit-cost
resolution.

Verified at good speed 0 and rt speed -6.

Change-Id: I5347e6e8c28a9ad9dd0aae1d76a3d0f3c2335bb9

vp9/encoder/vp9_cost.h
vp9/encoder/vp9_encodemb.c
vp9/encoder/vp9_encodemv.c
vp9/encoder/vp9_pickmode.c
vp9/encoder/vp9_rd.c
vp9/encoder/vp9_rd.h
vp9/encoder/vp9_rdopt.c
vp9/encoder/vp9_subexp.c

index eac74c40b433e0ffef6dedcea6d0a1b83c9f8abd..d8bf23f1e6862398c2ccf65fe324af565a7b88a4 100644 (file)
@@ -19,6 +19,9 @@ extern "C" {
 
 extern const unsigned int vp9_prob_cost[256];
 
+// The factor to scale from cost in bits to cost in vp9_prob_cost units.
+#define VP9_PROB_COST_SHIFT 8
+
 #define vp9_cost_zero(prob) (vp9_prob_cost[prob])
 
 #define vp9_cost_one(prob) vp9_cost_zero(vpx_complement(prob))
index 3c6a9283c919d2538e4cacf2fd956a9205e317c4..e3450097539ed92904d5f205e1c50f356c1dbc04 100644 (file)
@@ -50,7 +50,9 @@ void vp9_subtract_plane(MACROBLOCK *x, BLOCK_SIZE bsize, int plane) {
                      pd->dst.buf, pd->dst.stride);
 }
 
-#define RDTRUNC(RM, DM, R, D) ((128 + (R) * (RM)) & 0xFF)
+#define RDTRUNC(RM, DM, R, D)                        \
+  (((1 << (VP9_PROB_COST_SHIFT - 1)) + (R) * (RM)) & \
+   ((1 << VP9_PROB_COST_SHIFT) - 1))
 
 typedef struct vp9_token_state {
   int           rate;
index 3bcd6a3b6fa0c78d57d102908ac807d824dcbc52..109eba8c7661bbcb69e10523c8b6edfb9c25c1c0 100644 (file)
@@ -138,7 +138,8 @@ static int update_mv(vpx_writer *w, const unsigned int ct[2], vpx_prob *cur_p,
                      vpx_prob upd_p) {
   const vpx_prob new_p = get_binary_prob(ct[0], ct[1]) | 1;
   const int update = cost_branch256(ct, *cur_p) + vp9_cost_zero(upd_p) >
-                     cost_branch256(ct, new_p) + vp9_cost_one(upd_p) + 7 * 256;
+                     cost_branch256(ct, new_p) + vp9_cost_one(upd_p) +
+                         (7 << VP9_PROB_COST_SHIFT);
   vpx_write(w, update, upd_p);
   if (update) {
     *cur_p = new_p;
index 4880ff6805e1c92905ab0363c8c613ffc07943cc..ec70df6d880914c45900420ace1c51fe056fd9ad 100644 (file)
@@ -682,8 +682,8 @@ static void block_yrd(VP9_COMP *cpi, MACROBLOCK *x, int *rate, int64_t *dist,
   }
 
   if (*skippable == 0) {
-    *rate <<= 10;
-    *rate += (eob_cost << 8);
+    *rate <<= (2 + VP9_PROB_COST_SHIFT);
+    *rate += (eob_cost << VP9_PROB_COST_SHIFT);
   }
 }
 #endif
index eda7743764fbf1785cf498b9f47d3c84b24284c7..6431b036449eb6924bc9ff1dbaaa596a0029d85c 100644 (file)
@@ -409,7 +409,7 @@ void vp9_model_rd_from_var_lapndz(unsigned int var, unsigned int n_log2,
         (((uint64_t)qstep * qstep << (n_log2 + 10)) + (var >> 1)) / var;
     const int xsq_q10 = (int)VPXMIN(xsq_q10_64, MAX_XSQ_Q10);
     model_rd_norm(xsq_q10, &r_q10, &d_q10);
-    *rate = ((r_q10 << n_log2) + 2) >> 2;
+    *rate = ROUND_POWER_OF_TWO(r_q10 << n_log2, 10 - VP9_PROB_COST_SHIFT);
     *dist = (var * (int64_t)d_q10 + 512) >> 10;
   }
 }
index 28385c981edb53eebebc6f49d8fde943b9defa71..5e6e773a11ca956cf0ef99dc0936249d98bebe07 100644 (file)
@@ -17,6 +17,7 @@
 
 #include "vp9/encoder/vp9_block.h"
 #include "vp9/encoder/vp9_context_tree.h"
+#include "vp9/encoder/vp9_cost.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -25,7 +26,7 @@ extern "C" {
 #define RDDIV_BITS          7
 
 #define RDCOST(RM, DM, R, D) \
-  (((128 + ((int64_t)R) * (RM)) >> 8) + (D << DM))
+  (ROUND_POWER_OF_TWO(((int64_t)R) * (RM), VP9_PROB_COST_SHIFT) + (D << DM))
 #define QIDX_SKIP_THRESH     115
 
 #define MV_COST_WEIGHT      108
index 8ab4c8b351faac9e3e752a70f57e9d0927f8490f..ca0456144acafa22ef65f99eccbe55b88c1ccfac 100644 (file)
@@ -248,7 +248,7 @@ static void model_rd_for_sb(VP9_COMP *cpi, BLOCK_SIZE bsize,
       int quantizer = (pd->dequant[1] >> dequant_shift);
 
       if (quantizer < 120)
-        rate = (square_error * (280 - quantizer)) >> 8;
+        rate = (square_error * (280 - quantizer)) >> (16 - VP9_PROB_COST_SHIFT);
       else
         rate = 0;
       dist = (square_error * quantizer) >> 8;
index 7aa8fc3f60cfc7a64e7474c5bb0e449425ad4f88..1a8719940a2defba08e024f98a1879581ff80151 100644 (file)
@@ -80,7 +80,7 @@ static int remap_prob(int v, int m) {
 
 static int prob_diff_update_cost(vpx_prob newp, vpx_prob oldp) {
   int delp = remap_prob(newp, oldp);
-  return update_bits[delp] * 256;
+  return update_bits[delp] << VP9_PROB_COST_SHIFT;
 }
 
 static void encode_uniform(vpx_writer *w, int v) {