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

Side by Side Diff: source/libvpx/vp9/encoder/vp9_segmentation.c

Issue 290653003: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 6 years, 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebM project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebM project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 segcounts[5] * vp9_cost_one(probs[5]); 102 segcounts[5] * vp9_cost_one(probs[5]);
103 if (c67 > 0) 103 if (c67 > 0)
104 cost += segcounts[6] * vp9_cost_zero(probs[6]) + 104 cost += segcounts[6] * vp9_cost_zero(probs[6]) +
105 segcounts[7] * vp9_cost_one(probs[6]); 105 segcounts[7] * vp9_cost_one(probs[6]);
106 } 106 }
107 107
108 return cost; 108 return cost;
109 } 109 }
110 110
111 static void count_segs(VP9_COMP *cpi, const TileInfo *const tile, 111 static void count_segs(VP9_COMP *cpi, const TileInfo *const tile,
112 MODE_INFO **mi_8x8, 112 MODE_INFO **mi,
113 int *no_pred_segcounts, 113 int *no_pred_segcounts,
114 int (*temporal_predictor_count)[2], 114 int (*temporal_predictor_count)[2],
115 int *t_unpred_seg_counts, 115 int *t_unpred_seg_counts,
116 int bw, int bh, int mi_row, int mi_col) { 116 int bw, int bh, int mi_row, int mi_col) {
117 VP9_COMMON *const cm = &cpi->common; 117 VP9_COMMON *const cm = &cpi->common;
118 MACROBLOCKD *const xd = &cpi->mb.e_mbd; 118 MACROBLOCKD *const xd = &cpi->mb.e_mbd;
119 int segment_id; 119 int segment_id;
120 120
121 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) 121 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols)
122 return; 122 return;
123 123
124 xd->mi = mi_8x8; 124 xd->mi = mi;
125 segment_id = xd->mi[0]->mbmi.segment_id; 125 segment_id = xd->mi[0]->mbmi.segment_id;
126 126
127 set_mi_row_col(xd, tile, mi_row, bh, mi_col, bw, cm->mi_rows, cm->mi_cols); 127 set_mi_row_col(xd, tile, mi_row, bh, mi_col, bw, cm->mi_rows, cm->mi_cols);
128 128
129 // Count the number of hits on each segment with no prediction 129 // Count the number of hits on each segment with no prediction
130 no_pred_segcounts[segment_id]++; 130 no_pred_segcounts[segment_id]++;
131 131
132 // Temporal prediction not allowed on key frames 132 // Temporal prediction not allowed on key frames
133 if (cm->frame_type != KEY_FRAME) { 133 if (cm->frame_type != KEY_FRAME) {
134 const BLOCK_SIZE bsize = mi_8x8[0]->mbmi.sb_type; 134 const BLOCK_SIZE bsize = xd->mi[0]->mbmi.sb_type;
135 // Test to see if the segment id matches the predicted value. 135 // Test to see if the segment id matches the predicted value.
136 const int pred_segment_id = vp9_get_segment_id(cm, cm->last_frame_seg_map, 136 const int pred_segment_id = vp9_get_segment_id(cm, cm->last_frame_seg_map,
137 bsize, mi_row, mi_col); 137 bsize, mi_row, mi_col);
138 const int pred_flag = pred_segment_id == segment_id; 138 const int pred_flag = pred_segment_id == segment_id;
139 const int pred_context = vp9_get_pred_context_seg_id(xd); 139 const int pred_context = vp9_get_pred_context_seg_id(xd);
140 140
141 // Store the prediction status for this mb and update counts 141 // Store the prediction status for this mb and update counts
142 // as appropriate 142 // as appropriate
143 xd->mi[0]->mbmi.seg_id_predicted = pred_flag; 143 xd->mi[0]->mbmi.seg_id_predicted = pred_flag;
144 temporal_predictor_count[pred_context][pred_flag]++; 144 temporal_predictor_count[pred_context][pred_flag]++;
145 145
146 // Update the "unpredicted" segment count
146 if (!pred_flag) 147 if (!pred_flag)
147 // Update the "unpredicted" segment count
148 t_unpred_seg_counts[segment_id]++; 148 t_unpred_seg_counts[segment_id]++;
149 } 149 }
150 } 150 }
151 151
152 static void count_segs_sb(VP9_COMP *cpi, const TileInfo *const tile, 152 static void count_segs_sb(VP9_COMP *cpi, const TileInfo *const tile,
153 MODE_INFO **mi_8x8, 153 MODE_INFO **mi,
154 int *no_pred_segcounts, 154 int *no_pred_segcounts,
155 int (*temporal_predictor_count)[2], 155 int (*temporal_predictor_count)[2],
156 int *t_unpred_seg_counts, 156 int *t_unpred_seg_counts,
157 int mi_row, int mi_col, 157 int mi_row, int mi_col,
158 BLOCK_SIZE bsize) { 158 BLOCK_SIZE bsize) {
159 const VP9_COMMON *const cm = &cpi->common; 159 const VP9_COMMON *const cm = &cpi->common;
160 const int mis = cm->mi_stride; 160 const int mis = cm->mi_stride;
161 int bw, bh; 161 int bw, bh;
162 const int bs = num_8x8_blocks_wide_lookup[bsize], hbs = bs / 2; 162 const int bs = num_8x8_blocks_wide_lookup[bsize], hbs = bs / 2;
163 163
164 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) 164 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols)
165 return; 165 return;
166 166
167 bw = num_8x8_blocks_wide_lookup[mi_8x8[0]->mbmi.sb_type]; 167 bw = num_8x8_blocks_wide_lookup[mi[0]->mbmi.sb_type];
168 bh = num_8x8_blocks_high_lookup[mi_8x8[0]->mbmi.sb_type]; 168 bh = num_8x8_blocks_high_lookup[mi[0]->mbmi.sb_type];
169 169
170 if (bw == bs && bh == bs) { 170 if (bw == bs && bh == bs) {
171 count_segs(cpi, tile, mi_8x8, no_pred_segcounts, temporal_predictor_count, 171 count_segs(cpi, tile, mi, no_pred_segcounts, temporal_predictor_count,
172 t_unpred_seg_counts, bs, bs, mi_row, mi_col); 172 t_unpred_seg_counts, bs, bs, mi_row, mi_col);
173 } else if (bw == bs && bh < bs) { 173 } else if (bw == bs && bh < bs) {
174 count_segs(cpi, tile, mi_8x8, no_pred_segcounts, temporal_predictor_count, 174 count_segs(cpi, tile, mi, no_pred_segcounts, temporal_predictor_count,
175 t_unpred_seg_counts, bs, hbs, mi_row, mi_col); 175 t_unpred_seg_counts, bs, hbs, mi_row, mi_col);
176 count_segs(cpi, tile, mi_8x8 + hbs * mis, no_pred_segcounts, 176 count_segs(cpi, tile, mi + hbs * mis, no_pred_segcounts,
177 temporal_predictor_count, t_unpred_seg_counts, bs, hbs, 177 temporal_predictor_count, t_unpred_seg_counts, bs, hbs,
178 mi_row + hbs, mi_col); 178 mi_row + hbs, mi_col);
179 } else if (bw < bs && bh == bs) { 179 } else if (bw < bs && bh == bs) {
180 count_segs(cpi, tile, mi_8x8, no_pred_segcounts, temporal_predictor_count, 180 count_segs(cpi, tile, mi, no_pred_segcounts, temporal_predictor_count,
181 t_unpred_seg_counts, hbs, bs, mi_row, mi_col); 181 t_unpred_seg_counts, hbs, bs, mi_row, mi_col);
182 count_segs(cpi, tile, mi_8x8 + hbs, 182 count_segs(cpi, tile, mi + hbs,
183 no_pred_segcounts, temporal_predictor_count, t_unpred_seg_counts, 183 no_pred_segcounts, temporal_predictor_count, t_unpred_seg_counts,
184 hbs, bs, mi_row, mi_col + hbs); 184 hbs, bs, mi_row, mi_col + hbs);
185 } else { 185 } else {
186 const BLOCK_SIZE subsize = subsize_lookup[PARTITION_SPLIT][bsize]; 186 const BLOCK_SIZE subsize = subsize_lookup[PARTITION_SPLIT][bsize];
187 int n; 187 int n;
188 188
189 assert(bw < bs && bh < bs); 189 assert(bw < bs && bh < bs);
190 190
191 for (n = 0; n < 4; n++) { 191 for (n = 0; n < 4; n++) {
192 const int mi_dc = hbs * (n & 1); 192 const int mi_dc = hbs * (n & 1);
193 const int mi_dr = hbs * (n >> 1); 193 const int mi_dr = hbs * (n >> 1);
194 194
195 count_segs_sb(cpi, tile, &mi_8x8[mi_dr * mis + mi_dc], 195 count_segs_sb(cpi, tile, &mi[mi_dr * mis + mi_dc],
196 no_pred_segcounts, temporal_predictor_count, 196 no_pred_segcounts, temporal_predictor_count,
197 t_unpred_seg_counts, 197 t_unpred_seg_counts,
198 mi_row + mi_dr, mi_col + mi_dc, subsize); 198 mi_row + mi_dr, mi_col + mi_dc, subsize);
199 } 199 }
200 } 200 }
201 } 201 }
202 202
203 void vp9_choose_segmap_coding_method(VP9_COMP *cpi) { 203 void vp9_choose_segmap_coding_method(VP9_COMP *cpi) {
204 VP9_COMMON *const cm = &cpi->common; 204 VP9_COMMON *const cm = &cpi->common;
205 struct segmentation *seg = &cm->seg; 205 struct segmentation *seg = &cm->seg;
206 206
207 int no_pred_cost; 207 int no_pred_cost;
208 int t_pred_cost = INT_MAX; 208 int t_pred_cost = INT_MAX;
209 209
210 int i, tile_col, mi_row, mi_col; 210 int i, tile_col, mi_row, mi_col;
211 211
212 int temporal_predictor_count[PREDICTION_PROBS][2] = { { 0 } }; 212 int temporal_predictor_count[PREDICTION_PROBS][2] = { { 0 } };
213 int no_pred_segcounts[MAX_SEGMENTS] = { 0 }; 213 int no_pred_segcounts[MAX_SEGMENTS] = { 0 };
214 int t_unpred_seg_counts[MAX_SEGMENTS] = { 0 }; 214 int t_unpred_seg_counts[MAX_SEGMENTS] = { 0 };
215 215
216 vp9_prob no_pred_tree[SEG_TREE_PROBS]; 216 vp9_prob no_pred_tree[SEG_TREE_PROBS];
217 vp9_prob t_pred_tree[SEG_TREE_PROBS]; 217 vp9_prob t_pred_tree[SEG_TREE_PROBS];
218 vp9_prob t_nopred_prob[PREDICTION_PROBS]; 218 vp9_prob t_nopred_prob[PREDICTION_PROBS];
219 219
220 const int mis = cm->mi_stride;
221 MODE_INFO **mi_ptr, **mi;
222
223 // Set default state for the segment tree probabilities and the 220 // Set default state for the segment tree probabilities and the
224 // temporal coding probabilities 221 // temporal coding probabilities
225 vpx_memset(seg->tree_probs, 255, sizeof(seg->tree_probs)); 222 vpx_memset(seg->tree_probs, 255, sizeof(seg->tree_probs));
226 vpx_memset(seg->pred_probs, 255, sizeof(seg->pred_probs)); 223 vpx_memset(seg->pred_probs, 255, sizeof(seg->pred_probs));
227 224
228 // First of all generate stats regarding how well the last segment map 225 // First of all generate stats regarding how well the last segment map
229 // predicts this one 226 // predicts this one
230 for (tile_col = 0; tile_col < 1 << cm->log2_tile_cols; tile_col++) { 227 for (tile_col = 0; tile_col < 1 << cm->log2_tile_cols; tile_col++) {
231 TileInfo tile; 228 TileInfo tile;
229 MODE_INFO **mi_ptr;
230 vp9_tile_init(&tile, cm, 0, tile_col);
232 231
233 vp9_tile_init(&tile, cm, 0, tile_col);
234 mi_ptr = cm->mi_grid_visible + tile.mi_col_start; 232 mi_ptr = cm->mi_grid_visible + tile.mi_col_start;
235 for (mi_row = 0; mi_row < cm->mi_rows; 233 for (mi_row = 0; mi_row < cm->mi_rows;
236 mi_row += 8, mi_ptr += 8 * mis) { 234 mi_row += 8, mi_ptr += 8 * cm->mi_stride) {
237 mi = mi_ptr; 235 MODE_INFO **mi = mi_ptr;
238 for (mi_col = tile.mi_col_start; mi_col < tile.mi_col_end; 236 for (mi_col = tile.mi_col_start; mi_col < tile.mi_col_end;
239 mi_col += 8, mi += 8) 237 mi_col += 8, mi += 8)
240 count_segs_sb(cpi, &tile, mi, no_pred_segcounts, 238 count_segs_sb(cpi, &tile, mi, no_pred_segcounts,
241 temporal_predictor_count, t_unpred_seg_counts, 239 temporal_predictor_count, t_unpred_seg_counts,
242 mi_row, mi_col, BLOCK_64X64); 240 mi_row, mi_col, BLOCK_64X64);
243 } 241 }
244 } 242 }
245 243
246 // Work out probability tree for coding segments without prediction 244 // Work out probability tree for coding segments without prediction
247 // and the cost. 245 // and the cost.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 } 278 }
281 279
282 void vp9_reset_segment_features(struct segmentation *seg) { 280 void vp9_reset_segment_features(struct segmentation *seg) {
283 // Set up default state for MB feature flags 281 // Set up default state for MB feature flags
284 seg->enabled = 0; 282 seg->enabled = 0;
285 seg->update_map = 0; 283 seg->update_map = 0;
286 seg->update_data = 0; 284 seg->update_data = 0;
287 vpx_memset(seg->tree_probs, 255, sizeof(seg->tree_probs)); 285 vpx_memset(seg->tree_probs, 255, sizeof(seg->tree_probs));
288 vp9_clearall_segfeatures(seg); 286 vp9_clearall_segfeatures(seg);
289 } 287 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698