shithub: libvpx

Download patch

ref: b8dc52f4a30db2b9b51061fce9ae100ec049694a
parent: 345fbfef06cede8f56a4c6cd02242f6ffd53a1c6
author: Dmitry Kovalev <dkovalev@google.com>
date: Wed Dec 11 09:38:22 EST 2013

Cleaning up encode_sb() and encode_b() functions.

Trying to make encode_sb() more similar to write_modes_sb() and
decode_mode_sb() because essentially all branching logic should be the
same.

Change-Id: Ib7dec7b48fce29418142abad4d1dcfdb1c770735

--- a/vp9/encoder/vp9_encodeframe.c
+++ b/vp9/encoder/vp9_encodeframe.c
@@ -857,16 +857,9 @@
 
 static void encode_b(VP9_COMP *cpi, const TileInfo *const tile,
                      TOKENEXTRA **tp, int mi_row, int mi_col,
-                     int output_enabled, BLOCK_SIZE bsize, int sub_index) {
-  VP9_COMMON *const cm = &cpi->common;
+                     int output_enabled, BLOCK_SIZE bsize) {
   MACROBLOCK *const x = &cpi->mb;
 
-  if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols)
-    return;
-
-  if (sub_index != -1)
-    *get_sb_index(x, bsize) = sub_index;
-
   if (bsize < BLOCK_8X8) {
     // When ab_index = 0 all sub-blocks are handled, so for ab_index != 0
     // there is nothing to be done.
@@ -890,64 +883,73 @@
                       int output_enabled, BLOCK_SIZE bsize) {
   VP9_COMMON *const cm = &cpi->common;
   MACROBLOCK *const x = &cpi->mb;
-  BLOCK_SIZE c1 = BLOCK_8X8;
-  const int bsl = b_width_log2(bsize), bs = (1 << bsl) / 4;
-  int pl = 0;
+  const int bsl = b_width_log2(bsize), hbs = (1 << bsl) / 4;
+  int ctx;
   PARTITION_TYPE partition;
   BLOCK_SIZE subsize;
-  int i;
 
   if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols)
     return;
 
-  c1 = BLOCK_4X4;
   if (bsize >= BLOCK_8X8) {
-    pl = partition_plane_context(cpi->above_seg_context, cpi->left_seg_context,
+    ctx = partition_plane_context(cpi->above_seg_context, cpi->left_seg_context,
                                  mi_row, mi_col, bsize);
-    c1 = *(get_sb_partitioning(x, bsize));
+    subsize = *get_sb_partitioning(x, bsize);
+  } else {
+    ctx = 0;
+    subsize = BLOCK_4X4;
   }
-  partition = partition_lookup[bsl][c1];
 
+  partition = partition_lookup[bsl][subsize];
+
   switch (partition) {
     case PARTITION_NONE:
       if (output_enabled && bsize >= BLOCK_8X8)
-        cm->counts.partition[pl][PARTITION_NONE]++;
-      encode_b(cpi, tile, tp, mi_row, mi_col, output_enabled, c1, -1);
+        cm->counts.partition[ctx][PARTITION_NONE]++;
+      encode_b(cpi, tile, tp, mi_row, mi_col, output_enabled, subsize);
       break;
     case PARTITION_VERT:
       if (output_enabled)
-        cm->counts.partition[pl][PARTITION_VERT]++;
-      encode_b(cpi, tile, tp, mi_row, mi_col, output_enabled, c1, 0);
-      encode_b(cpi, tile, tp, mi_row, mi_col + bs, output_enabled, c1, 1);
+        cm->counts.partition[ctx][PARTITION_VERT]++;
+      *get_sb_index(x, subsize) = 0;
+      encode_b(cpi, tile, tp, mi_row, mi_col, output_enabled, subsize);
+      if (mi_col + hbs < cm->mi_cols) {
+        *get_sb_index(x, subsize) = 1;
+        encode_b(cpi, tile, tp, mi_row, mi_col + hbs, output_enabled, subsize);
+      }
       break;
     case PARTITION_HORZ:
       if (output_enabled)
-        cm->counts.partition[pl][PARTITION_HORZ]++;
-      encode_b(cpi, tile, tp, mi_row, mi_col, output_enabled, c1, 0);
-      encode_b(cpi, tile, tp, mi_row + bs, mi_col, output_enabled, c1, 1);
+        cm->counts.partition[ctx][PARTITION_HORZ]++;
+      *get_sb_index(x, subsize) = 0;
+      encode_b(cpi, tile, tp, mi_row, mi_col, output_enabled, subsize);
+      if (mi_row + hbs < cm->mi_rows) {
+        *get_sb_index(x, subsize) = 1;
+        encode_b(cpi, tile, tp, mi_row + hbs, mi_col, output_enabled, subsize);
+      }
       break;
     case PARTITION_SPLIT:
       subsize = get_subsize(bsize, PARTITION_SPLIT);
-
       if (output_enabled)
-        cm->counts.partition[pl][PARTITION_SPLIT]++;
+        cm->counts.partition[ctx][PARTITION_SPLIT]++;
 
-      for (i = 0; i < 4; i++) {
-        const int x_idx = i & 1, y_idx = i >> 1;
-
-        *get_sb_index(x, subsize) = i;
-        encode_sb(cpi, tile, tp, mi_row + y_idx * bs, mi_col + x_idx * bs,
-                  output_enabled, subsize);
-      }
+      *get_sb_index(x, subsize) = 0;
+      encode_sb(cpi, tile, tp, mi_row, mi_col, output_enabled, subsize);
+      *get_sb_index(x, subsize) = 1;
+      encode_sb(cpi, tile, tp, mi_row, mi_col + hbs, output_enabled, subsize);
+      *get_sb_index(x, subsize) = 2;
+      encode_sb(cpi, tile, tp, mi_row + hbs, mi_col, output_enabled, subsize);
+      *get_sb_index(x, subsize) = 3;
+      encode_sb(cpi, tile, tp, mi_row + hbs, mi_col + hbs, output_enabled,
+                subsize);
       break;
     default:
-      assert(0);
-      break;
+      assert("Invalid partition type.");
   }
 
   if (partition != PARTITION_SPLIT || bsize == BLOCK_8X8)
     update_partition_context(cpi->above_seg_context, cpi->left_seg_context,
-                             mi_row, mi_col, c1, bsize);
+                             mi_row, mi_col, subsize, bsize);
 }
 
 // Check to see if the given partition size is allowed for a specified number