blob: c9911de4ee62c2a9f28e329a81b08758b4cfffcc [file] [log] [blame]
Yaowu Xuc27fc142016-08-22 16:08:15 -07001/*
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Yaowu Xuc27fc142016-08-22 16:08:15 -07003 *
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07004 * 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 Xuc27fc142016-08-22 16:08:15 -070010 */
11
Yaowu Xuf883b422016-08-30 14:01:10 -070012#ifndef AV1_COMMON_SCAN_H_
13#define AV1_COMMON_SCAN_H_
Yaowu Xuc27fc142016-08-22 16:08:15 -070014
Yaowu Xuf883b422016-08-30 14:01:10 -070015#include "aom/aom_integer.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070016#include "aom_ports/mem.h"
17
18#include "av1/common/enums.h"
Angie Chiang648aeb02016-10-20 11:20:40 -070019#include "av1/common/onyxc_int.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070020#include "av1/common/blockd.h"
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26#define MAX_NEIGHBORS 2
27
Urvang Joshi03f6fdc2016-10-14 15:53:39 -070028extern const SCAN_ORDER av1_default_scan_orders[TX_SIZES];
Urvang Joshifeb925f2016-12-05 10:37:29 -080029extern const SCAN_ORDER av1_intra_scan_orders[TX_SIZES_ALL][TX_TYPES];
Jingning Hanec419e02016-11-01 18:19:30 -070030extern const SCAN_ORDER av1_inter_scan_orders[TX_SIZES_ALL][TX_TYPES];
Yaowu Xuc27fc142016-08-22 16:08:15 -070031
Angie Chiang648aeb02016-10-20 11:20:40 -070032#if CONFIG_ADAPT_SCAN
Jingning Han5d0b3102017-02-12 10:45:50 -080033void 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 Chiang648aeb02016-10-20 11:20:40 -070036
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 Chiangfe2a9592017-01-12 14:54:48 -080040void av1_augment_prob(TX_SIZE tx_size, TX_TYPE tx_type, uint32_t *prob);
Angie Chiang648aeb02016-10-20 11:20:40 -070041
42// apply quick sort on nonzero probabilities to obtain a sort order
Angie Chiangfe2a9592017-01-12 14:54:48 -080043void av1_update_sort_order(TX_SIZE tx_size, TX_TYPE tx_type,
44 const uint32_t *non_zero_prob, int16_t *sort_order);
Angie Chiang648aeb02016-10-20 11:20:40 -070045
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.
49void 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.
54void av1_update_neighbors(int tx_size, const int16_t *scan,
55 const int16_t *iscan, int16_t *neighbors);
Angie Chiang648aeb02016-10-20 11:20:40 -070056void av1_init_scan_order(AV1_COMMON *cm);
hui suff0da2b2017-03-07 15:51:37 -080057void av1_adapt_scan_order(AV1_COMMON *cm);
Angie Chiang648aeb02016-10-20 11:20:40 -070058#endif
Yi Luof8e87b42017-04-14 17:20:27 -070059void av1_deliver_eob_threshold(const AV1_COMMON *cm, MACROBLOCKD *xd);
Angie Chiang648aeb02016-10-20 11:20:40 -070060
Yaowu Xuc27fc142016-08-22 16:08:15 -070061static 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 Chiangfe2a9592017-01-12 14:54:48 -080068static INLINE const SCAN_ORDER *get_default_scan(TX_SIZE tx_size,
69 TX_TYPE tx_type,
70 int is_inter) {
Jingning Hanec419e02016-11-01 18:19:30 -070071#if CONFIG_EXT_TX || CONFIG_VAR_TX
Yaowu Xuf883b422016-08-30 14:01:10 -070072 return is_inter ? &av1_inter_scan_orders[tx_size][tx_type]
73 : &av1_intra_scan_orders[tx_size][tx_type];
Yaowu Xuc27fc142016-08-22 16:08:15 -070074#else
75 (void)is_inter;
Yaowu Xuf883b422016-08-30 14:01:10 -070076 return &av1_intra_scan_orders[tx_size][tx_type];
Yaowu Xuc27fc142016-08-22 16:08:15 -070077#endif // CONFIG_EXT_TX
Angie Chiangfe2a9592017-01-12 14:54:48 -080078}
79
80static INLINE const SCAN_ORDER *get_scan(const AV1_COMMON *cm, TX_SIZE tx_size,
Angie Chiangbd99b382017-06-20 15:11:16 -070081 TX_TYPE tx_type,
82 const MB_MODE_INFO *mbmi) {
Sarah Parker53f93db2017-07-11 17:20:04 -070083#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 Chiangd39f6b32017-07-24 13:28:27 -070087 const int is_inter = is_inter_block(mbmi);
Angie Chiangfe2a9592017-01-12 14:54:48 -080088#if CONFIG_ADAPT_SCAN
Angie Chiangbd99b382017-06-20 15:11:16 -070089 (void)mbmi;
Angie Chiangd39f6b32017-07-24 13:28:27 -070090 (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 Chiangfe2a9592017-01-12 14:54:48 -080097#else // CONFIG_ADAPT_SCAN
98 (void)cm;
99 return get_default_scan(tx_size, tx_type, is_inter);
Angie Chianged8cd9a2016-10-21 16:44:47 -0700100#endif // CONFIG_ADAPT_SCAN
Yaowu Xuc27fc142016-08-22 16:08:15 -0700101}
102
103#ifdef __cplusplus
104} // extern "C"
105#endif
106
Yaowu Xuf883b422016-08-30 14:01:10 -0700107#endif // AV1_COMMON_SCAN_H_