OLD | NEW |
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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 cost += segcounts[4] * vp9_cost_zero(probs[5]) + | 103 cost += segcounts[4] * vp9_cost_zero(probs[5]) + |
104 segcounts[5] * vp9_cost_one(probs[5]); | 104 segcounts[5] * vp9_cost_one(probs[5]); |
105 if (c67 > 0) | 105 if (c67 > 0) |
106 cost += segcounts[6] * vp9_cost_zero(probs[6]) + | 106 cost += segcounts[6] * vp9_cost_zero(probs[6]) + |
107 segcounts[7] * vp9_cost_one(probs[6]); | 107 segcounts[7] * vp9_cost_one(probs[6]); |
108 } | 108 } |
109 | 109 |
110 return cost; | 110 return cost; |
111 } | 111 } |
112 | 112 |
113 static void count_segs(VP9_COMP *cpi, const TileInfo *const tile, | 113 static void count_segs(const VP9_COMMON *cm, MACROBLOCKD *xd, |
114 MODE_INFO **mi, | 114 const TileInfo *tile, MODE_INFO **mi, |
115 int *no_pred_segcounts, | 115 int *no_pred_segcounts, |
116 int (*temporal_predictor_count)[2], | 116 int (*temporal_predictor_count)[2], |
117 int *t_unpred_seg_counts, | 117 int *t_unpred_seg_counts, |
118 int bw, int bh, int mi_row, int mi_col) { | 118 int bw, int bh, int mi_row, int mi_col) { |
119 VP9_COMMON *const cm = &cpi->common; | |
120 MACROBLOCKD *const xd = &cpi->mb.e_mbd; | |
121 int segment_id; | 119 int segment_id; |
122 | 120 |
123 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) | 121 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) |
124 return; | 122 return; |
125 | 123 |
126 xd->mi = mi; | 124 xd->mi = mi; |
127 segment_id = xd->mi[0]->mbmi.segment_id; | 125 segment_id = xd->mi[0]->mbmi.segment_id; |
128 | 126 |
129 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); |
130 | 128 |
(...skipping 13 matching lines...) Expand all Loading... |
144 // as appropriate | 142 // as appropriate |
145 xd->mi[0]->mbmi.seg_id_predicted = pred_flag; | 143 xd->mi[0]->mbmi.seg_id_predicted = pred_flag; |
146 temporal_predictor_count[pred_context][pred_flag]++; | 144 temporal_predictor_count[pred_context][pred_flag]++; |
147 | 145 |
148 // Update the "unpredicted" segment count | 146 // Update the "unpredicted" segment count |
149 if (!pred_flag) | 147 if (!pred_flag) |
150 t_unpred_seg_counts[segment_id]++; | 148 t_unpred_seg_counts[segment_id]++; |
151 } | 149 } |
152 } | 150 } |
153 | 151 |
154 static void count_segs_sb(VP9_COMP *cpi, const TileInfo *const tile, | 152 static void count_segs_sb(const VP9_COMMON *cm, MACROBLOCKD *xd, |
155 MODE_INFO **mi, | 153 const TileInfo *tile, MODE_INFO **mi, |
156 int *no_pred_segcounts, | 154 int *no_pred_segcounts, |
157 int (*temporal_predictor_count)[2], | 155 int (*temporal_predictor_count)[2], |
158 int *t_unpred_seg_counts, | 156 int *t_unpred_seg_counts, |
159 int mi_row, int mi_col, | 157 int mi_row, int mi_col, |
160 BLOCK_SIZE bsize) { | 158 BLOCK_SIZE bsize) { |
161 const VP9_COMMON *const cm = &cpi->common; | |
162 const int mis = cm->mi_stride; | 159 const int mis = cm->mi_stride; |
163 int bw, bh; | 160 int bw, bh; |
164 const int bs = num_8x8_blocks_wide_lookup[bsize], hbs = bs / 2; | 161 const int bs = num_8x8_blocks_wide_lookup[bsize], hbs = bs / 2; |
165 | 162 |
166 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) | 163 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) |
167 return; | 164 return; |
168 | 165 |
169 bw = num_8x8_blocks_wide_lookup[mi[0]->mbmi.sb_type]; | 166 bw = num_8x8_blocks_wide_lookup[mi[0]->mbmi.sb_type]; |
170 bh = num_8x8_blocks_high_lookup[mi[0]->mbmi.sb_type]; | 167 bh = num_8x8_blocks_high_lookup[mi[0]->mbmi.sb_type]; |
171 | 168 |
172 if (bw == bs && bh == bs) { | 169 if (bw == bs && bh == bs) { |
173 count_segs(cpi, tile, mi, no_pred_segcounts, temporal_predictor_count, | 170 count_segs(cm, xd, tile, mi, no_pred_segcounts, temporal_predictor_count, |
174 t_unpred_seg_counts, bs, bs, mi_row, mi_col); | 171 t_unpred_seg_counts, bs, bs, mi_row, mi_col); |
175 } else if (bw == bs && bh < bs) { | 172 } else if (bw == bs && bh < bs) { |
176 count_segs(cpi, tile, mi, no_pred_segcounts, temporal_predictor_count, | 173 count_segs(cm, xd, tile, mi, no_pred_segcounts, temporal_predictor_count, |
177 t_unpred_seg_counts, bs, hbs, mi_row, mi_col); | 174 t_unpred_seg_counts, bs, hbs, mi_row, mi_col); |
178 count_segs(cpi, tile, mi + hbs * mis, no_pred_segcounts, | 175 count_segs(cm, xd, tile, mi + hbs * mis, no_pred_segcounts, |
179 temporal_predictor_count, t_unpred_seg_counts, bs, hbs, | 176 temporal_predictor_count, t_unpred_seg_counts, bs, hbs, |
180 mi_row + hbs, mi_col); | 177 mi_row + hbs, mi_col); |
181 } else if (bw < bs && bh == bs) { | 178 } else if (bw < bs && bh == bs) { |
182 count_segs(cpi, tile, mi, no_pred_segcounts, temporal_predictor_count, | 179 count_segs(cm, xd, tile, mi, no_pred_segcounts, temporal_predictor_count, |
183 t_unpred_seg_counts, hbs, bs, mi_row, mi_col); | 180 t_unpred_seg_counts, hbs, bs, mi_row, mi_col); |
184 count_segs(cpi, tile, mi + hbs, | 181 count_segs(cm, xd, tile, mi + hbs, |
185 no_pred_segcounts, temporal_predictor_count, t_unpred_seg_counts, | 182 no_pred_segcounts, temporal_predictor_count, t_unpred_seg_counts, |
186 hbs, bs, mi_row, mi_col + hbs); | 183 hbs, bs, mi_row, mi_col + hbs); |
187 } else { | 184 } else { |
188 const BLOCK_SIZE subsize = subsize_lookup[PARTITION_SPLIT][bsize]; | 185 const BLOCK_SIZE subsize = subsize_lookup[PARTITION_SPLIT][bsize]; |
189 int n; | 186 int n; |
190 | 187 |
191 assert(bw < bs && bh < bs); | 188 assert(bw < bs && bh < bs); |
192 | 189 |
193 for (n = 0; n < 4; n++) { | 190 for (n = 0; n < 4; n++) { |
194 const int mi_dc = hbs * (n & 1); | 191 const int mi_dc = hbs * (n & 1); |
195 const int mi_dr = hbs * (n >> 1); | 192 const int mi_dr = hbs * (n >> 1); |
196 | 193 |
197 count_segs_sb(cpi, tile, &mi[mi_dr * mis + mi_dc], | 194 count_segs_sb(cm, xd, tile, &mi[mi_dr * mis + mi_dc], |
198 no_pred_segcounts, temporal_predictor_count, | 195 no_pred_segcounts, temporal_predictor_count, |
199 t_unpred_seg_counts, | 196 t_unpred_seg_counts, |
200 mi_row + mi_dr, mi_col + mi_dc, subsize); | 197 mi_row + mi_dr, mi_col + mi_dc, subsize); |
201 } | 198 } |
202 } | 199 } |
203 } | 200 } |
204 | 201 |
205 void vp9_choose_segmap_coding_method(VP9_COMP *cpi) { | 202 void vp9_choose_segmap_coding_method(VP9_COMMON *cm, MACROBLOCKD *xd) { |
206 VP9_COMMON *const cm = &cpi->common; | |
207 struct segmentation *seg = &cm->seg; | 203 struct segmentation *seg = &cm->seg; |
208 | 204 |
209 int no_pred_cost; | 205 int no_pred_cost; |
210 int t_pred_cost = INT_MAX; | 206 int t_pred_cost = INT_MAX; |
211 | 207 |
212 int i, tile_col, mi_row, mi_col; | 208 int i, tile_col, mi_row, mi_col; |
213 | 209 |
214 int temporal_predictor_count[PREDICTION_PROBS][2] = { { 0 } }; | 210 int temporal_predictor_count[PREDICTION_PROBS][2] = { { 0 } }; |
215 int no_pred_segcounts[MAX_SEGMENTS] = { 0 }; | 211 int no_pred_segcounts[MAX_SEGMENTS] = { 0 }; |
216 int t_unpred_seg_counts[MAX_SEGMENTS] = { 0 }; | 212 int t_unpred_seg_counts[MAX_SEGMENTS] = { 0 }; |
(...skipping 13 matching lines...) Expand all Loading... |
230 TileInfo tile; | 226 TileInfo tile; |
231 MODE_INFO **mi_ptr; | 227 MODE_INFO **mi_ptr; |
232 vp9_tile_init(&tile, cm, 0, tile_col); | 228 vp9_tile_init(&tile, cm, 0, tile_col); |
233 | 229 |
234 mi_ptr = cm->mi_grid_visible + tile.mi_col_start; | 230 mi_ptr = cm->mi_grid_visible + tile.mi_col_start; |
235 for (mi_row = 0; mi_row < cm->mi_rows; | 231 for (mi_row = 0; mi_row < cm->mi_rows; |
236 mi_row += 8, mi_ptr += 8 * cm->mi_stride) { | 232 mi_row += 8, mi_ptr += 8 * cm->mi_stride) { |
237 MODE_INFO **mi = mi_ptr; | 233 MODE_INFO **mi = mi_ptr; |
238 for (mi_col = tile.mi_col_start; mi_col < tile.mi_col_end; | 234 for (mi_col = tile.mi_col_start; mi_col < tile.mi_col_end; |
239 mi_col += 8, mi += 8) | 235 mi_col += 8, mi += 8) |
240 count_segs_sb(cpi, &tile, mi, no_pred_segcounts, | 236 count_segs_sb(cm, xd, &tile, mi, no_pred_segcounts, |
241 temporal_predictor_count, t_unpred_seg_counts, | 237 temporal_predictor_count, t_unpred_seg_counts, |
242 mi_row, mi_col, BLOCK_64X64); | 238 mi_row, mi_col, BLOCK_64X64); |
243 } | 239 } |
244 } | 240 } |
245 | 241 |
246 // Work out probability tree for coding segments without prediction | 242 // Work out probability tree for coding segments without prediction |
247 // and the cost. | 243 // and the cost. |
248 calc_segtree_probs(no_pred_segcounts, no_pred_tree); | 244 calc_segtree_probs(no_pred_segcounts, no_pred_tree); |
249 no_pred_cost = cost_segmap(no_pred_segcounts, no_pred_tree); | 245 no_pred_cost = cost_segmap(no_pred_segcounts, no_pred_tree); |
250 | 246 |
(...skipping 29 matching lines...) Expand all Loading... |
280 } | 276 } |
281 | 277 |
282 void vp9_reset_segment_features(struct segmentation *seg) { | 278 void vp9_reset_segment_features(struct segmentation *seg) { |
283 // Set up default state for MB feature flags | 279 // Set up default state for MB feature flags |
284 seg->enabled = 0; | 280 seg->enabled = 0; |
285 seg->update_map = 0; | 281 seg->update_map = 0; |
286 seg->update_data = 0; | 282 seg->update_data = 0; |
287 vpx_memset(seg->tree_probs, 255, sizeof(seg->tree_probs)); | 283 vpx_memset(seg->tree_probs, 255, sizeof(seg->tree_probs)); |
288 vp9_clearall_segfeatures(seg); | 284 vp9_clearall_segfeatures(seg); |
289 } | 285 } |
OLD | NEW |