1 /* 2 * Copyright (c) 2013 The WebM project authors. All Rights Reserved. 3 * 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 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef VP9_COMMON_VP9_SCAN_H_ 12 #define VP9_COMMON_VP9_SCAN_H_ 13 14 #include "vpx/vpx_integer.h" 15 #include "vpx_ports/mem.h" 16 17 #include "vp9/common/vp9_enums.h" 18 19 #define MAX_NEIGHBORS 2 20 21 extern DECLARE_ALIGNED(16, const int16_t, vp9_default_scan_4x4[16]); 22 extern DECLARE_ALIGNED(16, const int16_t, vp9_col_scan_4x4[16]); 23 extern DECLARE_ALIGNED(16, const int16_t, vp9_row_scan_4x4[16]); 24 25 extern DECLARE_ALIGNED(16, const int16_t, vp9_default_scan_8x8[64]); 26 extern DECLARE_ALIGNED(16, const int16_t, vp9_col_scan_8x8[64]); 27 extern DECLARE_ALIGNED(16, const int16_t, vp9_row_scan_8x8[64]); 28 29 extern DECLARE_ALIGNED(16, const int16_t, vp9_default_scan_16x16[256]); 30 extern DECLARE_ALIGNED(16, const int16_t, vp9_col_scan_16x16[256]); 31 extern DECLARE_ALIGNED(16, const int16_t, vp9_row_scan_16x16[256]); 32 33 extern DECLARE_ALIGNED(16, const int16_t, vp9_default_scan_32x32[1024]); 34 35 extern DECLARE_ALIGNED(16, int16_t, vp9_default_iscan_4x4[16]); 36 extern DECLARE_ALIGNED(16, int16_t, vp9_col_iscan_4x4[16]); 37 extern DECLARE_ALIGNED(16, int16_t, vp9_row_iscan_4x4[16]); 38 39 extern DECLARE_ALIGNED(16, int16_t, vp9_default_iscan_8x8[64]); 40 extern DECLARE_ALIGNED(16, int16_t, vp9_col_iscan_8x8[64]); 41 extern DECLARE_ALIGNED(16, int16_t, vp9_row_iscan_8x8[64]); 42 43 extern DECLARE_ALIGNED(16, int16_t, vp9_default_iscan_16x16[256]); 44 extern DECLARE_ALIGNED(16, int16_t, vp9_col_iscan_16x16[256]); 45 extern DECLARE_ALIGNED(16, int16_t, vp9_row_iscan_16x16[256]); 46 47 extern DECLARE_ALIGNED(16, int16_t, vp9_default_iscan_32x32[1024]); 48 49 extern DECLARE_ALIGNED(16, int16_t, 50 vp9_default_scan_4x4_neighbors[17 * MAX_NEIGHBORS]); 51 extern DECLARE_ALIGNED(16, int16_t, 52 vp9_col_scan_4x4_neighbors[17 * MAX_NEIGHBORS]); 53 extern DECLARE_ALIGNED(16, int16_t, 54 vp9_row_scan_4x4_neighbors[17 * MAX_NEIGHBORS]); 55 extern DECLARE_ALIGNED(16, int16_t, 56 vp9_col_scan_8x8_neighbors[65 * MAX_NEIGHBORS]); 57 extern DECLARE_ALIGNED(16, int16_t, 58 vp9_row_scan_8x8_neighbors[65 * MAX_NEIGHBORS]); 59 extern DECLARE_ALIGNED(16, int16_t, 60 vp9_default_scan_8x8_neighbors[65 * MAX_NEIGHBORS]); 61 extern DECLARE_ALIGNED(16, int16_t, 62 vp9_col_scan_16x16_neighbors[257 * MAX_NEIGHBORS]); 63 extern DECLARE_ALIGNED(16, int16_t, 64 vp9_row_scan_16x16_neighbors[257 * MAX_NEIGHBORS]); 65 extern DECLARE_ALIGNED(16, int16_t, 66 vp9_default_scan_16x16_neighbors[257 * MAX_NEIGHBORS]); 67 extern DECLARE_ALIGNED(16, int16_t, 68 vp9_default_scan_32x32_neighbors[1025 * MAX_NEIGHBORS]); 69 70 71 void vp9_init_neighbors(); 72 73 static INLINE const int16_t* get_scan_4x4(TX_TYPE tx_type) { 74 switch (tx_type) { 75 case ADST_DCT: 76 return vp9_row_scan_4x4; 77 case DCT_ADST: 78 return vp9_col_scan_4x4; 79 default: 80 return vp9_default_scan_4x4; 81 } 82 } 83 84 static INLINE void get_scan_nb_4x4(TX_TYPE tx_type, 85 const int16_t **scan, const int16_t **nb) { 86 switch (tx_type) { 87 case ADST_DCT: 88 *scan = vp9_row_scan_4x4; 89 *nb = vp9_row_scan_4x4_neighbors; 90 break; 91 case DCT_ADST: 92 *scan = vp9_col_scan_4x4; 93 *nb = vp9_col_scan_4x4_neighbors; 94 break; 95 default: 96 *scan = vp9_default_scan_4x4; 97 *nb = vp9_default_scan_4x4_neighbors; 98 break; 99 } 100 } 101 102 static INLINE const int16_t* get_iscan_4x4(TX_TYPE tx_type) { 103 switch (tx_type) { 104 case ADST_DCT: 105 return vp9_row_iscan_4x4; 106 case DCT_ADST: 107 return vp9_col_iscan_4x4; 108 default: 109 return vp9_default_iscan_4x4; 110 } 111 } 112 113 static INLINE const int16_t* get_scan_8x8(TX_TYPE tx_type) { 114 switch (tx_type) { 115 case ADST_DCT: 116 return vp9_row_scan_8x8; 117 case DCT_ADST: 118 return vp9_col_scan_8x8; 119 default: 120 return vp9_default_scan_8x8; 121 } 122 } 123 124 static INLINE void get_scan_nb_8x8(TX_TYPE tx_type, 125 const int16_t **scan, const int16_t **nb) { 126 switch (tx_type) { 127 case ADST_DCT: 128 *scan = vp9_row_scan_8x8; 129 *nb = vp9_row_scan_8x8_neighbors; 130 break; 131 case DCT_ADST: 132 *scan = vp9_col_scan_8x8; 133 *nb = vp9_col_scan_8x8_neighbors; 134 break; 135 default: 136 *scan = vp9_default_scan_8x8; 137 *nb = vp9_default_scan_8x8_neighbors; 138 break; 139 } 140 } 141 142 static INLINE const int16_t* get_iscan_8x8(TX_TYPE tx_type) { 143 switch (tx_type) { 144 case ADST_DCT: 145 return vp9_row_iscan_8x8; 146 case DCT_ADST: 147 return vp9_col_iscan_8x8; 148 default: 149 return vp9_default_iscan_8x8; 150 } 151 } 152 153 static INLINE const int16_t* get_scan_16x16(TX_TYPE tx_type) { 154 switch (tx_type) { 155 case ADST_DCT: 156 return vp9_row_scan_16x16; 157 case DCT_ADST: 158 return vp9_col_scan_16x16; 159 default: 160 return vp9_default_scan_16x16; 161 } 162 } 163 164 static INLINE void get_scan_nb_16x16(TX_TYPE tx_type, 165 const int16_t **scan, const int16_t **nb) { 166 switch (tx_type) { 167 case ADST_DCT: 168 *scan = vp9_row_scan_16x16; 169 *nb = vp9_row_scan_16x16_neighbors; 170 break; 171 case DCT_ADST: 172 *scan = vp9_col_scan_16x16; 173 *nb = vp9_col_scan_16x16_neighbors; 174 break; 175 default: 176 *scan = vp9_default_scan_16x16; 177 *nb = vp9_default_scan_16x16_neighbors; 178 break; 179 } 180 } 181 182 static INLINE const int16_t* get_iscan_16x16(TX_TYPE tx_type) { 183 switch (tx_type) { 184 case ADST_DCT: 185 return vp9_row_iscan_16x16; 186 case DCT_ADST: 187 return vp9_col_iscan_16x16; 188 default: 189 return vp9_default_iscan_16x16; 190 } 191 } 192 193 static INLINE int get_coef_context(const int16_t *neighbors, 194 const uint8_t *token_cache, int c) { 195 return (1 + token_cache[neighbors[MAX_NEIGHBORS * c + 0]] + 196 token_cache[neighbors[MAX_NEIGHBORS * c + 1]]) >> 1; 197 } 198 199 #endif // VP9_COMMON_VP9_SCAN_H_ 200