entropy.h (5154B)
1 /* 2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved. 3 * 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. 10 */ 11 12 #ifndef AOM_AV1_COMMON_ENTROPY_H_ 13 #define AOM_AV1_COMMON_ENTROPY_H_ 14 15 #include "config/aom_config.h" 16 17 #include "aom/aom_integer.h" 18 #include "aom_dsp/prob.h" 19 20 #include "av1/common/common.h" 21 #include "av1/common/common_data.h" 22 #include "av1/common/enums.h" 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 #define TOKEN_CDF_Q_CTXS 4 29 30 #define TXB_SKIP_CONTEXTS 13 31 32 #define EOB_COEF_CONTEXTS 9 33 34 #define SIG_COEF_CONTEXTS_2D 26 35 #define SIG_COEF_CONTEXTS_1D 16 36 #define SIG_COEF_CONTEXTS_EOB 4 37 #define SIG_COEF_CONTEXTS (SIG_COEF_CONTEXTS_2D + SIG_COEF_CONTEXTS_1D) 38 39 #define COEFF_BASE_CONTEXTS (SIG_COEF_CONTEXTS) 40 #define DC_SIGN_CONTEXTS 3 41 42 #define BR_TMP_OFFSET 12 43 #define BR_REF_CAT 4 44 #define LEVEL_CONTEXTS 21 45 46 #define NUM_BASE_LEVELS 2 47 48 #define BR_CDF_SIZE (4) 49 #define COEFF_BASE_RANGE (4 * (BR_CDF_SIZE - 1)) 50 51 #define COEFF_CONTEXT_BITS 3 52 #define COEFF_CONTEXT_MASK ((1 << COEFF_CONTEXT_BITS) - 1) 53 #define MAX_BASE_BR_RANGE (COEFF_BASE_RANGE + NUM_BASE_LEVELS + 1) 54 55 #define BASE_CONTEXT_POSITION_NUM 12 56 57 enum { 58 TX_CLASS_2D = 0, 59 TX_CLASS_HORIZ = 1, 60 TX_CLASS_VERT = 2, 61 TX_CLASSES = 3, 62 } UENUM1BYTE(TX_CLASS); 63 64 #define DCT_MAX_VALUE 16384 65 #define DCT_MAX_VALUE_HIGH10 65536 66 #define DCT_MAX_VALUE_HIGH12 262144 67 68 /* Coefficients are predicted via a 3-dimensional probability table indexed on 69 * REF_TYPES, COEF_BANDS and COEF_CONTEXTS. */ 70 #define REF_TYPES 2 // intra=0, inter=1 71 72 struct AV1Common; 73 struct frame_contexts; 74 void av1_reset_cdf_symbol_counters(struct frame_contexts *fc); 75 void av1_default_coef_probs(struct AV1Common *cm); 76 void av1_init_mode_probs(struct frame_contexts *fc); 77 78 struct frame_contexts; 79 80 typedef char ENTROPY_CONTEXT; 81 82 static inline int combine_entropy_contexts(ENTROPY_CONTEXT a, 83 ENTROPY_CONTEXT b) { 84 return (a != 0) + (b != 0); 85 } 86 87 static inline int get_entropy_context(TX_SIZE tx_size, const ENTROPY_CONTEXT *a, 88 const ENTROPY_CONTEXT *l) { 89 ENTROPY_CONTEXT above_ec = 0, left_ec = 0; 90 91 switch (tx_size) { 92 case TX_4X4: 93 above_ec = a[0] != 0; 94 left_ec = l[0] != 0; 95 break; 96 case TX_4X8: 97 above_ec = a[0] != 0; 98 left_ec = !!*(const uint16_t *)l; 99 break; 100 case TX_8X4: 101 above_ec = !!*(const uint16_t *)a; 102 left_ec = l[0] != 0; 103 break; 104 case TX_8X16: 105 above_ec = !!*(const uint16_t *)a; 106 left_ec = !!*(const uint32_t *)l; 107 break; 108 case TX_16X8: 109 above_ec = !!*(const uint32_t *)a; 110 left_ec = !!*(const uint16_t *)l; 111 break; 112 case TX_16X32: 113 above_ec = !!*(const uint32_t *)a; 114 left_ec = !!*(const uint64_t *)l; 115 break; 116 case TX_32X16: 117 above_ec = !!*(const uint64_t *)a; 118 left_ec = !!*(const uint32_t *)l; 119 break; 120 case TX_8X8: 121 above_ec = !!*(const uint16_t *)a; 122 left_ec = !!*(const uint16_t *)l; 123 break; 124 case TX_16X16: 125 above_ec = !!*(const uint32_t *)a; 126 left_ec = !!*(const uint32_t *)l; 127 break; 128 case TX_32X32: 129 above_ec = !!*(const uint64_t *)a; 130 left_ec = !!*(const uint64_t *)l; 131 break; 132 case TX_64X64: 133 above_ec = !!(*(const uint64_t *)a | *(const uint64_t *)(a + 8)); 134 left_ec = !!(*(const uint64_t *)l | *(const uint64_t *)(l + 8)); 135 break; 136 case TX_32X64: 137 above_ec = !!*(const uint64_t *)a; 138 left_ec = !!(*(const uint64_t *)l | *(const uint64_t *)(l + 8)); 139 break; 140 case TX_64X32: 141 above_ec = !!(*(const uint64_t *)a | *(const uint64_t *)(a + 8)); 142 left_ec = !!*(const uint64_t *)l; 143 break; 144 case TX_4X16: 145 above_ec = a[0] != 0; 146 left_ec = !!*(const uint32_t *)l; 147 break; 148 case TX_16X4: 149 above_ec = !!*(const uint32_t *)a; 150 left_ec = l[0] != 0; 151 break; 152 case TX_8X32: 153 above_ec = !!*(const uint16_t *)a; 154 left_ec = !!*(const uint64_t *)l; 155 break; 156 case TX_32X8: 157 above_ec = !!*(const uint64_t *)a; 158 left_ec = !!*(const uint16_t *)l; 159 break; 160 case TX_16X64: 161 above_ec = !!*(const uint32_t *)a; 162 left_ec = !!(*(const uint64_t *)l | *(const uint64_t *)(l + 8)); 163 break; 164 case TX_64X16: 165 above_ec = !!(*(const uint64_t *)a | *(const uint64_t *)(a + 8)); 166 left_ec = !!*(const uint32_t *)l; 167 break; 168 default: assert(0 && "Invalid transform size."); break; 169 } 170 return combine_entropy_contexts(above_ec, left_ec); 171 } 172 173 static inline TX_SIZE get_txsize_entropy_ctx(TX_SIZE txsize) { 174 return (TX_SIZE)((txsize_sqr_map[txsize] + txsize_sqr_up_map[txsize] + 1) >> 175 1); 176 } 177 178 #ifdef __cplusplus 179 } // extern "C" 180 #endif 181 182 #endif // AOM_AV1_COMMON_ENTROPY_H_