consolidate update_mb_segmentation_map data
authorJohn Koleszar <jkoleszar@google.com>
Fri, 12 Oct 2012 05:15:33 +0000 (22:15 -0700)
committerJohn Koleszar <jkoleszar@google.com>
Fri, 12 Oct 2012 14:12:59 +0000 (07:12 -0700)
The update_mb_segmentation_map flag was being signalled earlier than
other data dependent on that flag. Consolidate this data so it's
parsed within the same if-scope as the flag is originally parsed in.

Change-Id: I10e90b4f511856445ef75a85a44ff441e1e5e672

vp8/decoder/decodframe.c
vp8/encoder/bitstream.c

index b2aca85..52d243d 100644 (file)
@@ -1151,9 +1151,27 @@ int vp8_decode_frame(VP8D_COMP *pbi) {
     xd->update_mb_segmentation_map = (unsigned char)vp8_read_bit(bc);
 
     // If so what method will be used.
-    if (xd->update_mb_segmentation_map)
-      pc->temporal_update = (unsigned char)vp8_read_bit(bc);
+    if (xd->update_mb_segmentation_map) {
+      // Which macro block level features are enabled
+
+      // Read the probs used to decode the segment id for each macro
+      // block.
+      for (i = 0; i < MB_FEATURE_TREE_PROBS; i++) {
+          xd->mb_segment_tree_probs[i] = vp8_read_bit(bc) ?
+              (vp8_prob)vp8_read_literal(bc, 8) : 255;
+      }
 
+      // Read the prediction probs needed to decode the segment id
+      pc->temporal_update = (unsigned char)vp8_read_bit(bc);
+      for (i = 0; i < PREDICTION_PROBS; i++) {
+        if (pc->temporal_update) {
+          pc->segment_pred_probs[i] = vp8_read_bit(bc) ?
+              (vp8_prob)vp8_read_literal(bc, 8) : 255;
+        } else {
+          pc->segment_pred_probs[i] = 255;
+        }
+      }
+    }
     // Is the segment data being updated
     xd->update_mb_segmentation_data = (unsigned char)vp8_read_bit(bc);
 
@@ -1218,38 +1236,6 @@ int vp8_decode_frame(VP8D_COMP *pbi) {
         }
       }
     }
-
-    if (xd->update_mb_segmentation_map) {
-      // Which macro block level features are enabled
-      vpx_memset(xd->mb_segment_tree_probs, 255,
-                 sizeof(xd->mb_segment_tree_probs));
-      vpx_memset(pc->segment_pred_probs, 255,
-                 sizeof(pc->segment_pred_probs));
-
-      // Read the probs used to decode the segment id for each macro
-      // block.
-      for (i = 0; i < MB_FEATURE_TREE_PROBS; i++) {
-        // If not explicitly set value is defaulted to 255 by
-        // memset above
-        if (vp8_read_bit(bc))
-          xd->mb_segment_tree_probs[i] =
-            (vp8_prob)vp8_read_literal(bc, 8);
-      }
-
-      // If predictive coding of segment map is enabled read the
-      // prediction probabilities.
-      if (pc->temporal_update) {
-        // Read the prediction probs needed to decode the segment id
-        // when predictive coding enabled
-        for (i = 0; i < PREDICTION_PROBS; i++) {
-          // If not explicitly set value is defaulted to 255 by
-          // memset above
-          if (vp8_read_bit(bc))
-            pc->segment_pred_probs[i] =
-              (vp8_prob)vp8_read_literal(bc, 8);
-        }
-      }
-    }
   }
 
   // Read common prediction model status flag probability updates for the
index f58fd7b..91b606d 100644 (file)
@@ -2473,9 +2473,33 @@ void vp8_pack_bitstream(VP8_COMP *cpi, unsigned char *dest, unsigned long *size)
     if (xd->update_mb_segmentation_map) {
       // Select the coding strategy (temporal or spatial)
       choose_segmap_coding_method(cpi);
+      // Send the tree probabilities used to decode unpredicted
+      // macro-block segments
+      for (i = 0; i < MB_FEATURE_TREE_PROBS; i++) {
+        int data = xd->mb_segment_tree_probs[i];
+
+        if (data != 255) {
+          vp8_write_bit(bc, 1);
+          vp8_write_literal(bc, data, 8);
+        } else {
+          vp8_write_bit(bc, 0);
+        }
+      }
 
       // Write out the chosen coding method.
       vp8_write_bit(bc, (pc->temporal_update) ? 1 : 0);
+      if (pc->temporal_update) {
+        for (i = 0; i < PREDICTION_PROBS; i++) {
+          int data = pc->segment_pred_probs[i];
+
+          if (data != 255) {
+            vp8_write_bit(bc, 1);
+            vp8_write_literal(bc, data, 8);
+          } else {
+            vp8_write_bit(bc, 0);
+          }
+        }
+      }
     }
 
     vp8_write_bit(bc, (xd->update_mb_segmentation_data) ? 1 : 0);
@@ -2569,33 +2593,6 @@ void vp8_pack_bitstream(VP8_COMP *cpi, unsigned char *dest, unsigned long *size)
     save_segment_info(xd);
 #endif
 
-    if (xd->update_mb_segmentation_map) {
-      // Send the tree probabilities used to decode unpredicted
-      // macro-block segments
-      for (i = 0; i < MB_FEATURE_TREE_PROBS; i++) {
-        int Data = xd->mb_segment_tree_probs[i];
-
-        if (Data != 255) {
-          vp8_write_bit(bc, 1);
-          vp8_write_literal(bc, Data, 8);
-        } else
-          vp8_write_bit(bc, 0);
-      }
-
-      // If predictive coding of segment map is enabled send the
-      // prediction probabilities.
-      if (pc->temporal_update) {
-        for (i = 0; i < PREDICTION_PROBS; i++) {
-          int Data = pc->segment_pred_probs[i];
-
-          if (Data != 255) {
-            vp8_write_bit(bc, 1);
-            vp8_write_literal(bc, Data, 8);
-          } else
-            vp8_write_bit(bc, 0);
-        }
-      }
-    }
   }
 
   // Encode the common prediction model status flag probability updates for