shithub: libvpx

Download patch

ref: b32da7c3da9103f2aff7054f7db469775b8f2931
parent: 9bcf07ae4a1ebd83713350ce7ef9c1d47de9d30f
author: John Koleszar <jkoleszar@google.com>
date: Tue Jun 28 13:03:47 EDT 2011

Use MAX_ENTROPY_TOKENS and ENTROPY_NODES more consistently

There were many instances in the code of vp8_coef_tokens and
vp8_coef_tokens-1, which was a preprocessor macro despite the naming
convention. Replace these with MAX_ENTROPY_TOKENS and ENTROPY_NODES,
respectively.

Change-Id: I72c4f6c7634c94e1fa066cd511471e5592c748da

--- a/vp8/common/coefupdateprobs.h
+++ b/vp8/common/coefupdateprobs.h
@@ -12,7 +12,7 @@
 /* Update probabilities for the nodes in the token entropy tree.
    Generated file included by entropy.c */
 
-const vp8_prob vp8_coef_update_probs [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [vp8_coef_tokens-1] =
+const vp8_prob vp8_coef_update_probs [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [ENTROPY_NODES] =
 {
     {
         {
--- a/vp8/common/defaultcoefcounts.c
+++ b/vp8/common/defaultcoefcounts.c
@@ -15,7 +15,7 @@
 const unsigned int vp8_default_coef_counts[BLOCK_TYPES]
                                           [COEF_BANDS]
                                           [PREV_COEF_CONTEXTS]
-                                          [vp8_coef_tokens] =
+                                          [MAX_ENTROPY_TOKENS] =
 {
 
     {
--- a/vp8/common/defaultcoefcounts.h
+++ b/vp8/common/defaultcoefcounts.h
@@ -16,6 +16,6 @@
 extern const unsigned int vp8_default_coef_counts[BLOCK_TYPES]
                                                  [COEF_BANDS]
                                                  [PREV_COEF_CONTEXTS]
-                                                 [vp8_coef_tokens];
+                                                 [MAX_ENTROPY_TOKENS];
 
 #endif //__DEFAULTCOEFCOUNTS_H
--- a/vp8/common/entropy.c
+++ b/vp8/common/entropy.c
@@ -65,7 +65,7 @@
     -DCT_VAL_CATEGORY5, -DCT_VAL_CATEGORY6   /* 10 = CAT_FIVE */
 };
 
-struct vp8_token_struct vp8_coef_encodings[vp8_coef_tokens];
+struct vp8_token_struct vp8_coef_encodings[MAX_ENTROPY_TOKENS];
 
 /* Trees for extra bits.  Probabilities are constant and
    do not depend on previously encoded bits */
@@ -145,9 +145,9 @@
 
             do
             {
-                unsigned int branch_ct [vp8_coef_tokens-1] [2];
+                unsigned int branch_ct [ENTROPY_NODES] [2];
                 vp8_tree_probs_from_distribution(
-                    vp8_coef_tokens, vp8_coef_encodings, vp8_coef_tree,
+                    MAX_ENTROPY_TOKENS, vp8_coef_encodings, vp8_coef_tree,
                     pc->fc.coef_probs[h][i][k],
                     branch_ct,
                     vp8_default_coef_counts[h][i][k],
--- a/vp8/common/entropy.h
+++ b/vp8/common/entropy.h
@@ -30,13 +30,12 @@
 #define DCT_VAL_CATEGORY6       10      /* 67+       Extra Bits 11+1 */
 #define DCT_EOB_TOKEN           11      /* EOB       Extra Bits 0+0 */
 
-#define vp8_coef_tokens 12
-#define MAX_ENTROPY_TOKENS vp8_coef_tokens
+#define MAX_ENTROPY_TOKENS 12
 #define ENTROPY_NODES 11
 
 extern const vp8_tree_index vp8_coef_tree[];
 
-extern struct vp8_token_struct vp8_coef_encodings[vp8_coef_tokens];
+extern struct vp8_token_struct vp8_coef_encodings[MAX_ENTROPY_TOKENS];
 
 typedef struct
 {
@@ -85,9 +84,9 @@
 /*# define DC_TOKEN_CONTEXTS        3*/ /* 00, 0!0, !0!0 */
 #   define PREV_COEF_CONTEXTS       3
 
-extern DECLARE_ALIGNED(16, const unsigned char, vp8_prev_token_class[vp8_coef_tokens]);
+extern DECLARE_ALIGNED(16, const unsigned char, vp8_prev_token_class[MAX_ENTROPY_TOKENS]);
 
-extern const vp8_prob vp8_coef_update_probs [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [vp8_coef_tokens-1];
+extern const vp8_prob vp8_coef_update_probs [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [ENTROPY_NODES];
 
 
 struct VP8Common;
--- a/vp8/common/onyxc_int.h
+++ b/vp8/common/onyxc_int.h
@@ -43,7 +43,7 @@
     vp8_prob ymode_prob [VP8_YMODES-1];   /* interframe intra mode probs */
     vp8_prob uv_mode_prob [VP8_UV_MODES-1];
     vp8_prob sub_mv_ref_prob [VP8_SUBMVREFS-1];
-    vp8_prob coef_probs [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [vp8_coef_tokens-1];
+    vp8_prob coef_probs [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [ENTROPY_NODES];
     MV_CONTEXT mvc[2];
     MV_CONTEXT pre_mvc[2];  /* not to caculate the mvcost for the frame if mvc doesn't change. */
 } FRAME_CONTEXT;
--- a/vp8/decoder/decodframe.c
+++ b/vp8/decoder/decodframe.c
@@ -979,7 +979,7 @@
         for (i = 0; i < BLOCK_TYPES; i++)
             for (j = 0; j < COEF_BANDS; j++)
                 for (k = 0; k < PREV_COEF_CONTEXTS; k++)
-                    for (l = 0; l < MAX_ENTROPY_TOKENS - 1; l++)
+                    for (l = 0; l < ENTROPY_NODES; l++)
                     {
 
                         vp8_prob *const p = pc->fc.coef_probs [i][j][k] + l;
--- a/vp8/encoder/bitstream.c
+++ b/vp8/encoder/bitstream.c
@@ -50,7 +50,7 @@
 
 #ifdef ENTROPY_STATS
 int intra_mode_stats[10][10][10];
-static unsigned int tree_update_hist [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [vp8_coef_tokens-1] [2];
+static unsigned int tree_update_hist [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [ENTROPY_NODES] [2];
 extern unsigned int active_section;
 #endif
 
@@ -1133,7 +1133,7 @@
 
 /* This function is used for debugging probability trees. */
 static void print_prob_tree(vp8_prob
-     coef_probs[BLOCK_TYPES][COEF_BANDS][PREV_COEF_CONTEXTS][vp8_coef_tokens-1])
+     coef_probs[BLOCK_TYPES][COEF_BANDS][PREV_COEF_CONTEXTS][ENTROPY_NODES])
 {
     /* print coef probability tree */
     int i,j,k,l;
@@ -1148,7 +1148,7 @@
             for (k = 0; k < PREV_COEF_CONTEXTS; k++)
             {
                 fprintf(f, "      {");
-                for (l = 0; l < MAX_ENTROPY_TOKENS - 1; l++)
+                for (l = 0; l < ENTROPY_NODES; l++)
                 {
                     fprintf(f, "%3u, ",
                             (unsigned int)(coef_probs [i][j][k][l]));
@@ -1164,11 +1164,11 @@
 }
 
 static void sum_probs_over_prev_coef_context(
-        const unsigned int probs[PREV_COEF_CONTEXTS][vp8_coef_tokens],
+        const unsigned int probs[PREV_COEF_CONTEXTS][MAX_ENTROPY_TOKENS],
         unsigned int* out)
 {
     int i, j;
-    for (i=0; i < vp8_coef_tokens; ++i)
+    for (i=0; i < MAX_ENTROPY_TOKENS; ++i)
     {
         for (j=0; j < PREV_COEF_CONTEXTS; ++j)
         {
@@ -1203,8 +1203,8 @@
         do
         {
             int k = 0;
-            unsigned int prev_coef_count_sum[vp8_coef_tokens] = {0};
-            int prev_coef_savings[vp8_coef_tokens] = {0};
+            unsigned int prev_coef_count_sum[MAX_ENTROPY_TOKENS] = {0};
+            int prev_coef_savings[MAX_ENTROPY_TOKENS] = {0};
             /* Calculate new probabilities given the constraint that
              * they must be equal over the prev coef contexts
              */
@@ -1224,13 +1224,13 @@
                 /* at every context */
 
                 /* calc probs and branch cts for this frame only */
-                //vp8_prob new_p           [vp8_coef_tokens-1];
-                //unsigned int branch_ct   [vp8_coef_tokens-1] [2];
+                //vp8_prob new_p           [ENTROPY_NODES];
+                //unsigned int branch_ct   [ENTROPY_NODES] [2];
 
                 int t = 0;      /* token/prob index */
 
                 vp8_tree_probs_from_distribution(
-                    vp8_coef_tokens, vp8_coef_encodings, vp8_coef_tree,
+                    MAX_ENTROPY_TOKENS, vp8_coef_encodings, vp8_coef_tree,
                     cpi->frame_coef_probs[i][j][k],
                     cpi->frame_branch_ct [i][j][k],
                     prev_coef_count_sum,
@@ -1248,7 +1248,7 @@
                         (cpi->common.frame_type == KEY_FRAME && newp != oldp))
                         prev_coef_savings[t] += s;
                 }
-                while (++t < vp8_coef_tokens - 1);
+                while (++t < ENTROPY_NODES);
             }
             while (++k < PREV_COEF_CONTEXTS);
             k = 0;
@@ -1263,7 +1263,7 @@
                     cpi->common.frame_type == KEY_FRAME)
                     savings += prev_coef_savings[k];
             }
-            while (++k < vp8_coef_tokens - 1);
+            while (++k < ENTROPY_NODES);
         }
         while (++j < COEF_BANDS);
     }
@@ -1286,14 +1286,14 @@
                 /* at every context */
 
                 /* calc probs and branch cts for this frame only */
-                //vp8_prob new_p           [vp8_coef_tokens-1];
-                //unsigned int branch_ct   [vp8_coef_tokens-1] [2];
+                //vp8_prob new_p           [ENTROPY_NODES];
+                //unsigned int branch_ct   [ENTROPY_NODES] [2];
 
                 int t = 0;      /* token/prob index */
 
 
                 vp8_tree_probs_from_distribution(
-                    vp8_coef_tokens, vp8_coef_encodings, vp8_coef_tree,
+                    MAX_ENTROPY_TOKENS, vp8_coef_encodings, vp8_coef_tree,
                     cpi->frame_coef_probs [i][j][k],
                     cpi->frame_branch_ct [i][j][k],
                     cpi->coef_counts [i][j][k],
@@ -1313,7 +1313,7 @@
                         savings += s;
                     }
                 }
-                while (++t < vp8_coef_tokens - 1);
+                while (++t < ENTROPY_NODES);
             }
             while (++k < PREV_COEF_CONTEXTS);
         }
@@ -1408,13 +1408,13 @@
         do
         {
             int k = 0;
-            int prev_coef_savings[vp8_coef_tokens - 1] = {0};
+            int prev_coef_savings[ENTROPY_NODES] = {0};
             if (cpi->oxcf.error_resilient_mode & VPX_ERROR_RESILIENT_PARTITIONS)
             {
                 for (k = 0; k < PREV_COEF_CONTEXTS; ++k)
                 {
                     int t;      /* token/prob index */
-                    for (t = 0; t < vp8_coef_tokens - 1; ++t)
+                    for (t = 0; t < ENTROPY_NODES; ++t)
                     {
                         const unsigned int *ct = cpi->frame_branch_ct [i][j]
                                                                       [k][t];
@@ -1435,13 +1435,13 @@
                 /* at every context */
 
                 /* calc probs and branch cts for this frame only */
-                //vp8_prob new_p           [vp8_coef_tokens-1];
-                //unsigned int branch_ct   [vp8_coef_tokens-1] [2];
+                //vp8_prob new_p           [ENTROPY_NODES];
+                //unsigned int branch_ct   [ENTROPY_NODES] [2];
 
                 int t = 0;      /* token/prob index */
 
                 //vp8_tree_probs_from_distribution(
-                //    vp8_coef_tokens, vp8_coef_encodings, vp8_coef_tree,
+                //    MAX_ENTROPY_TOKENS, vp8_coef_encodings, vp8_coef_tree,
                 //    new_p, branch_ct, (unsigned int *)cpi->coef_counts [i][j][k],
                 //    256, 1
                 //    );
@@ -1495,7 +1495,7 @@
                     }
 
                 }
-                while (++t < vp8_coef_tokens - 1);
+                while (++t < ENTROPY_NODES);
 
                 /* Accum token counts for generation of default statistics */
 #ifdef ENTROPY_STATS
@@ -1505,7 +1505,7 @@
                 {
                     context_counters [i][j][k][t] += cpi->coef_counts [i][j][k][t];
                 }
-                while (++t < vp8_coef_tokens);
+                while (++t < MAX_ENTROPY_TOKENS);
 
 #endif
 
@@ -1881,7 +1881,7 @@
     FILE *f = fopen("context.c", "a");
     int Sum;
     fprintf(f, "\n/* Update probabilities for token entropy tree. */\n\n");
-    fprintf(f, "const vp8_prob tree_update_probs[BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [vp8_coef_tokens-1] = {\n");
+    fprintf(f, "const vp8_prob tree_update_probs[BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [ENTROPY_NODES] = {\n");
 
     for (i = 0; i < BLOCK_TYPES; i++)
     {
@@ -1895,7 +1895,7 @@
             {
                 fprintf(f, "      {");
 
-                for (l = 0; l < MAX_ENTROPY_TOKENS - 1; l++)
+                for (l = 0; l < ENTROPY_NODES; l++)
                 {
                     Sum = tree_update_hist[i][j][k][l][0] + tree_update_hist[i][j][k][l][1];
 
--- a/vp8/encoder/block.h
+++ b/vp8/encoder/block.h
@@ -115,7 +115,7 @@
     unsigned char *active_ptr;
     MV_CONTEXT *mvc;
 
-    unsigned int token_costs[BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [vp8_coef_tokens];
+    unsigned int token_costs[BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [MAX_ENTROPY_TOKENS];
     int optimize;
     int q_index;
 
--- a/vp8/encoder/onyx_int.h
+++ b/vp8/encoder/onyx_int.h
@@ -401,11 +401,11 @@
 
     unsigned int MVcount [2] [MVvals];  /* (row,col) MV cts this frame */
 
-    unsigned int coef_counts [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [vp8_coef_tokens];  /* for this frame */
-    //DECLARE_ALIGNED(16, int, coef_counts_backup [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [vp8_coef_tokens]);   //not used any more
+    unsigned int coef_counts [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [MAX_ENTROPY_TOKENS];  /* for this frame */
+    //DECLARE_ALIGNED(16, int, coef_counts_backup [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [MAX_ENTROPY_TOKENS]);   //not used any more
     //save vp8_tree_probs_from_distribution result for each frame to avoid repeat calculation
-    vp8_prob frame_coef_probs [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [vp8_coef_tokens-1];
-    unsigned int frame_branch_ct [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [vp8_coef_tokens-1][2];
+    vp8_prob frame_coef_probs [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [ENTROPY_NODES];
+    unsigned int frame_branch_ct [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [ENTROPY_NODES][2];
 
     int gfu_boost;
     int kf_boost;
--- a/vp8/encoder/rdopt.c
+++ b/vp8/encoder/rdopt.c
@@ -134,8 +134,8 @@
 };
 
 static void fill_token_costs(
-    unsigned int c      [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [vp8_coef_tokens],
-    const vp8_prob p    [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [vp8_coef_tokens-1]
+    unsigned int c      [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [MAX_ENTROPY_TOKENS],
+    const vp8_prob p    [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [ENTROPY_NODES]
 )
 {
     int i, j, k;
--- a/vp8/encoder/tokenize.c
+++ b/vp8/encoder/tokenize.c
@@ -21,7 +21,7 @@
    compressions, then generating context.c = initial stats. */
 
 #ifdef ENTROPY_STATS
-_int64 context_counters[BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [vp8_coef_tokens];
+_int64 context_counters[BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [MAX_ENTROPY_TOKENS];
 #endif
 void vp8_stuff_mb(VP8_COMP *cpi, MACROBLOCKD *x, TOKENEXTRA **t) ;
 void vp8_fix_contexts(MACROBLOCKD *x);
@@ -282,9 +282,9 @@
 
     fprintf(f, "\n/* *** GENERATED FILE: DO NOT EDIT *** */\n\n");
 
-    fprintf(f, "int Contexts[BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [vp8_coef_tokens];\n\n");
+    fprintf(f, "int Contexts[BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [MAX_ENTROPY_TOKENS];\n\n");
 
-    fprintf(f, "const int default_contexts[BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [vp8_coef_tokens] = {");
+    fprintf(f, "const int default_contexts[BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [MAX_ENTROPY_TOKENS] = {");
 
 # define Comma( X) (X? ",":"")
 
@@ -317,7 +317,7 @@
                     fprintf(f, "%s %d", Comma(t), y);
 
                 }
-                while (++t < vp8_coef_tokens);
+                while (++t < MAX_ENTROPY_TOKENS);
 
                 fprintf(f, "}");
             }
--- a/vp8/encoder/tokenize.h
+++ b/vp8/encoder/tokenize.h
@@ -37,7 +37,7 @@
 void init_context_counters();
 void print_context_counters();
 
-extern _int64 context_counters[BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [vp8_coef_tokens];
+extern _int64 context_counters[BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [MAX_ENTROPY_TOKENS];
 #endif
 
 extern const int *vp8_dct_value_cost_ptr;