Commit 8bbabbea authored by John Koleszar's avatar John Koleszar Committed by Gerrit Code Review
Browse files

Merge "Segmentation code cleanup." into experimental

parents fa135d7b 2c424995
......@@ -12,21 +12,18 @@
#include "vp9/common/vp9_blockd.h"
#include "vp9/common/vp9_seg_common.h"
static const int segfeaturedata_signed[SEG_LVL_MAX] = { 1, 1, 0, 0 };
static const int seg_feature_data_max[SEG_LVL_MAX] = { MAXQ, 63, 0xf, 0xf };
static const int seg_feature_data_signed[SEG_LVL_MAX] = { 1, 1, 0, 0 };
static const int seg_feature_data_max[SEG_LVL_MAX] = { MAXQ, 63, 15, 15 };
// These functions provide access to new segment level features.
// Eventually these function may be "optimized out" but for the moment,
// the coding mechanism is still subject to change so these provide a
// convenient single point of change.
int vp9_segfeature_active(const MACROBLOCKD *xd,
int segment_id,
int vp9_segfeature_active(const MACROBLOCKD *xd, int segment_id,
SEG_LVL_FEATURES feature_id) {
// Return true if mask bit set and segmentation enabled.
return (xd->segmentation_enabled &&
(xd->segment_feature_mask[segment_id] &
(0x01 << feature_id)));
return xd->segmentation_enabled &&
(xd->segment_feature_mask[segment_id] & (1 << feature_id));
}
void vp9_clearall_segfeatures(MACROBLOCKD *xd) {
......@@ -34,14 +31,12 @@ void vp9_clearall_segfeatures(MACROBLOCKD *xd) {
vpx_memset(xd->segment_feature_mask, 0, sizeof(xd->segment_feature_mask));
}
void vp9_enable_segfeature(MACROBLOCKD *xd,
int segment_id,
void vp9_enable_segfeature(MACROBLOCKD *xd, int segment_id,
SEG_LVL_FEATURES feature_id) {
xd->segment_feature_mask[segment_id] |= (0x01 << feature_id);
xd->segment_feature_mask[segment_id] |= 1 << feature_id;
}
void vp9_disable_segfeature(MACROBLOCKD *xd,
int segment_id,
void vp9_disable_segfeature(MACROBLOCKD *xd, int segment_id,
SEG_LVL_FEATURES feature_id) {
xd->segment_feature_mask[segment_id] &= ~(1 << feature_id);
}
......@@ -51,30 +46,26 @@ int vp9_seg_feature_data_max(SEG_LVL_FEATURES feature_id) {
}
int vp9_is_segfeature_signed(SEG_LVL_FEATURES feature_id) {
return segfeaturedata_signed[feature_id];
return seg_feature_data_signed[feature_id];
}
void vp9_clear_segdata(MACROBLOCKD *xd,
int segment_id,
void vp9_clear_segdata(MACROBLOCKD *xd, int segment_id,
SEG_LVL_FEATURES feature_id) {
xd->segment_feature_data[segment_id][feature_id] = 0;
}
void vp9_set_segdata(MACROBLOCKD *xd,
int segment_id,
SEG_LVL_FEATURES feature_id,
int seg_data) {
void vp9_set_segdata(MACROBLOCKD *xd, int segment_id,
SEG_LVL_FEATURES feature_id, int seg_data) {
assert(seg_data <= seg_feature_data_max[feature_id]);
if (seg_data < 0) {
assert(segfeaturedata_signed[feature_id]);
assert(seg_feature_data_signed[feature_id]);
assert(-seg_data <= seg_feature_data_max[feature_id]);
}
xd->segment_feature_data[segment_id][feature_id] = seg_data;
}
int vp9_get_segdata(const MACROBLOCKD *xd,
int segment_id,
int vp9_get_segdata(const MACROBLOCKD *xd, int segment_id,
SEG_LVL_FEATURES feature_id) {
return xd->segment_feature_data[segment_id][feature_id];
}
......@@ -83,23 +74,15 @@ void vp9_clear_segref(MACROBLOCKD *xd, int segment_id) {
xd->segment_feature_data[segment_id][SEG_LVL_REF_FRAME] = 0;
}
void vp9_set_segref(MACROBLOCKD *xd,
int segment_id,
void vp9_set_segref(MACROBLOCKD *xd, int segment_id,
MV_REFERENCE_FRAME ref_frame) {
xd->segment_feature_data[segment_id][SEG_LVL_REF_FRAME] |=
(1 << ref_frame);
xd->segment_feature_data[segment_id][SEG_LVL_REF_FRAME] |= 1 << ref_frame;
}
int vp9_check_segref(const MACROBLOCKD *xd,
int segment_id,
int vp9_check_segref(const MACROBLOCKD *xd, int segment_id,
MV_REFERENCE_FRAME ref_frame) {
return (xd->segment_feature_data[segment_id][SEG_LVL_REF_FRAME] &
(1 << ref_frame)) ? 1 : 0;
}
int vp9_check_segref_inter(MACROBLOCKD *xd, int segment_id) {
return (xd->segment_feature_data[segment_id][SEG_LVL_REF_FRAME] &
~(1 << INTRA_FRAME)) ? 1 : 0;
}
// TBD? Functions to read and write segment data with range / validity checking
......@@ -55,7 +55,5 @@ int vp9_check_segref(const MACROBLOCKD *xd,
int segment_id,
MV_REFERENCE_FRAME ref_frame);
int vp9_check_segref_inter(MACROBLOCKD *xd, int segment_id);
#endif // VP9_COMMON_VP9_SEG_COMMON_H_
......@@ -1272,8 +1272,8 @@ static void update_frame_size(VP9D_COMP *pbi) {
const int width = multiple16(cm->width);
const int height = multiple16(cm->height);
cm->mb_rows = height >> 4;
cm->mb_cols = width >> 4;
cm->mb_rows = height / 16;
cm->mb_cols = width / 16;
cm->MBs = cm->mb_rows * cm->mb_cols;
cm->mode_info_stride = cm->mb_cols + 1;
memset(cm->mip, 0,
......@@ -1294,7 +1294,6 @@ static void setup_segmentation(VP9_COMMON *pc, MACROBLOCKD *xd, vp9_reader *r) {
// this frame.
xd->update_mb_segmentation_map = vp9_read_bit(r);
// If so what method will be used.
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.
......@@ -1303,15 +1302,10 @@ static void setup_segmentation(VP9_COMMON *pc, MACROBLOCKD *xd, vp9_reader *r) {
// Read the prediction probs needed to decode the segment id
pc->temporal_update = vp9_read_bit(r);
for (i = 0; i < PREDICTION_PROBS; i++) {
pc->segment_pred_probs[i] = pc->temporal_update
? (vp9_read_bit(r) ? vp9_read_prob(r) : 255)
: 255;
}
if (pc->temporal_update) {
const vp9_prob *p = xd->mb_segment_tree_probs;
vp9_prob *p_mod = xd->mb_segment_mispred_tree_probs;
const int c0 = p[0] * p[1];
const int c1 = p[0] * (256 - p[1]);
const int c2 = (256 - p[0]) * p[2];
......@@ -1321,6 +1315,12 @@ static void setup_segmentation(VP9_COMMON *pc, MACROBLOCKD *xd, vp9_reader *r) {
p_mod[1] = get_binary_prob(c0, c2 + c3);
p_mod[2] = get_binary_prob(c0 + c1, c3);
p_mod[3] = get_binary_prob(c0 + c1, c2);
for (i = 0; i < PREDICTION_PROBS; i++)
pc->segment_pred_probs[i] = vp9_read_bit(r) ? vp9_read_prob(r) : 255;
} else {
for (i = 0; i < PREDICTION_PROBS; i++)
pc->segment_pred_probs[i] = 255;
}
}
......@@ -1330,25 +1330,17 @@ static void setup_segmentation(VP9_COMMON *pc, MACROBLOCKD *xd, vp9_reader *r) {
vp9_clearall_segfeatures(xd);
// For each segmentation...
for (i = 0; i < MAX_MB_SEGMENTS; i++) {
// For each of the segments features...
for (j = 0; j < SEG_LVL_MAX; j++) {
int data;
// Is the feature enabled
if (vp9_read_bit(r)) {
// Update the feature data and mask
int data = 0;
const int feature_enabled = vp9_read_bit(r);
if (feature_enabled) {
vp9_enable_segfeature(xd, i, j);
data = vp9_decode_unsigned_max(r, vp9_seg_feature_data_max(j));
// Is the segment data signed.
if (vp9_is_segfeature_signed(j) && vp9_read_bit(r)) {
data = -data;
}
} else {
data = 0;
}
vp9_set_segdata(xd, i, j, data);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment