OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2010 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 // Assuming max number of probabilities <= 32 | 71 // Assuming max number of probabilities <= 32 |
72 assert(n <= 32); | 72 assert(n <= 32); |
73 | 73 |
74 vp9_tree_probs_from_distribution(tree, branch_ct, counts); | 74 vp9_tree_probs_from_distribution(tree, branch_ct, counts); |
75 for (i = 0; i < n - 1; ++i) | 75 for (i = 0; i < n - 1; ++i) |
76 vp9_cond_prob_diff_update(w, &probs[i], branch_ct[i]); | 76 vp9_cond_prob_diff_update(w, &probs[i], branch_ct[i]); |
77 } | 77 } |
78 | 78 |
79 static void write_selected_tx_size(const VP9_COMMON *cm, | 79 static void write_selected_tx_size(const VP9_COMMON *cm, |
80 const MACROBLOCKD *xd, vp9_writer *w) { | 80 const MACROBLOCKD *xd, vp9_writer *w) { |
81 TX_SIZE tx_size = xd->mi[0].src_mi->mbmi.tx_size; | 81 TX_SIZE tx_size = xd->mi[0]->mbmi.tx_size; |
82 BLOCK_SIZE bsize = xd->mi[0].src_mi->mbmi.sb_type; | 82 BLOCK_SIZE bsize = xd->mi[0]->mbmi.sb_type; |
83 const TX_SIZE max_tx_size = max_txsize_lookup[bsize]; | 83 const TX_SIZE max_tx_size = max_txsize_lookup[bsize]; |
84 const vp9_prob *const tx_probs = get_tx_probs2(max_tx_size, xd, | 84 const vp9_prob *const tx_probs = get_tx_probs2(max_tx_size, xd, |
85 &cm->fc->tx_probs); | 85 &cm->fc->tx_probs); |
86 vp9_write(w, tx_size != TX_4X4, tx_probs[0]); | 86 vp9_write(w, tx_size != TX_4X4, tx_probs[0]); |
87 if (tx_size != TX_4X4 && max_tx_size >= TX_16X16) { | 87 if (tx_size != TX_4X4 && max_tx_size >= TX_16X16) { |
88 vp9_write(w, tx_size != TX_8X8, tx_probs[1]); | 88 vp9_write(w, tx_size != TX_8X8, tx_probs[1]); |
89 if (tx_size != TX_8X8 && max_tx_size >= TX_32X32) | 89 if (tx_size != TX_8X8 && max_tx_size >= TX_32X32) |
90 vp9_write(w, tx_size != TX_16X16, tx_probs[2]); | 90 vp9_write(w, tx_size != TX_16X16, tx_probs[2]); |
91 } | 91 } |
92 } | 92 } |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 | 194 |
195 static void write_segment_id(vp9_writer *w, const struct segmentation *seg, | 195 static void write_segment_id(vp9_writer *w, const struct segmentation *seg, |
196 int segment_id) { | 196 int segment_id) { |
197 if (seg->enabled && seg->update_map) | 197 if (seg->enabled && seg->update_map) |
198 vp9_write_tree(w, vp9_segment_tree, seg->tree_probs, segment_id, 3, 0); | 198 vp9_write_tree(w, vp9_segment_tree, seg->tree_probs, segment_id, 3, 0); |
199 } | 199 } |
200 | 200 |
201 // This function encodes the reference frame | 201 // This function encodes the reference frame |
202 static void write_ref_frames(const VP9_COMMON *cm, const MACROBLOCKD *xd, | 202 static void write_ref_frames(const VP9_COMMON *cm, const MACROBLOCKD *xd, |
203 vp9_writer *w) { | 203 vp9_writer *w) { |
204 const MB_MODE_INFO *const mbmi = &xd->mi[0].src_mi->mbmi; | 204 const MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi; |
205 const int is_compound = has_second_ref(mbmi); | 205 const int is_compound = has_second_ref(mbmi); |
206 const int segment_id = mbmi->segment_id; | 206 const int segment_id = mbmi->segment_id; |
207 | 207 |
208 // If segment level coding of this signal is disabled... | 208 // If segment level coding of this signal is disabled... |
209 // or the segment allows multiple reference frame options | 209 // or the segment allows multiple reference frame options |
210 if (vp9_segfeature_active(&cm->seg, segment_id, SEG_LVL_REF_FRAME)) { | 210 if (vp9_segfeature_active(&cm->seg, segment_id, SEG_LVL_REF_FRAME)) { |
211 assert(!is_compound); | 211 assert(!is_compound); |
212 assert(mbmi->ref_frame[0] == | 212 assert(mbmi->ref_frame[0] == |
213 vp9_get_segdata(&cm->seg, segment_id, SEG_LVL_REF_FRAME)); | 213 vp9_get_segdata(&cm->seg, segment_id, SEG_LVL_REF_FRAME)); |
214 } else { | 214 } else { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 write_segment_id(w, seg, segment_id); | 261 write_segment_id(w, seg, segment_id); |
262 } | 262 } |
263 } | 263 } |
264 | 264 |
265 skip = write_skip(cm, xd, segment_id, mi, w); | 265 skip = write_skip(cm, xd, segment_id, mi, w); |
266 | 266 |
267 if (!vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME)) | 267 if (!vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME)) |
268 vp9_write(w, is_inter, vp9_get_intra_inter_prob(cm, xd)); | 268 vp9_write(w, is_inter, vp9_get_intra_inter_prob(cm, xd)); |
269 | 269 |
270 if (bsize >= BLOCK_8X8 && cm->tx_mode == TX_MODE_SELECT && | 270 if (bsize >= BLOCK_8X8 && cm->tx_mode == TX_MODE_SELECT && |
271 !(is_inter && | 271 !(is_inter && skip)) { |
272 (skip || vp9_segfeature_active(seg, segment_id, SEG_LVL_SKIP)))) { | |
273 write_selected_tx_size(cm, xd, w); | 272 write_selected_tx_size(cm, xd, w); |
274 } | 273 } |
275 | 274 |
276 if (!is_inter) { | 275 if (!is_inter) { |
277 if (bsize >= BLOCK_8X8) { | 276 if (bsize >= BLOCK_8X8) { |
278 write_intra_mode(w, mode, cm->fc->y_mode_prob[size_group_lookup[bsize]]); | 277 write_intra_mode(w, mode, cm->fc->y_mode_prob[size_group_lookup[bsize]]); |
279 } else { | 278 } else { |
280 int idx, idy; | 279 int idx, idy; |
281 const int num_4x4_w = num_4x4_blocks_wide_lookup[bsize]; | 280 const int num_4x4_w = num_4x4_blocks_wide_lookup[bsize]; |
282 const int num_4x4_h = num_4x4_blocks_high_lookup[bsize]; | 281 const int num_4x4_h = num_4x4_blocks_high_lookup[bsize]; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 for (ref = 0; ref < 1 + is_compound; ++ref) | 331 for (ref = 0; ref < 1 + is_compound; ++ref) |
333 vp9_encode_mv(cpi, w, &mbmi->mv[ref].as_mv, | 332 vp9_encode_mv(cpi, w, &mbmi->mv[ref].as_mv, |
334 &mbmi->ref_mvs[mbmi->ref_frame[ref]][0].as_mv, nmvc, | 333 &mbmi->ref_mvs[mbmi->ref_frame[ref]][0].as_mv, nmvc, |
335 allow_hp); | 334 allow_hp); |
336 } | 335 } |
337 } | 336 } |
338 } | 337 } |
339 } | 338 } |
340 | 339 |
341 static void write_mb_modes_kf(const VP9_COMMON *cm, const MACROBLOCKD *xd, | 340 static void write_mb_modes_kf(const VP9_COMMON *cm, const MACROBLOCKD *xd, |
342 MODE_INFO *mi_8x8, vp9_writer *w) { | 341 MODE_INFO **mi_8x8, vp9_writer *w) { |
343 const struct segmentation *const seg = &cm->seg; | 342 const struct segmentation *const seg = &cm->seg; |
344 const MODE_INFO *const mi = mi_8x8; | 343 const MODE_INFO *const mi = mi_8x8[0]; |
345 const MODE_INFO *const above_mi = xd->above_mi; | 344 const MODE_INFO *const above_mi = xd->above_mi; |
346 const MODE_INFO *const left_mi = xd->left_mi; | 345 const MODE_INFO *const left_mi = xd->left_mi; |
347 const MB_MODE_INFO *const mbmi = &mi->mbmi; | 346 const MB_MODE_INFO *const mbmi = &mi->mbmi; |
348 const BLOCK_SIZE bsize = mbmi->sb_type; | 347 const BLOCK_SIZE bsize = mbmi->sb_type; |
349 | 348 |
350 if (seg->update_map) | 349 if (seg->update_map) |
351 write_segment_id(w, seg, mbmi->segment_id); | 350 write_segment_id(w, seg, mbmi->segment_id); |
352 | 351 |
353 write_skip(cm, xd, mbmi->segment_id, mi, w); | 352 write_skip(cm, xd, mbmi->segment_id, mi, w); |
354 | 353 |
(...skipping 20 matching lines...) Expand all Loading... |
375 } | 374 } |
376 | 375 |
377 static void write_modes_b(VP9_COMP *cpi, const TileInfo *const tile, | 376 static void write_modes_b(VP9_COMP *cpi, const TileInfo *const tile, |
378 vp9_writer *w, TOKENEXTRA **tok, | 377 vp9_writer *w, TOKENEXTRA **tok, |
379 const TOKENEXTRA *const tok_end, | 378 const TOKENEXTRA *const tok_end, |
380 int mi_row, int mi_col) { | 379 int mi_row, int mi_col) { |
381 const VP9_COMMON *const cm = &cpi->common; | 380 const VP9_COMMON *const cm = &cpi->common; |
382 MACROBLOCKD *const xd = &cpi->td.mb.e_mbd; | 381 MACROBLOCKD *const xd = &cpi->td.mb.e_mbd; |
383 MODE_INFO *m; | 382 MODE_INFO *m; |
384 | 383 |
385 xd->mi = cm->mi + (mi_row * cm->mi_stride + mi_col); | 384 xd->mi = cm->mi_grid_visible + (mi_row * cm->mi_stride + mi_col); |
386 m = xd->mi; | 385 m = xd->mi[0]; |
387 | 386 |
388 set_mi_row_col(xd, tile, | 387 set_mi_row_col(xd, tile, |
389 mi_row, num_8x8_blocks_high_lookup[m->mbmi.sb_type], | 388 mi_row, num_8x8_blocks_high_lookup[m->mbmi.sb_type], |
390 mi_col, num_8x8_blocks_wide_lookup[m->mbmi.sb_type], | 389 mi_col, num_8x8_blocks_wide_lookup[m->mbmi.sb_type], |
391 cm->mi_rows, cm->mi_cols); | 390 cm->mi_rows, cm->mi_cols); |
392 if (frame_is_intra_only(cm)) { | 391 if (frame_is_intra_only(cm)) { |
393 write_mb_modes_kf(cm, xd, xd->mi, w); | 392 write_mb_modes_kf(cm, xd, xd->mi, w); |
394 } else { | 393 } else { |
395 pack_inter_mode_mvs(cpi, m, w); | 394 pack_inter_mode_mvs(cpi, m, w); |
396 } | 395 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 | 429 |
431 const int bsl = b_width_log2_lookup[bsize]; | 430 const int bsl = b_width_log2_lookup[bsize]; |
432 const int bs = (1 << bsl) / 4; | 431 const int bs = (1 << bsl) / 4; |
433 PARTITION_TYPE partition; | 432 PARTITION_TYPE partition; |
434 BLOCK_SIZE subsize; | 433 BLOCK_SIZE subsize; |
435 const MODE_INFO *m = NULL; | 434 const MODE_INFO *m = NULL; |
436 | 435 |
437 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) | 436 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) |
438 return; | 437 return; |
439 | 438 |
440 m = cm->mi[mi_row * cm->mi_stride + mi_col].src_mi; | 439 m = cm->mi_grid_visible[mi_row * cm->mi_stride + mi_col]; |
441 | 440 |
442 partition = partition_lookup[bsl][m->mbmi.sb_type]; | 441 partition = partition_lookup[bsl][m->mbmi.sb_type]; |
443 write_partition(cm, xd, bs, mi_row, mi_col, partition, bsize, w); | 442 write_partition(cm, xd, bs, mi_row, mi_col, partition, bsize, w); |
444 subsize = get_subsize(bsize, partition); | 443 subsize = get_subsize(bsize, partition); |
445 if (subsize < BLOCK_8X8) { | 444 if (subsize < BLOCK_8X8) { |
446 write_modes_b(cpi, tile, w, tok, tok_end, mi_row, mi_col); | 445 write_modes_b(cpi, tile, w, tok, tok_end, mi_row, mi_col); |
447 } else { | 446 } else { |
448 switch (partition) { | 447 switch (partition) { |
449 case PARTITION_NONE: | 448 case PARTITION_NONE: |
450 write_modes_b(cpi, tile, w, tok, tok_end, mi_row, mi_col); | 449 write_modes_b(cpi, tile, w, tok, tok_end, mi_row, mi_col); |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
922 | 921 |
923 static size_t encode_tiles(VP9_COMP *cpi, uint8_t *data_ptr) { | 922 static size_t encode_tiles(VP9_COMP *cpi, uint8_t *data_ptr) { |
924 VP9_COMMON *const cm = &cpi->common; | 923 VP9_COMMON *const cm = &cpi->common; |
925 vp9_writer residual_bc; | 924 vp9_writer residual_bc; |
926 int tile_row, tile_col; | 925 int tile_row, tile_col; |
927 TOKENEXTRA *tok_end; | 926 TOKENEXTRA *tok_end; |
928 size_t total_size = 0; | 927 size_t total_size = 0; |
929 const int tile_cols = 1 << cm->log2_tile_cols; | 928 const int tile_cols = 1 << cm->log2_tile_cols; |
930 const int tile_rows = 1 << cm->log2_tile_rows; | 929 const int tile_rows = 1 << cm->log2_tile_rows; |
931 | 930 |
932 vpx_memset(cm->above_seg_context, 0, sizeof(*cm->above_seg_context) * | 931 memset(cm->above_seg_context, 0, |
933 mi_cols_aligned_to_sb(cm->mi_cols)); | 932 sizeof(*cm->above_seg_context) * mi_cols_aligned_to_sb(cm->mi_cols)); |
934 | 933 |
935 for (tile_row = 0; tile_row < tile_rows; tile_row++) { | 934 for (tile_row = 0; tile_row < tile_rows; tile_row++) { |
936 for (tile_col = 0; tile_col < tile_cols; tile_col++) { | 935 for (tile_col = 0; tile_col < tile_cols; tile_col++) { |
937 int tile_idx = tile_row * tile_cols + tile_col; | 936 int tile_idx = tile_row * tile_cols + tile_col; |
938 TOKENEXTRA *tok = cpi->tile_tok[tile_row][tile_col]; | 937 TOKENEXTRA *tok = cpi->tile_tok[tile_row][tile_col]; |
939 | 938 |
940 tok_end = cpi->tile_tok[tile_row][tile_col] + | 939 tok_end = cpi->tile_tok[tile_row][tile_col] + |
941 cpi->tok_count[tile_row][tile_col]; | 940 cpi->tok_count[tile_row][tile_col]; |
942 | 941 |
943 if (tile_col < tile_cols - 1 || tile_row < tile_rows - 1) | 942 if (tile_col < tile_cols - 1 || tile_row < tile_rows - 1) |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1238 | 1237 |
1239 first_part_size = write_compressed_header(cpi, data); | 1238 first_part_size = write_compressed_header(cpi, data); |
1240 data += first_part_size; | 1239 data += first_part_size; |
1241 // TODO(jbb): Figure out what to do if first_part_size > 16 bits. | 1240 // TODO(jbb): Figure out what to do if first_part_size > 16 bits. |
1242 vp9_wb_write_literal(&saved_wb, (int)first_part_size, 16); | 1241 vp9_wb_write_literal(&saved_wb, (int)first_part_size, 16); |
1243 | 1242 |
1244 data += encode_tiles(cpi, data); | 1243 data += encode_tiles(cpi, data); |
1245 | 1244 |
1246 *size = data - dest; | 1245 *size = data - dest; |
1247 } | 1246 } |
OLD | NEW |