Line data Source code
1 : /*
2 : * Copyright(c) 2019 Netflix, Inc.
3 : * SPDX - License - Identifier: BSD - 2 - Clause - Patent
4 : */
5 :
6 : #ifndef EbCommonUtils_h
7 : #define EbCommonUtils_h
8 :
9 : #include "EbCodingUnit.h"
10 : #include "EbDefinitions.h"
11 :
12 : #define MAX_OFFSET_WIDTH 64
13 : #define MAX_OFFSET_HEIGHT 0
14 :
15 : static const int16_t eb_k_eob_group_start[12] = { 0, 1, 2, 3, 5, 9, 17, 33, 65, 129, 257, 513 };
16 : static const int16_t eb_k_eob_offset_bits[12] = { 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
17 :
18 : static const PredictionMode fimode_to_intradir[FILTER_INTRA_MODES] = {
19 : DC_PRED, V_PRED, H_PRED, D157_PRED, DC_PRED
20 : };
21 :
22 78877567 : static INLINE uint8_t *set_levels(uint8_t *const levels_buf, const int32_t width) {
23 78877567 : return levels_buf + TX_PAD_TOP * (width + TX_PAD_HOR);
24 : }
25 :
26 1173667506 : static INLINE int get_padded_idx(const int idx, const int bwl) {
27 1173667506 : return idx + ((idx >> bwl) << TX_PAD_HOR_LOG2);
28 : }
29 :
30 116484485 : static INLINE int get_txb_bwl(TxSize tx_size) {
31 116484485 : tx_size = av1_get_adjusted_tx_size(tx_size);
32 116473285 : return tx_size_wide_log2[tx_size];
33 : }
34 :
35 116449885 : static INLINE int get_txb_wide(TxSize tx_size) {
36 116449885 : tx_size = av1_get_adjusted_tx_size(tx_size);
37 116413485 : return tx_size_wide[tx_size];
38 : }
39 :
40 116404185 : static INLINE int get_txb_high(TxSize tx_size) {
41 116404185 : tx_size = av1_get_adjusted_tx_size(tx_size);
42 116365185 : return tx_size_high[tx_size];
43 : }
44 :
45 771735 : static INLINE PredictionMode get_uv_mode(UvPredictionMode mode) {
46 9377 : assert(mode < UV_INTRA_MODES);
47 : static const PredictionMode uv2y[] = {
48 : DC_PRED, // UV_DC_PRED
49 : V_PRED, // UV_V_PRED
50 : H_PRED, // UV_H_PRED
51 : D45_PRED, // UV_D45_PRED
52 : D135_PRED, // UV_D135_PRED
53 : D113_PRED, // UV_D113_PRED
54 : D157_PRED, // UV_D157_PRED
55 : D203_PRED, // UV_D203_PRED
56 : D67_PRED, // UV_D67_PRED
57 : SMOOTH_PRED, // UV_SMOOTH_PRED
58 : SMOOTH_V_PRED, // UV_SMOOTH_V_PRED
59 : SMOOTH_H_PRED, // UV_SMOOTH_H_PRED
60 : PAETH_PRED, // UV_PAETH_PRED
61 : DC_PRED, // UV_CFL_PRED
62 : INTRA_INVALID, // UV_INTRA_MODES
63 : INTRA_INVALID, // UV_MODE_INVALID
64 : };
65 771735 : return uv2y[mode];
66 : }
67 :
68 763856 : static INLINE TxType intra_mode_to_tx_type(const BlockModeInfo *mbmi, PlaneType plane_type) {
69 : static const TxType _intra_mode_to_tx_type[INTRA_MODES] = {
70 : DCT_DCT, // DC
71 : ADST_DCT, // V
72 : DCT_ADST, // H
73 : DCT_DCT, // D45
74 : ADST_ADST, // D135
75 : ADST_DCT, // D117
76 : DCT_ADST, // D153
77 : DCT_ADST, // D207
78 : ADST_DCT, // D63
79 : ADST_ADST, // SMOOTH
80 : ADST_DCT, // SMOOTH_V
81 : DCT_ADST, // SMOOTH_H
82 : ADST_ADST, // PAETH
83 : };
84 763901 : const PredictionMode mode =
85 763856 : (plane_type == PLANE_TYPE_Y) ? mbmi->mode : get_uv_mode(mbmi->uv_mode);
86 1511 : assert(mode < INTRA_MODES);
87 763901 : return _intra_mode_to_tx_type[mode];
88 : }
89 :
90 0 : static INLINE int get_segdata(SegmentationParams *seg, int segment_id,
91 : SEG_LVL_FEATURES feature_id)
92 : {
93 0 : return seg->feature_data[segment_id][feature_id];
94 : }
95 :
96 : static AOM_FORCE_INLINE int get_br_ctx_eob(const int c, // raster order
97 : const int bwl, const TxClass tx_class)
98 : {
99 2971318 : const int row = c >> bwl;
100 2971318 : const int col = c - (row << bwl);
101 2971318 : if (c == 0) return 0;
102 1913299 : if ((tx_class == TX_CLASS_2D && row < 2 && col < 2) ||
103 1498696 : (tx_class == TX_CLASS_HORIZ && col == 0) ||
104 141555 : (tx_class == TX_CLASS_VERT && row == 0))
105 557163 : return 7;
106 1356144 : return 14;
107 : }
108 :
109 143235683 : static INLINE int32_t get_br_ctx(const uint8_t *const levels,
110 : const int32_t c, // raster order
111 : const int32_t bwl, const TxType tx_type)
112 : {
113 143235683 : const int32_t row = c >> bwl;
114 143235683 : const int32_t col = c - (row << bwl);
115 143235683 : const int32_t stride = (1 << bwl) + TX_PAD_HOR;
116 143235683 : const TxClass tx_class = tx_type_to_class[tx_type];
117 143235683 : const int32_t pos = row * stride + col;
118 143235683 : int32_t mag = levels[pos + 1];
119 143235683 : mag += levels[pos + stride];
120 143235683 : switch (tx_class) {
121 134522444 : case TX_CLASS_2D:
122 134522444 : mag += levels[pos + stride + 1];
123 134522444 : mag = AOMMIN((mag + 1) >> 1, 6);
124 134522444 : if (c == 0) return mag;
125 111412800 : if ((row < 2) && (col < 2)) return mag + 7;
126 90320900 : break;
127 4544700 : case TX_CLASS_HORIZ:
128 4544700 : mag += levels[pos + 2];
129 4544700 : mag = AOMMIN((mag + 1) >> 1, 6);
130 4544700 : if (c == 0) return mag;
131 4138520 : if (col == 0) return mag + 7;
132 1889687 : break;
133 4281569 : case TX_CLASS_VERT:
134 4281569 : mag += levels[pos + (stride << 1)];
135 4281569 : mag = AOMMIN((mag + 1) >> 1, 6);
136 4281569 : if (c == 0) return mag;
137 3972308 : if (row == 0) return mag + 7;
138 1979379 : break;
139 0 : default: break;
140 : }
141 :
142 94077006 : return mag + 14;
143 : }
144 :
145 112861342 : static INLINE int get_lower_levels_ctx_eob(int bwl, int height, int scan_idx) {
146 112861342 : if (scan_idx == 0) return 0;
147 103061757 : if (scan_idx <= (height << bwl) / 8) return 1;
148 84909776 : if (scan_idx <= (height << bwl) / 4) return 2;
149 69594847 : return 3;
150 : }
151 :
152 239867692 : static INLINE int32_t is_chroma_reference(int32_t mi_row, int32_t mi_col, BlockSize bsize,
153 : int32_t subsampling_x, int32_t subsampling_y)
154 : {
155 239867692 : const int32_t bw = mi_size_wide[bsize];
156 239867692 : const int32_t bh = mi_size_high[bsize];
157 479729118 : int32_t ref_pos = ((mi_row & 0x01) || !(bh & 0x01) || !subsampling_y) &&
158 239860426 : ((mi_col & 0x01) || !(bw & 0x01) || !subsampling_x);
159 239867692 : return ref_pos;
160 : }
161 : #endif//EbCommonUtils_h
|