Rework the level map based txb encoding loop

This commit integrates the level map coding within cb4x4 framework.

Change-Id: Ied9721df0a7ffd21d1d69d68759d91b6c320c179
diff --git a/av1/common/blockd.c b/av1/common/blockd.c
index 5209448..8bc1291 100644
--- a/av1/common/blockd.c
+++ b/av1/common/blockd.c
@@ -158,13 +158,21 @@
 
 #if CONFIG_LV_MAP
 void av1_foreach_transformed_block(const MACROBLOCKD *const xd,
-                                   BLOCK_SIZE bsize,
+                                   BLOCK_SIZE bsize, int mi_row, int mi_col,
                                    foreach_transformed_block_visitor visit,
                                    void *arg) {
   int plane;
 
-  for (plane = 0; plane < MAX_MB_PLANE; ++plane)
+  for (plane = 0; plane < MAX_MB_PLANE; ++plane) {
+#if CONFIG_CB4X4
+    if (bsize < BLOCK_8X8 && plane && !is_chroma_reference(mi_row, mi_col))
+      continue;
+#else
+    (void)mi_row;
+    (void)mi_col;
+#endif
     av1_foreach_transformed_block_in_plane(xd, bsize, plane, visit, arg);
+  }
 }
 #endif
 
diff --git a/av1/common/blockd.h b/av1/common/blockd.h
index 12e5eab..5cf0f83 100644
--- a/av1/common/blockd.h
+++ b/av1/common/blockd.h
@@ -999,7 +999,7 @@
 
 #if CONFIG_LV_MAP
 void av1_foreach_transformed_block(const MACROBLOCKD *const xd,
-                                   BLOCK_SIZE bsize,
+                                   BLOCK_SIZE bsize, int mi_row, int mi_col,
                                    foreach_transformed_block_visitor visit,
                                    void *arg);
 #endif
diff --git a/av1/encoder/encodetxb.c b/av1/encoder/encodetxb.c
index 85e71c0..2c1e22f 100644
--- a/av1/encoder/encodetxb.c
+++ b/av1/encoder/encodetxb.c
@@ -565,10 +565,11 @@
 
   if (!dry_run) {
     td->counts->skip[ctx][0] += skip_inc;
-    av1_foreach_transformed_block(xd, bsize, update_and_record_txb_context,
-                                  &arg);
+    av1_foreach_transformed_block(xd, bsize, mi_row, mi_col,
+                                  update_and_record_txb_context, &arg);
   } else if (dry_run == DRY_RUN_NORMAL) {
-    av1_foreach_transformed_block(xd, bsize, update_txb_context, &arg);
+    av1_foreach_transformed_block(xd, bsize, mi_row, mi_col, update_txb_context,
+                                  &arg);
   } else {
     printf("DRY_RUN_COSTCOEFFS is not supported yet\n");
     assert(0);