]> granicus.if.org Git - libvpx/commitdiff
Segment Features:
authorPaul Wilkins <paulwilkins@google.com>
Tue, 13 Sep 2011 10:26:39 +0000 (11:26 +0100)
committerPaul Wilkins <paulwilkins@google.com>
Tue, 13 Sep 2011 10:26:39 +0000 (11:26 +0100)
Some basic plumbing added for a range of segment level features.
MB_LVL_* changed to SEG_LVL_* to better reflect meaning.

Change-Id: Iac96da36990aa0e40afc0d86e990df337fd0c50b

vp8/common/blockd.h
vp8/common/entropy.c
vp8/common/entropy.h
vp8/common/loopfilter.c
vp8/decoder/decodframe.c
vp8/encoder/bitstream.c
vp8/encoder/encodeframe.c
vp8/encoder/onyx_if.c
vp8/encoder/onyx_int.h
vp8/encoder/picklpf.c
vp8/encoder/quantize.c

index f66e73c59cff20904fbfcc922b66831a0af0c2c9..873c67467b5eac0e4415f2c72488125680667c2d 100644 (file)
@@ -94,18 +94,23 @@ typedef enum
     MB_MODE_COUNT
 } MB_PREDICTION_MODE;
 
-/* Macroblock level features */
+// Segment level features.
 typedef enum
 {
-    MB_LVL_ALT_Q = 0,               /* Use alternate Quantizer .... */
-    MB_LVL_ALT_LF = 1,              /* Use alternate loop filter value... */
-    MB_LVL_MAX = 2                  /* Number of MB level features supported */
+    SEG_LVL_ALT_Q = 0,               // Use alternate Quantizer ....
+    SEG_LVL_ALT_LF = 1,              // Use alternate loop filter value...
+#if CONFIG_SEGFEATURES
+    SEG_LVL_REF_FRAME = 2,           // Optional Segment reference frame
+    SEG_LVL_MODE = 3,                // Optional Segment mode
+    SEG_LVL_EOB = 4,                 // EOB end stop marker.
+    SEG_LVL_TRANSFORM = 6,           // Block transform size.
+
+    SEG_LVL_MAX = 6                  // Number of MB level features supported
+#else
+    SEG_LVL_MAX = 2                  // Number of MB level features supported
+#endif
 
-} MB_LVL_FEATURES;
-
-/* Segment Feature Masks */
-#define SEGMENT_ALTQ    0x01
-#define SEGMENT_ALT_LF  0x02
+} SEG_LVL_FEATURES;
 
 #define VP8_YMODES  (B_PRED + 1)
 #define VP8_UV_MODES (TM_PRED + 1)
@@ -246,7 +251,9 @@ typedef struct MacroBlockD
 #else
     vp8_prob mb_segment_tree_probs[MB_FEATURE_TREE_PROBS];
 #endif
-    signed char segment_feature_data[MB_LVL_MAX][MAX_MB_SEGMENTS];            // Segment parameters
+
+    // Segment features
+    signed char segment_feature_data[SEG_LVL_MAX][MAX_MB_SEGMENTS];
 
     /* mode_based Loop filter adjustment */
     unsigned char mode_ref_lf_delta_enabled;
index 34b54b9a77139ec92589b8b281cea2e0c0f2fe3d..5fb64df36bf2cec65437260ba0bb72de7c80389d 100644 (file)
@@ -92,7 +92,11 @@ DECLARE_ALIGNED(16, short, vp8_default_zig_zag_mask[16]);
 DECLARE_ALIGNED(64, short, vp8_default_zig_zag_mask_8x8[64]);//int64_t
 #endif
 
-const int vp8_mb_feature_data_bits[MB_LVL_MAX] = {7, 6};
+#if CONFIG_SEGFEATURES
+const int vp8_mb_feature_data_bits[SEG_LVL_MAX] = {7, 6, 2, 3, 4, 2};
+#else
+const int vp8_mb_feature_data_bits[SEG_LVL_MAX] = {7, 6};
+#endif
 
 /* Array indices are identical to previously-existing CONTEXT_NODE indices */
 
index d3e841c3e9e71abe76e0a6d7ba8f1bad32e4b8fe..4d15449c971abbb3101e0b4b58ab00eac9d53548 100644 (file)
@@ -106,7 +106,7 @@ extern short vp8_default_zig_zag_mask[16];
 extern DECLARE_ALIGNED(64, const int, vp8_default_zig_zag1d_8x8[64]);
 extern short vp8_default_zig_zag_mask_8x8[64];//int64_t
 #endif
-extern const int vp8_mb_feature_data_bits[MB_LVL_MAX];
+extern const int vp8_mb_feature_data_bits[SEG_LVL_MAX];
 
 void vp8_coef_tree_initialize(void);
 #endif
index fe0644bdda425a5874e830ae576da301c962831a..b74521622cbac70b338d3dd2d6f96c5ace2f2aed 100644 (file)
@@ -221,11 +221,11 @@ void vp8_loop_filter_frame_init(VP8_COMMON *cm,
             /* Abs value */
             if (mbd->mb_segement_abs_delta == SEGMENT_ABSDATA)
             {
-                lvl_seg = mbd->segment_feature_data[MB_LVL_ALT_LF][seg];
+                lvl_seg = mbd->segment_feature_data[SEG_LVL_ALT_LF][seg];
             }
             else  /* Delta Value */
             {
-                lvl_seg += mbd->segment_feature_data[MB_LVL_ALT_LF][seg];
+                lvl_seg += mbd->segment_feature_data[SEG_LVL_ALT_LF][seg];
                 lvl_seg = (lvl_seg > 0) ? ((lvl_seg > 63) ? 63: lvl_seg) : 0;
             }
         }
@@ -541,13 +541,13 @@ void vp8_loop_filter_partial_frame
         {    /* Abs value */
             if (mbd->mb_segement_abs_delta == SEGMENT_ABSDATA)
             {
-                lvl_seg[i] = mbd->segment_feature_data[MB_LVL_ALT_LF][i];
+                lvl_seg[i] = mbd->segment_feature_data[SEG_LVL_ALT_LF][i];
             }
             /* Delta Value */
             else
             {
                 lvl_seg[i] = default_filt_lvl
-                        + mbd->segment_feature_data[MB_LVL_ALT_LF][i];
+                        + mbd->segment_feature_data[SEG_LVL_ALT_LF][i];
                 lvl_seg[i] = (lvl_seg[i] > 0) ?
                         ((lvl_seg[i] > 63) ? 63: lvl_seg[i]) : 0;
             }
index a1aa1ec8aeff67acd1fa0082f7144ad9e39d49e6..02ac80aabe08f7f5bcec86b64adbcb5a4515b0bf 100644 (file)
@@ -80,12 +80,12 @@ void mb_init_dequantizer(VP8D_COMP *pbi, MACROBLOCKD *xd)
     {
         /* Abs Value */
         if (xd->mb_segement_abs_delta == SEGMENT_ABSDATA)
-            QIndex = xd->segment_feature_data[MB_LVL_ALT_Q][mbmi->segment_id];
+            QIndex = xd->segment_feature_data[SEG_LVL_ALT_Q][mbmi->segment_id];
 
         /* Delta Value */
         else
         {
-            QIndex = pc->base_qindex + xd->segment_feature_data[MB_LVL_ALT_Q][mbmi->segment_id];
+            QIndex = pc->base_qindex + xd->segment_feature_data[SEG_LVL_ALT_Q][mbmi->segment_id];
             QIndex = (QIndex >= 0) ? ((QIndex <= MAXQ) ? QIndex : MAXQ) : 0;    /* Clamp to valid range */
         }
     }
@@ -939,7 +939,7 @@ int vp8_decode_frame(VP8D_COMP *pbi)
             vpx_memset(xd->segment_feature_data, 0, sizeof(xd->segment_feature_data));
 
             /* For each segmentation feature (Quant and loop filter level) */
-            for (i = 0; i < MB_LVL_MAX; i++)
+            for (i = 0; i < SEG_LVL_MAX; i++)
             {
                 for (j = 0; j < MAX_MB_SEGMENTS; j++)
                 {
index e65a7f9d4dda64184400004940d8b2a1fb5a6f96..7c4ec9a887d3baa88496957f89f878767518f44d 100644 (file)
@@ -1846,8 +1846,8 @@ void vp8_pack_bitstream(VP8_COMP *cpi, unsigned char *dest, unsigned long *size)
 
             vp8_write_bit(bc, (xd->mb_segement_abs_delta) ? 1 : 0);
 
-            // For each segmentation feature (Quant and loop filter level)
-            for (i = 0; i < MB_LVL_MAX; i++)
+            // For each segmentation codable feature
+            for (i = 0; i < SEG_LVL_MAX; i++)
             {
                 // For each of the segments
                 for (j = 0; j < MAX_MB_SEGMENTS; j++)
index e3c214580519dd2de6bbf59846fc1c07c74ff625..a3772751000954b9a9cfc82ab6ea5b12e819e070 100644 (file)
@@ -995,7 +995,7 @@ void vp8_encode_frame(VP8_COMP *cpi)
 
     vp8cx_frame_init_quantizer(cpi);
 
-    vp8_initialize_rd_consts(cpi, cm->base_qindex + cm->y1dc_delta_q);\r
+    vp8_initialize_rd_consts(cpi, cm->base_qindex + cm->y1dc_delta_q);
     vp8cx_initialize_me_consts(cpi, cm->base_qindex);
 
     if(cpi->oxcf.tuning == VP8_TUNE_SSIM)
index e2fd622f37fc0e040a7606ee28323edb8247e280..866f542b8d634f1e08b6d18e2243114352434f85 100644 (file)
@@ -428,8 +428,8 @@ static void set_segmentation_map(VP8_PTR ptr, unsigned char *segmentation_map)
 
 // The values given for each segment can be either deltas (from the default value chosen for the frame) or absolute values.
 //
-// Valid range for abs values is (0-127 for MB_LVL_ALT_Q) , (0-63 for SEGMENT_ALT_LF)
-// Valid range for delta values are (+/-127 for MB_LVL_ALT_Q) , (+/-63 for SEGMENT_ALT_LF)
+// Valid range for abs values is (0-127 for SEG_LVL_ALT_Q) , (0-63 for SEGMENT_ALT_LF)
+// Valid range for delta values are (+/-127 for SEG_LVL_ALT_Q) , (+/-63 for SEGMENT_ALT_LF)
 //
 // abs_delta = SEGMENT_DELTADATA (deltas) abs_delta = SEGMENT_ABSDATA (use the absolute values given).
 //
@@ -447,7 +447,7 @@ static void segmentation_test_function(VP8_PTR ptr)
 {
     VP8_COMP *cpi = (VP8_COMP *)(ptr);
     unsigned char *seg_map;
-    signed char feature_data[MB_LVL_MAX][MAX_MB_SEGMENTS];
+    signed char feature_data[SEG_LVL_MAX][MAX_MB_SEGMENTS];
     CHECK_MEM_ERROR(seg_map, vpx_calloc((cpi->common.mb_rows * cpi->common.mb_cols), 1));
     // Create a temporary map for segmentation data.
 
@@ -478,15 +478,15 @@ static void segmentation_test_function(VP8_PTR ptr)
     enable_segmentation(ptr);
 
     // Set up the quant segment data
-    feature_data[MB_LVL_ALT_Q][0] = 0;
-    feature_data[MB_LVL_ALT_Q][1] = 4;
-    feature_data[MB_LVL_ALT_Q][2] = 0;
-    feature_data[MB_LVL_ALT_Q][3] = 0;
+    feature_data[SEG_LVL_ALT_Q][0] = 0;
+    feature_data[SEG_LVL_ALT_Q][1] = 4;
+    feature_data[SEG_LVL_ALT_Q][2] = 0;
+    feature_data[SEG_LVL_ALT_Q][3] = 0;
     // Set up the loop segment data
-    feature_data[MB_LVL_ALT_LF][0] = 0;
-    feature_data[MB_LVL_ALT_LF][1] = 0;
-    feature_data[MB_LVL_ALT_LF][2] = 0;
-    feature_data[MB_LVL_ALT_LF][3] = 0;
+    feature_data[SEG_LVL_ALT_LF][0] = 0;
+    feature_data[SEG_LVL_ALT_LF][1] = 0;
+    feature_data[SEG_LVL_ALT_LF][2] = 0;
+    feature_data[SEG_LVL_ALT_LF][3] = 0;
 
     // Initialise the feature data structure
     // SEGMENT_DELTADATA    0, SEGMENT_ABSDATA      1
@@ -503,7 +503,7 @@ static void segmentation_test_function(VP8_PTR ptr)
 static void cyclic_background_refresh(VP8_COMP *cpi, int Q, int lf_adjustment)
 {
     unsigned char *seg_map;
-    signed char feature_data[MB_LVL_MAX][MAX_MB_SEGMENTS];
+    signed char feature_data[SEG_LVL_MAX][MAX_MB_SEGMENTS];
     int i;
     int block_count = cpi->cyclic_refresh_mode_max_mbs_perframe;
     int mbs_in_frame = cpi->common.mb_rows * cpi->common.mb_cols;
@@ -570,16 +570,16 @@ static void cyclic_background_refresh(VP8_COMP *cpi, int Q, int lf_adjustment)
     enable_segmentation((VP8_PTR)cpi);
 
     // Set up the quant segment data
-    feature_data[MB_LVL_ALT_Q][0] = 0;
-    feature_data[MB_LVL_ALT_Q][1] = (cpi->cyclic_refresh_q - Q);
-    feature_data[MB_LVL_ALT_Q][2] = 0;
-    feature_data[MB_LVL_ALT_Q][3] = 0;
+    feature_data[SEG_LVL_ALT_Q][0] = 0;
+    feature_data[SEG_LVL_ALT_Q][1] = (cpi->cyclic_refresh_q - Q);
+    feature_data[SEG_LVL_ALT_Q][2] = 0;
+    feature_data[SEG_LVL_ALT_Q][3] = 0;
 
     // Set up the loop segment data
-    feature_data[MB_LVL_ALT_LF][0] = 0;
-    feature_data[MB_LVL_ALT_LF][1] = lf_adjustment;
-    feature_data[MB_LVL_ALT_LF][2] = 0;
-    feature_data[MB_LVL_ALT_LF][3] = 0;
+    feature_data[SEG_LVL_ALT_LF][0] = 0;
+    feature_data[SEG_LVL_ALT_LF][1] = lf_adjustment;
+    feature_data[SEG_LVL_ALT_LF][2] = 0;
+    feature_data[SEG_LVL_ALT_LF][3] = 0;
 
     // Initialise the feature data structure
     // SEGMENT_DELTADATA    0, SEGMENT_ABSDATA      1
@@ -5202,7 +5202,7 @@ int vp8_get_preview_raw_frame(VP8_PTR comp, YV12_BUFFER_CONFIG *dest, vp8_ppflag
 int vp8_set_roimap(VP8_PTR comp, unsigned char *map, unsigned int rows, unsigned int cols, int delta_q[4], int delta_lf[4], unsigned int threshold[4])
 {
     VP8_COMP *cpi = (VP8_COMP *) comp;
-    signed char feature_data[MB_LVL_MAX][MAX_MB_SEGMENTS];
+    signed char feature_data[SEG_LVL_MAX][MAX_MB_SEGMENTS];
 
     if (cpi->common.mb_rows != rows || cpi->common.mb_cols != cols)
         return -1;
@@ -5220,16 +5220,16 @@ int vp8_set_roimap(VP8_PTR comp, unsigned char *map, unsigned int rows, unsigned
     enable_segmentation((VP8_PTR)cpi);
 
     // Set up the quant segment data
-    feature_data[MB_LVL_ALT_Q][0] = delta_q[0];
-    feature_data[MB_LVL_ALT_Q][1] = delta_q[1];
-    feature_data[MB_LVL_ALT_Q][2] = delta_q[2];
-    feature_data[MB_LVL_ALT_Q][3] = delta_q[3];
+    feature_data[SEG_LVL_ALT_Q][0] = delta_q[0];
+    feature_data[SEG_LVL_ALT_Q][1] = delta_q[1];
+    feature_data[SEG_LVL_ALT_Q][2] = delta_q[2];
+    feature_data[SEG_LVL_ALT_Q][3] = delta_q[3];
 
     // Set up the loop segment data s
-    feature_data[MB_LVL_ALT_LF][0] = delta_lf[0];
-    feature_data[MB_LVL_ALT_LF][1] = delta_lf[1];
-    feature_data[MB_LVL_ALT_LF][2] = delta_lf[2];
-    feature_data[MB_LVL_ALT_LF][3] = delta_lf[3];
+    feature_data[SEG_LVL_ALT_LF][0] = delta_lf[0];
+    feature_data[SEG_LVL_ALT_LF][1] = delta_lf[1];
+    feature_data[SEG_LVL_ALT_LF][2] = delta_lf[2];
+    feature_data[SEG_LVL_ALT_LF][3] = delta_lf[3];
 
     cpi->segment_encode_breakout[0] = threshold[0];
     cpi->segment_encode_breakout[1] = threshold[1];
index 8519b8f81b955ecf6d365f446ae1944feec16efa..403508bb09842cbefae22503094a0d3eea7b8b94 100644 (file)
@@ -470,14 +470,18 @@ typedef struct VP8_COMP
     int gf_update_recommended;
     int skip_true_count;
     int skip_false_count;
-#if CONFIG_T8X8\r
-    int t4x4_count;\r
-    int t8x8_count;\r
+#if CONFIG_T8X8
+    int t4x4_count;
+    int t8x8_count;
 #endif
 
     unsigned char *segmentation_map;
-    signed char segment_feature_data[MB_LVL_MAX][MAX_MB_SEGMENTS];            // Segment data (can be deltas or absolute values)
-    int  segment_encode_breakout[MAX_MB_SEGMENTS];                    // segment threashold for encode breakout
+
+    // Segment data (can be deltas or absolute values)
+    signed char segment_feature_data[SEG_LVL_MAX][MAX_MB_SEGMENTS];
+
+    // segment threashold for encode breakout
+    int  segment_encode_breakout[MAX_MB_SEGMENTS];
 
     unsigned char *active_map;
     unsigned int active_map_enabled;
index beefe8d8ea0e9b98ba94d73a07f4db38911f0f34..3a6117f6f37d8b7aae51497a4996369f6977eb75 100644 (file)
@@ -259,10 +259,10 @@ void vp8cx_set_alt_lf_level(VP8_COMP *cpi, int filt_val)
     MACROBLOCKD *mbd = &cpi->mb.e_mbd;
     (void) filt_val;
 
-    mbd->segment_feature_data[MB_LVL_ALT_LF][0] = cpi->segment_feature_data[MB_LVL_ALT_LF][0];
-    mbd->segment_feature_data[MB_LVL_ALT_LF][1] = cpi->segment_feature_data[MB_LVL_ALT_LF][1];
-    mbd->segment_feature_data[MB_LVL_ALT_LF][2] = cpi->segment_feature_data[MB_LVL_ALT_LF][2];
-    mbd->segment_feature_data[MB_LVL_ALT_LF][3] = cpi->segment_feature_data[MB_LVL_ALT_LF][3];
+    mbd->segment_feature_data[SEG_LVL_ALT_LF][0] = cpi->segment_feature_data[SEG_LVL_ALT_LF][0];
+    mbd->segment_feature_data[SEG_LVL_ALT_LF][1] = cpi->segment_feature_data[SEG_LVL_ALT_LF][1];
+    mbd->segment_feature_data[SEG_LVL_ALT_LF][2] = cpi->segment_feature_data[SEG_LVL_ALT_LF][2];
+    mbd->segment_feature_data[SEG_LVL_ALT_LF][3] = cpi->segment_feature_data[SEG_LVL_ALT_LF][3];
 }
 
 void vp8cx_pick_filter_level(YV12_BUFFER_CONFIG *sd, VP8_COMP *cpi)
index 328eabbf9ef603defa25eff5ba374186766b7bb9..200d1ae0a144fa89ffd0fdcb08e6b2908f69b2ec 100644 (file)
@@ -1174,11 +1174,11 @@ void vp8cx_mb_init_quantizer(VP8_COMP *cpi, MACROBLOCK *x)
         // Abs Value
         if (xd->mb_segement_abs_delta == SEGMENT_ABSDATA)
 
-            QIndex = xd->segment_feature_data[MB_LVL_ALT_Q][xd->mode_info_context->mbmi.segment_id];
+            QIndex = xd->segment_feature_data[SEG_LVL_ALT_Q][xd->mode_info_context->mbmi.segment_id];
         // Delta Value
         else
         {
-            QIndex = cpi->common.base_qindex + xd->segment_feature_data[MB_LVL_ALT_Q][xd->mode_info_context->mbmi.segment_id];
+            QIndex = cpi->common.base_qindex + xd->segment_feature_data[SEG_LVL_ALT_Q][xd->mode_info_context->mbmi.segment_id];
             QIndex = (QIndex >= 0) ? ((QIndex <= MAXQ) ? QIndex : MAXQ) : 0;    // Clamp to valid range
         }
     }
@@ -1316,10 +1316,10 @@ void vp8_set_quantizer(struct VP8_COMP *cpi, int Q)
 
 
     // Set Segment specific quatizers
-    mbd->segment_feature_data[MB_LVL_ALT_Q][0] = cpi->segment_feature_data[MB_LVL_ALT_Q][0];
-    mbd->segment_feature_data[MB_LVL_ALT_Q][1] = cpi->segment_feature_data[MB_LVL_ALT_Q][1];
-    mbd->segment_feature_data[MB_LVL_ALT_Q][2] = cpi->segment_feature_data[MB_LVL_ALT_Q][2];
-    mbd->segment_feature_data[MB_LVL_ALT_Q][3] = cpi->segment_feature_data[MB_LVL_ALT_Q][3];
+    mbd->segment_feature_data[SEG_LVL_ALT_Q][0] = cpi->segment_feature_data[SEG_LVL_ALT_Q][0];
+    mbd->segment_feature_data[SEG_LVL_ALT_Q][1] = cpi->segment_feature_data[SEG_LVL_ALT_Q][1];
+    mbd->segment_feature_data[SEG_LVL_ALT_Q][2] = cpi->segment_feature_data[SEG_LVL_ALT_Q][2];
+    mbd->segment_feature_data[SEG_LVL_ALT_Q][3] = cpi->segment_feature_data[SEG_LVL_ALT_Q][3];
 
     /* quantizer has to be reinitialized for any delta_q changes */
     if(update)