• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 6
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 
77 struct frame_contexts;
78 
79 typedef char ENTROPY_CONTEXT;
80 
combine_entropy_contexts(ENTROPY_CONTEXT a,ENTROPY_CONTEXT b)81 static INLINE int combine_entropy_contexts(ENTROPY_CONTEXT a,
82                                            ENTROPY_CONTEXT b) {
83   return (a != 0) + (b != 0);
84 }
85 
get_entropy_context(TX_SIZE tx_size,const ENTROPY_CONTEXT * a,const ENTROPY_CONTEXT * l)86 static INLINE int get_entropy_context(TX_SIZE tx_size, const ENTROPY_CONTEXT *a,
87                                       const ENTROPY_CONTEXT *l) {
88   ENTROPY_CONTEXT above_ec = 0, left_ec = 0;
89 
90   switch (tx_size) {
91     case TX_4X4:
92       above_ec = a[0] != 0;
93       left_ec = l[0] != 0;
94       break;
95     case TX_4X8:
96       above_ec = a[0] != 0;
97       left_ec = !!*(const uint16_t *)l;
98       break;
99     case TX_8X4:
100       above_ec = !!*(const uint16_t *)a;
101       left_ec = l[0] != 0;
102       break;
103     case TX_8X16:
104       above_ec = !!*(const uint16_t *)a;
105       left_ec = !!*(const uint32_t *)l;
106       break;
107     case TX_16X8:
108       above_ec = !!*(const uint32_t *)a;
109       left_ec = !!*(const uint16_t *)l;
110       break;
111     case TX_16X32:
112       above_ec = !!*(const uint32_t *)a;
113       left_ec = !!*(const uint64_t *)l;
114       break;
115     case TX_32X16:
116       above_ec = !!*(const uint64_t *)a;
117       left_ec = !!*(const uint32_t *)l;
118       break;
119     case TX_8X8:
120       above_ec = !!*(const uint16_t *)a;
121       left_ec = !!*(const uint16_t *)l;
122       break;
123     case TX_16X16:
124       above_ec = !!*(const uint32_t *)a;
125       left_ec = !!*(const uint32_t *)l;
126       break;
127     case TX_32X32:
128       above_ec = !!*(const uint64_t *)a;
129       left_ec = !!*(const uint64_t *)l;
130       break;
131     case TX_64X64:
132       above_ec = !!(*(const uint64_t *)a | *(const uint64_t *)(a + 8));
133       left_ec = !!(*(const uint64_t *)l | *(const uint64_t *)(l + 8));
134       break;
135     case TX_32X64:
136       above_ec = !!*(const uint64_t *)a;
137       left_ec = !!(*(const uint64_t *)l | *(const uint64_t *)(l + 8));
138       break;
139     case TX_64X32:
140       above_ec = !!(*(const uint64_t *)a | *(const uint64_t *)(a + 8));
141       left_ec = !!*(const uint64_t *)l;
142       break;
143     case TX_4X16:
144       above_ec = a[0] != 0;
145       left_ec = !!*(const uint32_t *)l;
146       break;
147     case TX_16X4:
148       above_ec = !!*(const uint32_t *)a;
149       left_ec = l[0] != 0;
150       break;
151     case TX_8X32:
152       above_ec = !!*(const uint16_t *)a;
153       left_ec = !!*(const uint64_t *)l;
154       break;
155     case TX_32X8:
156       above_ec = !!*(const uint64_t *)a;
157       left_ec = !!*(const uint16_t *)l;
158       break;
159     case TX_16X64:
160       above_ec = !!*(const uint32_t *)a;
161       left_ec = !!(*(const uint64_t *)l | *(const uint64_t *)(l + 8));
162       break;
163     case TX_64X16:
164       above_ec = !!(*(const uint64_t *)a | *(const uint64_t *)(a + 8));
165       left_ec = !!*(const uint32_t *)l;
166       break;
167     default: assert(0 && "Invalid transform size."); break;
168   }
169   return combine_entropy_contexts(above_ec, left_ec);
170 }
171 
get_txsize_entropy_ctx(TX_SIZE txsize)172 static INLINE TX_SIZE get_txsize_entropy_ctx(TX_SIZE txsize) {
173   return (TX_SIZE)((txsize_sqr_map[txsize] + txsize_sqr_up_map[txsize] + 1) >>
174                    1);
175 }
176 
177 #ifdef __cplusplus
178 }  // extern "C"
179 #endif
180 
181 #endif  // AOM_AV1_COMMON_ENTROPY_H_
182