Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(966)

Unified Diff: source/libvpx/vp9/encoder/vp9_segmentation.c

Issue 23600008: libvpx: Pull from upstream (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_rdopt.c ('k') | source/libvpx/vp9/encoder/vp9_temporal_filter.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: source/libvpx/vp9/encoder/vp9_segmentation.c
===================================================================
--- source/libvpx/vp9/encoder/vp9_segmentation.c (revision 219822)
+++ source/libvpx/vp9/encoder/vp9_segmentation.c (working copy)
@@ -17,39 +17,42 @@
void vp9_enable_segmentation(VP9_PTR ptr) {
VP9_COMP *cpi = (VP9_COMP *)ptr;
+ struct segmentation *const seg = &cpi->common.seg;
- cpi->mb.e_mbd.seg.enabled = 1;
- cpi->mb.e_mbd.seg.update_map = 1;
- cpi->mb.e_mbd.seg.update_data = 1;
+ seg->enabled = 1;
+ seg->update_map = 1;
+ seg->update_data = 1;
}
void vp9_disable_segmentation(VP9_PTR ptr) {
VP9_COMP *cpi = (VP9_COMP *)ptr;
- cpi->mb.e_mbd.seg.enabled = 0;
+ struct segmentation *const seg = &cpi->common.seg;
+ seg->enabled = 0;
}
void vp9_set_segmentation_map(VP9_PTR ptr,
unsigned char *segmentation_map) {
- VP9_COMP *cpi = (VP9_COMP *)(ptr);
+ VP9_COMP *cpi = (VP9_COMP *)ptr;
+ struct segmentation *const seg = &cpi->common.seg;
// Copy in the new segmentation map
vpx_memcpy(cpi->segmentation_map, segmentation_map,
(cpi->common.mi_rows * cpi->common.mi_cols));
// Signal that the map should be updated.
- cpi->mb.e_mbd.seg.update_map = 1;
- cpi->mb.e_mbd.seg.update_data = 1;
+ seg->update_map = 1;
+ seg->update_data = 1;
}
void vp9_set_segment_data(VP9_PTR ptr,
signed char *feature_data,
unsigned char abs_delta) {
- VP9_COMP *cpi = (VP9_COMP *)(ptr);
+ VP9_COMP *cpi = (VP9_COMP *)ptr;
+ struct segmentation *const seg = &cpi->common.seg;
- cpi->mb.e_mbd.seg.abs_delta = abs_delta;
+ seg->abs_delta = abs_delta;
- vpx_memcpy(cpi->mb.e_mbd.seg.feature_data, feature_data,
- sizeof(cpi->mb.e_mbd.seg.feature_data));
+ vpx_memcpy(seg->feature_data, feature_data, sizeof(seg->feature_data));
// TBD ?? Set the feature mask
// vpx_memcpy(cpi->mb.e_mbd.segment_feature_mask, 0,
@@ -57,8 +60,7 @@
}
// Based on set of segment counts calculate a probability tree
-static void calc_segtree_probs(MACROBLOCKD *xd, int *segcounts,
- vp9_prob *segment_tree_probs) {
+static void calc_segtree_probs(int *segcounts, vp9_prob *segment_tree_probs) {
// Work out probabilities of each segment
const int c01 = segcounts[0] + segcounts[1];
const int c23 = segcounts[2] + segcounts[3];
@@ -75,7 +77,7 @@
}
// Based on set of segment counts and probabilities calculate a cost estimate
-static int cost_segmap(MACROBLOCKD *xd, int *segcounts, vp9_prob *probs) {
+static int cost_segmap(int *segcounts, vp9_prob *probs) {
const int c01 = segcounts[0] + segcounts[1];
const int c23 = segcounts[2] + segcounts[3];
const int c45 = segcounts[4] + segcounts[5];
@@ -136,7 +138,7 @@
// Temporal prediction not allowed on key frames
if (cm->frame_type != KEY_FRAME) {
- const BLOCK_SIZE_TYPE bsize = mi->mbmi.sb_type;
+ const BLOCK_SIZE bsize = mi->mbmi.sb_type;
// Test to see if the segment id matches the predicted value.
const int pred_segment_id = vp9_get_segment_id(cm, cm->last_frame_seg_map,
bsize, mi_row, mi_col);
@@ -159,68 +161,61 @@
int (*temporal_predictor_count)[2],
int *t_unpred_seg_counts,
int mi_row, int mi_col,
- BLOCK_SIZE_TYPE bsize) {
- VP9_COMMON *const cm = &cpi->common;
+ BLOCK_SIZE bsize) {
+ const VP9_COMMON *const cm = &cpi->common;
const int mis = cm->mode_info_stride;
- int bwl, bhl;
- const int bsl = mi_width_log2(bsize), bs = 1 << (bsl - 1);
+ int bw, bh;
+ const int bs = num_8x8_blocks_wide_lookup[bsize], hbs = bs / 2;
if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols)
return;
- bwl = mi_width_log2(mi->mbmi.sb_type);
- bhl = mi_height_log2(mi->mbmi.sb_type);
+ bw = num_8x8_blocks_wide_lookup[mi->mbmi.sb_type];
+ bh = num_8x8_blocks_high_lookup[mi->mbmi.sb_type];
- if (bwl == bsl && bhl == bsl) {
+ if (bw == bs && bh == bs) {
count_segs(cpi, mi, no_pred_segcounts, temporal_predictor_count,
- t_unpred_seg_counts, 1 << bsl, 1 << bsl, mi_row, mi_col);
- } else if (bwl == bsl && bhl < bsl) {
+ t_unpred_seg_counts, bs, bs, mi_row, mi_col);
+ } else if (bw == bs && bh < bs) {
count_segs(cpi, mi, no_pred_segcounts, temporal_predictor_count,
- t_unpred_seg_counts, 1 << bsl, bs, mi_row, mi_col);
- count_segs(cpi, mi + bs * mis, no_pred_segcounts, temporal_predictor_count,
- t_unpred_seg_counts, 1 << bsl, bs, mi_row + bs, mi_col);
- } else if (bwl < bsl && bhl == bsl) {
+ t_unpred_seg_counts, bs, hbs, mi_row, mi_col);
+ count_segs(cpi, mi + hbs * mis, no_pred_segcounts, temporal_predictor_count,
+ t_unpred_seg_counts, bs, hbs, mi_row + hbs, mi_col);
+ } else if (bw < bs && bh == bs) {
count_segs(cpi, mi, no_pred_segcounts, temporal_predictor_count,
- t_unpred_seg_counts, bs, 1 << bsl, mi_row, mi_col);
- count_segs(cpi, mi + bs, no_pred_segcounts, temporal_predictor_count,
- t_unpred_seg_counts, bs, 1 << bsl, mi_row, mi_col + bs);
+ t_unpred_seg_counts, hbs, bs, mi_row, mi_col);
+ count_segs(cpi, mi + hbs, no_pred_segcounts, temporal_predictor_count,
+ t_unpred_seg_counts, hbs, bs, mi_row, mi_col + hbs);
} else {
- BLOCK_SIZE_TYPE subsize;
+ const BLOCK_SIZE subsize = subsize_lookup[PARTITION_SPLIT][bsize];
int n;
- assert(bwl < bsl && bhl < bsl);
- if (bsize == BLOCK_SIZE_SB64X64) {
- subsize = BLOCK_SIZE_SB32X32;
- } else if (bsize == BLOCK_SIZE_SB32X32) {
- subsize = BLOCK_SIZE_MB16X16;
- } else {
- assert(bsize == BLOCK_SIZE_MB16X16);
- subsize = BLOCK_SIZE_SB8X8;
- }
+ assert(bw < bs && bh < bs);
for (n = 0; n < 4; n++) {
- const int y_idx = n >> 1, x_idx = n & 0x01;
+ const int mi_dc = hbs * (n & 1);
+ const int mi_dr = hbs * (n >> 1);
- count_segs_sb(cpi, mi + y_idx * bs * mis + x_idx * bs,
+ count_segs_sb(cpi, &mi[mi_dr * mis + mi_dc],
no_pred_segcounts, temporal_predictor_count,
t_unpred_seg_counts,
- mi_row + y_idx * bs, mi_col + x_idx * bs, subsize);
+ mi_row + mi_dr, mi_col + mi_dc, subsize);
}
}
}
void vp9_choose_segmap_coding_method(VP9_COMP *cpi) {
VP9_COMMON *const cm = &cpi->common;
- MACROBLOCKD *const xd = &cpi->mb.e_mbd;
+ struct segmentation *seg = &cm->seg;
int no_pred_cost;
int t_pred_cost = INT_MAX;
int i, tile_col, mi_row, mi_col;
- int temporal_predictor_count[PREDICTION_PROBS][2];
- int no_pred_segcounts[MAX_SEGMENTS];
- int t_unpred_seg_counts[MAX_SEGMENTS];
+ int temporal_predictor_count[PREDICTION_PROBS][2] = { { 0 } };
+ int no_pred_segcounts[MAX_SEGMENTS] = { 0 };
+ int t_unpred_seg_counts[MAX_SEGMENTS] = { 0 };
vp9_prob no_pred_tree[SEG_TREE_PROBS];
vp9_prob t_pred_tree[SEG_TREE_PROBS];
@@ -231,13 +226,9 @@
// Set default state for the segment tree probabilities and the
// temporal coding probabilities
- vpx_memset(xd->seg.tree_probs, 255, sizeof(xd->seg.tree_probs));
- vpx_memset(xd->seg.pred_probs, 255, sizeof(xd->seg.pred_probs));
+ vpx_memset(seg->tree_probs, 255, sizeof(seg->tree_probs));
+ vpx_memset(seg->pred_probs, 255, sizeof(seg->pred_probs));
- vpx_memset(no_pred_segcounts, 0, sizeof(no_pred_segcounts));
- vpx_memset(t_unpred_seg_counts, 0, sizeof(t_unpred_seg_counts));
- vpx_memset(temporal_predictor_count, 0, sizeof(temporal_predictor_count));
-
// First of all generate stats regarding how well the last segment map
// predicts this one
for (tile_col = 0; tile_col < 1 << cm->log2_tile_cols; tile_col++) {
@@ -249,21 +240,21 @@
for (mi_col = cm->cur_tile_mi_col_start; mi_col < cm->cur_tile_mi_col_end;
mi_col += 8, mi += 8)
count_segs_sb(cpi, mi, no_pred_segcounts, temporal_predictor_count,
- t_unpred_seg_counts, mi_row, mi_col, BLOCK_SIZE_SB64X64);
+ t_unpred_seg_counts, mi_row, mi_col, BLOCK_64X64);
}
}
// Work out probability tree for coding segments without prediction
// and the cost.
- calc_segtree_probs(xd, no_pred_segcounts, no_pred_tree);
- no_pred_cost = cost_segmap(xd, no_pred_segcounts, no_pred_tree);
+ calc_segtree_probs(no_pred_segcounts, no_pred_tree);
+ no_pred_cost = cost_segmap(no_pred_segcounts, no_pred_tree);
// Key frames cannot use temporal prediction
if (cm->frame_type != KEY_FRAME) {
// Work out probability tree for coding those segments not
// predicted using the temporal method and the cost.
- calc_segtree_probs(xd, t_unpred_seg_counts, t_pred_tree);
- t_pred_cost = cost_segmap(xd, t_unpred_seg_counts, t_pred_tree);
+ calc_segtree_probs(t_unpred_seg_counts, t_pred_tree);
+ t_pred_cost = cost_segmap(t_unpred_seg_counts, t_pred_tree);
// Add in the cost of the signalling for each prediction context
for (i = 0; i < PREDICTION_PROBS; i++) {
@@ -280,11 +271,11 @@
// Now choose which coding method to use.
if (t_pred_cost < no_pred_cost) {
- xd->seg.temporal_update = 1;
- vpx_memcpy(xd->seg.tree_probs, t_pred_tree, sizeof(t_pred_tree));
- vpx_memcpy(xd->seg.pred_probs, t_nopred_prob, sizeof(t_nopred_prob));
+ seg->temporal_update = 1;
+ vpx_memcpy(seg->tree_probs, t_pred_tree, sizeof(t_pred_tree));
+ vpx_memcpy(seg->pred_probs, t_nopred_prob, sizeof(t_nopred_prob));
} else {
- xd->seg.temporal_update = 0;
- vpx_memcpy(xd->seg.tree_probs, no_pred_tree, sizeof(no_pred_tree));
+ seg->temporal_update = 0;
+ vpx_memcpy(seg->tree_probs, no_pred_tree, sizeof(no_pred_tree));
}
}
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_rdopt.c ('k') | source/libvpx/vp9/encoder/vp9_temporal_filter.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698