Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1 | /* |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3 | * |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 4 | * This source code is subject to the terms of the BSD 2 Clause License and |
| 5 | * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
| 6 | * was not distributed with this source code in the LICENSE file, you can |
| 7 | * obtain it at www.aomedia.org/license/software. If the Alliance for Open |
| 8 | * Media Patent License 1.0 was not distributed with this source code in the |
| 9 | * PATENTS file, you can obtain it at www.aomedia.org/license/patent. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 12 | #ifndef AV1_COMMON_SCAN_H_ |
| 13 | #define AV1_COMMON_SCAN_H_ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 14 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 15 | #include "aom/aom_integer.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 16 | #include "aom_ports/mem.h" |
| 17 | |
| 18 | #include "av1/common/enums.h" |
Angie Chiang | 648aeb0 | 2016-10-20 11:20:40 -0700 | [diff] [blame] | 19 | #include "av1/common/onyxc_int.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 20 | #include "av1/common/blockd.h" |
| 21 | |
| 22 | #ifdef __cplusplus |
| 23 | extern "C" { |
| 24 | #endif |
| 25 | |
| 26 | #define MAX_NEIGHBORS 2 |
| 27 | |
Urvang Joshi | 03f6fdc | 2016-10-14 15:53:39 -0700 | [diff] [blame] | 28 | extern const SCAN_ORDER av1_default_scan_orders[TX_SIZES]; |
Urvang Joshi | feb925f | 2016-12-05 10:37:29 -0800 | [diff] [blame] | 29 | extern const SCAN_ORDER av1_intra_scan_orders[TX_SIZES_ALL][TX_TYPES]; |
Jingning Han | ec419e0 | 2016-11-01 18:19:30 -0700 | [diff] [blame] | 30 | extern const SCAN_ORDER av1_inter_scan_orders[TX_SIZES_ALL][TX_TYPES]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 31 | |
Angie Chiang | 648aeb0 | 2016-10-20 11:20:40 -0700 | [diff] [blame] | 32 | #if CONFIG_ADAPT_SCAN |
Jingning Han | 5d0b310 | 2017-02-12 10:45:50 -0800 | [diff] [blame] | 33 | void av1_update_scan_count_facade(AV1_COMMON *cm, FRAME_COUNTS *counts, |
| 34 | TX_SIZE tx_size, TX_TYPE tx_type, |
| 35 | const tran_low_t *dqcoeffs, int max_scan); |
Angie Chiang | 648aeb0 | 2016-10-20 11:20:40 -0700 | [diff] [blame] | 36 | |
| 37 | // embed r + c and coeff_idx info with nonzero probabilities. When sorting the |
| 38 | // nonzero probabilities, if there is a tie, the coefficient with smaller r + c |
| 39 | // will be scanned first |
Angie Chiang | fe2a959 | 2017-01-12 14:54:48 -0800 | [diff] [blame] | 40 | void av1_augment_prob(TX_SIZE tx_size, TX_TYPE tx_type, uint32_t *prob); |
Angie Chiang | 648aeb0 | 2016-10-20 11:20:40 -0700 | [diff] [blame] | 41 | |
| 42 | // apply quick sort on nonzero probabilities to obtain a sort order |
Angie Chiang | fe2a959 | 2017-01-12 14:54:48 -0800 | [diff] [blame] | 43 | void av1_update_sort_order(TX_SIZE tx_size, TX_TYPE tx_type, |
| 44 | const uint32_t *non_zero_prob, int16_t *sort_order); |
Angie Chiang | 648aeb0 | 2016-10-20 11:20:40 -0700 | [diff] [blame] | 45 | |
| 46 | // apply topological sort on the nonzero probabilities sorting order to |
| 47 | // guarantee each to-be-scanned coefficient's upper and left coefficient will be |
| 48 | // scanned before the to-be-scanned coefficient. |
| 49 | void av1_update_scan_order(TX_SIZE tx_size, int16_t *sort_order, int16_t *scan, |
| 50 | int16_t *iscan); |
| 51 | |
| 52 | // For each coeff_idx in scan[], update its above and left neighbors in |
| 53 | // neighbors[] accordingly. |
| 54 | void av1_update_neighbors(int tx_size, const int16_t *scan, |
| 55 | const int16_t *iscan, int16_t *neighbors); |
Angie Chiang | 648aeb0 | 2016-10-20 11:20:40 -0700 | [diff] [blame] | 56 | void av1_init_scan_order(AV1_COMMON *cm); |
hui su | ff0da2b | 2017-03-07 15:51:37 -0800 | [diff] [blame] | 57 | void av1_adapt_scan_order(AV1_COMMON *cm); |
Angie Chiang | 648aeb0 | 2016-10-20 11:20:40 -0700 | [diff] [blame] | 58 | #endif |
Yi Luo | f8e87b4 | 2017-04-14 17:20:27 -0700 | [diff] [blame] | 59 | void av1_deliver_eob_threshold(const AV1_COMMON *cm, MACROBLOCKD *xd); |
Angie Chiang | 648aeb0 | 2016-10-20 11:20:40 -0700 | [diff] [blame] | 60 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 61 | static INLINE int get_coef_context(const int16_t *neighbors, |
| 62 | const uint8_t *token_cache, int c) { |
| 63 | return (1 + token_cache[neighbors[MAX_NEIGHBORS * c + 0]] + |
| 64 | token_cache[neighbors[MAX_NEIGHBORS * c + 1]]) >> |
| 65 | 1; |
| 66 | } |
| 67 | |
Angie Chiang | fe2a959 | 2017-01-12 14:54:48 -0800 | [diff] [blame] | 68 | static INLINE const SCAN_ORDER *get_default_scan(TX_SIZE tx_size, |
| 69 | TX_TYPE tx_type, |
| 70 | int is_inter) { |
Jingning Han | ec419e0 | 2016-11-01 18:19:30 -0700 | [diff] [blame] | 71 | #if CONFIG_EXT_TX || CONFIG_VAR_TX |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 72 | return is_inter ? &av1_inter_scan_orders[tx_size][tx_type] |
| 73 | : &av1_intra_scan_orders[tx_size][tx_type]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 74 | #else |
| 75 | (void)is_inter; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 76 | return &av1_intra_scan_orders[tx_size][tx_type]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 77 | #endif // CONFIG_EXT_TX |
Angie Chiang | fe2a959 | 2017-01-12 14:54:48 -0800 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | static INLINE const SCAN_ORDER *get_scan(const AV1_COMMON *cm, TX_SIZE tx_size, |
Angie Chiang | bd99b38 | 2017-06-20 15:11:16 -0700 | [diff] [blame] | 81 | TX_TYPE tx_type, |
| 82 | const MB_MODE_INFO *mbmi) { |
Sarah Parker | 53f93db | 2017-07-11 17:20:04 -0700 | [diff] [blame] | 83 | #if CONFIG_MRC_TX |
| 84 | // use the DCT_DCT scan order for MRC_DCT for now |
| 85 | if (tx_type == MRC_DCT) tx_type = DCT_DCT; |
| 86 | #endif // CONFIG_MRC_TX |
Angie Chiang | d39f6b3 | 2017-07-24 13:28:27 -0700 | [diff] [blame] | 87 | const int is_inter = is_inter_block(mbmi); |
Angie Chiang | fe2a959 | 2017-01-12 14:54:48 -0800 | [diff] [blame] | 88 | #if CONFIG_ADAPT_SCAN |
Angie Chiang | bd99b38 | 2017-06-20 15:11:16 -0700 | [diff] [blame] | 89 | (void)mbmi; |
Angie Chiang | d39f6b3 | 2017-07-24 13:28:27 -0700 | [diff] [blame] | 90 | (void)is_inter; |
| 91 | #if CONFIG_EXT_TX |
| 92 | if (tx_type >= IDTX) |
| 93 | return get_default_scan(tx_size, tx_type, is_inter); |
| 94 | else |
| 95 | #endif // CONFIG_EXT_TX |
| 96 | return &cm->fc->sc[tx_size][tx_type]; |
Angie Chiang | fe2a959 | 2017-01-12 14:54:48 -0800 | [diff] [blame] | 97 | #else // CONFIG_ADAPT_SCAN |
| 98 | (void)cm; |
| 99 | return get_default_scan(tx_size, tx_type, is_inter); |
Angie Chiang | ed8cd9a | 2016-10-21 16:44:47 -0700 | [diff] [blame] | 100 | #endif // CONFIG_ADAPT_SCAN |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | #ifdef __cplusplus |
| 104 | } // extern "C" |
| 105 | #endif |
| 106 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 107 | #endif // AV1_COMMON_SCAN_H_ |