/src/aom/av1/common/entropy.c
Line | Count | Source |
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 | | #include "config/aom_config.h" |
13 | | |
14 | | #include "aom/aom_integer.h" |
15 | | #include "aom_mem/aom_mem.h" |
16 | | #include "av1/common/av1_common_int.h" |
17 | | #include "av1/common/blockd.h" |
18 | | #include "av1/common/entropy.h" |
19 | | #include "av1/common/entropymode.h" |
20 | | #include "av1/common/scan.h" |
21 | | #include "av1/common/token_cdfs.h" |
22 | | #include "av1/common/txb_common.h" |
23 | | |
24 | 3.24k | static int get_q_ctx(int q) { |
25 | 3.24k | if (q <= 20) return 0; |
26 | 2.92k | if (q <= 60) return 1; |
27 | 2.83k | if (q <= 120) return 2; |
28 | 2.64k | return 3; |
29 | 2.83k | } |
30 | | |
31 | 3.24k | void av1_default_coef_probs(AV1_COMMON *cm) { |
32 | 3.24k | const int index = get_q_ctx(cm->quant_params.base_qindex); |
33 | | #if CONFIG_ENTROPY_STATS |
34 | | cm->coef_cdf_category = index; |
35 | | #endif |
36 | | |
37 | 3.24k | av1_copy(cm->fc->txb_skip_cdf, av1_default_txb_skip_cdfs[index]); |
38 | 3.24k | av1_copy(cm->fc->eob_extra_cdf, av1_default_eob_extra_cdfs[index]); |
39 | 3.24k | av1_copy(cm->fc->dc_sign_cdf, av1_default_dc_sign_cdfs[index]); |
40 | 3.24k | av1_copy(cm->fc->coeff_br_cdf, av1_default_coeff_lps_multi_cdfs[index]); |
41 | 3.24k | av1_copy(cm->fc->coeff_base_cdf, av1_default_coeff_base_multi_cdfs[index]); |
42 | 3.24k | av1_copy(cm->fc->coeff_base_eob_cdf, |
43 | 3.24k | av1_default_coeff_base_eob_multi_cdfs[index]); |
44 | 3.24k | av1_copy(cm->fc->eob_flag_cdf16, av1_default_eob_multi16_cdfs[index]); |
45 | 3.24k | av1_copy(cm->fc->eob_flag_cdf32, av1_default_eob_multi32_cdfs[index]); |
46 | 3.24k | av1_copy(cm->fc->eob_flag_cdf64, av1_default_eob_multi64_cdfs[index]); |
47 | 3.24k | av1_copy(cm->fc->eob_flag_cdf128, av1_default_eob_multi128_cdfs[index]); |
48 | 3.24k | av1_copy(cm->fc->eob_flag_cdf256, av1_default_eob_multi256_cdfs[index]); |
49 | 3.24k | av1_copy(cm->fc->eob_flag_cdf512, av1_default_eob_multi512_cdfs[index]); |
50 | 3.24k | av1_copy(cm->fc->eob_flag_cdf1024, av1_default_eob_multi1024_cdfs[index]); |
51 | 3.24k | } |
52 | | |
53 | | static AOM_INLINE void reset_cdf_symbol_counter(aom_cdf_prob *cdf_ptr, |
54 | | int num_cdfs, int cdf_stride, |
55 | 177k | int nsymbs) { |
56 | 2.13M | for (int i = 0; i < num_cdfs; i++) { |
57 | 1.95M | cdf_ptr[i * cdf_stride + nsymbs] = 0; |
58 | 1.95M | } |
59 | 177k | } |
60 | | |
61 | | #define RESET_CDF_COUNTER(cname, nsymbs) \ |
62 | 141k | RESET_CDF_COUNTER_STRIDE(cname, nsymbs, CDF_SIZE(nsymbs)) |
63 | | |
64 | | #define RESET_CDF_COUNTER_STRIDE(cname, nsymbs, cdf_stride) \ |
65 | 177k | do { \ |
66 | 177k | aom_cdf_prob *cdf_ptr = (aom_cdf_prob *)cname; \ |
67 | 177k | int array_size = (int)sizeof(cname) / sizeof(aom_cdf_prob); \ |
68 | 177k | int num_cdfs = array_size / cdf_stride; \ |
69 | 177k | reset_cdf_symbol_counter(cdf_ptr, num_cdfs, cdf_stride, nsymbs); \ |
70 | 177k | } while (0) |
71 | | |
72 | 2.52k | static AOM_INLINE void reset_nmv_counter(nmv_context *nmv) { |
73 | 2.52k | RESET_CDF_COUNTER(nmv->joints_cdf, 4); |
74 | 7.57k | for (int i = 0; i < 2; i++) { |
75 | 5.04k | RESET_CDF_COUNTER(nmv->comps[i].classes_cdf, MV_CLASSES); |
76 | 5.04k | RESET_CDF_COUNTER(nmv->comps[i].class0_fp_cdf, MV_FP_SIZE); |
77 | 5.04k | RESET_CDF_COUNTER(nmv->comps[i].fp_cdf, MV_FP_SIZE); |
78 | 5.04k | RESET_CDF_COUNTER(nmv->comps[i].sign_cdf, 2); |
79 | 5.04k | RESET_CDF_COUNTER(nmv->comps[i].class0_hp_cdf, 2); |
80 | 5.04k | RESET_CDF_COUNTER(nmv->comps[i].hp_cdf, 2); |
81 | 5.04k | RESET_CDF_COUNTER(nmv->comps[i].class0_cdf, CLASS0_SIZE); |
82 | 5.04k | RESET_CDF_COUNTER(nmv->comps[i].bits_cdf, 2); |
83 | 5.04k | } |
84 | 2.52k | } |
85 | | |
86 | 1.26k | void av1_reset_cdf_symbol_counters(FRAME_CONTEXT *fc) { |
87 | 1.26k | RESET_CDF_COUNTER(fc->txb_skip_cdf, 2); |
88 | 1.26k | RESET_CDF_COUNTER(fc->eob_extra_cdf, 2); |
89 | 1.26k | RESET_CDF_COUNTER(fc->dc_sign_cdf, 2); |
90 | 1.26k | RESET_CDF_COUNTER(fc->eob_flag_cdf16, 5); |
91 | 1.26k | RESET_CDF_COUNTER(fc->eob_flag_cdf32, 6); |
92 | 1.26k | RESET_CDF_COUNTER(fc->eob_flag_cdf64, 7); |
93 | 1.26k | RESET_CDF_COUNTER(fc->eob_flag_cdf128, 8); |
94 | 1.26k | RESET_CDF_COUNTER(fc->eob_flag_cdf256, 9); |
95 | 1.26k | RESET_CDF_COUNTER(fc->eob_flag_cdf512, 10); |
96 | 1.26k | RESET_CDF_COUNTER(fc->eob_flag_cdf1024, 11); |
97 | 1.26k | RESET_CDF_COUNTER(fc->coeff_base_eob_cdf, 3); |
98 | 1.26k | RESET_CDF_COUNTER(fc->coeff_base_cdf, 4); |
99 | 1.26k | RESET_CDF_COUNTER(fc->coeff_br_cdf, BR_CDF_SIZE); |
100 | 1.26k | RESET_CDF_COUNTER(fc->newmv_cdf, 2); |
101 | 1.26k | RESET_CDF_COUNTER(fc->zeromv_cdf, 2); |
102 | 1.26k | RESET_CDF_COUNTER(fc->refmv_cdf, 2); |
103 | 1.26k | RESET_CDF_COUNTER(fc->drl_cdf, 2); |
104 | 1.26k | RESET_CDF_COUNTER(fc->inter_compound_mode_cdf, INTER_COMPOUND_MODES); |
105 | 1.26k | RESET_CDF_COUNTER(fc->compound_type_cdf, MASKED_COMPOUND_TYPES); |
106 | 1.26k | RESET_CDF_COUNTER(fc->wedge_idx_cdf, 16); |
107 | 1.26k | RESET_CDF_COUNTER(fc->interintra_cdf, 2); |
108 | 1.26k | RESET_CDF_COUNTER(fc->wedge_interintra_cdf, 2); |
109 | 1.26k | RESET_CDF_COUNTER(fc->interintra_mode_cdf, INTERINTRA_MODES); |
110 | 1.26k | RESET_CDF_COUNTER(fc->motion_mode_cdf, MOTION_MODES); |
111 | 1.26k | RESET_CDF_COUNTER(fc->obmc_cdf, 2); |
112 | 1.26k | RESET_CDF_COUNTER(fc->palette_y_size_cdf, PALETTE_SIZES); |
113 | 1.26k | RESET_CDF_COUNTER(fc->palette_uv_size_cdf, PALETTE_SIZES); |
114 | 10.0k | for (int j = 0; j < PALETTE_SIZES; j++) { |
115 | 8.83k | int nsymbs = j + PALETTE_MIN_SIZE; |
116 | 8.83k | RESET_CDF_COUNTER_STRIDE(fc->palette_y_color_index_cdf[j], nsymbs, |
117 | 8.83k | CDF_SIZE(PALETTE_COLORS)); |
118 | 8.83k | RESET_CDF_COUNTER_STRIDE(fc->palette_uv_color_index_cdf[j], nsymbs, |
119 | 8.83k | CDF_SIZE(PALETTE_COLORS)); |
120 | 8.83k | } |
121 | 1.26k | RESET_CDF_COUNTER(fc->palette_y_mode_cdf, 2); |
122 | 1.26k | RESET_CDF_COUNTER(fc->palette_uv_mode_cdf, 2); |
123 | 1.26k | RESET_CDF_COUNTER(fc->comp_inter_cdf, 2); |
124 | 1.26k | RESET_CDF_COUNTER(fc->single_ref_cdf, 2); |
125 | 1.26k | RESET_CDF_COUNTER(fc->comp_ref_type_cdf, 2); |
126 | 1.26k | RESET_CDF_COUNTER(fc->uni_comp_ref_cdf, 2); |
127 | 1.26k | RESET_CDF_COUNTER(fc->comp_ref_cdf, 2); |
128 | 1.26k | RESET_CDF_COUNTER(fc->comp_bwdref_cdf, 2); |
129 | 1.26k | RESET_CDF_COUNTER(fc->txfm_partition_cdf, 2); |
130 | 1.26k | RESET_CDF_COUNTER(fc->compound_index_cdf, 2); |
131 | 1.26k | RESET_CDF_COUNTER(fc->comp_group_idx_cdf, 2); |
132 | 1.26k | RESET_CDF_COUNTER(fc->skip_mode_cdfs, 2); |
133 | 1.26k | RESET_CDF_COUNTER(fc->skip_txfm_cdfs, 2); |
134 | 1.26k | RESET_CDF_COUNTER(fc->intra_inter_cdf, 2); |
135 | 1.26k | reset_nmv_counter(&fc->nmvc); |
136 | 1.26k | reset_nmv_counter(&fc->ndvc); |
137 | 1.26k | RESET_CDF_COUNTER(fc->intrabc_cdf, 2); |
138 | 1.26k | RESET_CDF_COUNTER(fc->seg.tree_cdf, MAX_SEGMENTS); |
139 | 1.26k | RESET_CDF_COUNTER(fc->seg.pred_cdf, 2); |
140 | 1.26k | RESET_CDF_COUNTER(fc->seg.spatial_pred_seg_cdf, MAX_SEGMENTS); |
141 | 1.26k | RESET_CDF_COUNTER(fc->filter_intra_cdfs, 2); |
142 | 1.26k | RESET_CDF_COUNTER(fc->filter_intra_mode_cdf, FILTER_INTRA_MODES); |
143 | 1.26k | RESET_CDF_COUNTER(fc->switchable_restore_cdf, RESTORE_SWITCHABLE_TYPES); |
144 | 1.26k | RESET_CDF_COUNTER(fc->wiener_restore_cdf, 2); |
145 | 1.26k | RESET_CDF_COUNTER(fc->sgrproj_restore_cdf, 2); |
146 | 1.26k | RESET_CDF_COUNTER(fc->y_mode_cdf, INTRA_MODES); |
147 | 1.26k | RESET_CDF_COUNTER_STRIDE(fc->uv_mode_cdf[0], UV_INTRA_MODES - 1, |
148 | 1.26k | CDF_SIZE(UV_INTRA_MODES)); |
149 | 1.26k | RESET_CDF_COUNTER(fc->uv_mode_cdf[1], UV_INTRA_MODES); |
150 | 26.5k | for (int i = 0; i < PARTITION_CONTEXTS; i++) { |
151 | 25.2k | if (i < 4) { |
152 | 5.04k | RESET_CDF_COUNTER_STRIDE(fc->partition_cdf[i], 4, CDF_SIZE(10)); |
153 | 20.1k | } else if (i < 16) { |
154 | 15.1k | RESET_CDF_COUNTER(fc->partition_cdf[i], 10); |
155 | 15.1k | } else { |
156 | 5.04k | RESET_CDF_COUNTER_STRIDE(fc->partition_cdf[i], 8, CDF_SIZE(10)); |
157 | 5.04k | } |
158 | 25.2k | } |
159 | 1.26k | RESET_CDF_COUNTER(fc->switchable_interp_cdf, SWITCHABLE_FILTERS); |
160 | 1.26k | RESET_CDF_COUNTER(fc->kf_y_cdf, INTRA_MODES); |
161 | 1.26k | RESET_CDF_COUNTER(fc->angle_delta_cdf, 2 * MAX_ANGLE_DELTA + 1); |
162 | 1.26k | RESET_CDF_COUNTER_STRIDE(fc->tx_size_cdf[0], MAX_TX_DEPTH, |
163 | 1.26k | CDF_SIZE(MAX_TX_DEPTH + 1)); |
164 | 1.26k | RESET_CDF_COUNTER(fc->tx_size_cdf[1], MAX_TX_DEPTH + 1); |
165 | 1.26k | RESET_CDF_COUNTER(fc->tx_size_cdf[2], MAX_TX_DEPTH + 1); |
166 | 1.26k | RESET_CDF_COUNTER(fc->tx_size_cdf[3], MAX_TX_DEPTH + 1); |
167 | 1.26k | RESET_CDF_COUNTER(fc->delta_q_cdf, DELTA_Q_PROBS + 1); |
168 | 1.26k | RESET_CDF_COUNTER(fc->delta_lf_cdf, DELTA_LF_PROBS + 1); |
169 | 6.31k | for (int i = 0; i < FRAME_LF_COUNT; i++) { |
170 | 5.04k | RESET_CDF_COUNTER(fc->delta_lf_multi_cdf[i], DELTA_LF_PROBS + 1); |
171 | 5.04k | } |
172 | 1.26k | RESET_CDF_COUNTER_STRIDE(fc->intra_ext_tx_cdf[1], 7, CDF_SIZE(TX_TYPES)); |
173 | 1.26k | RESET_CDF_COUNTER_STRIDE(fc->intra_ext_tx_cdf[2], 5, CDF_SIZE(TX_TYPES)); |
174 | 1.26k | RESET_CDF_COUNTER_STRIDE(fc->inter_ext_tx_cdf[1], 16, CDF_SIZE(TX_TYPES)); |
175 | 1.26k | RESET_CDF_COUNTER_STRIDE(fc->inter_ext_tx_cdf[2], 12, CDF_SIZE(TX_TYPES)); |
176 | 1.26k | RESET_CDF_COUNTER_STRIDE(fc->inter_ext_tx_cdf[3], 2, CDF_SIZE(TX_TYPES)); |
177 | 1.26k | RESET_CDF_COUNTER(fc->cfl_sign_cdf, CFL_JOINT_SIGNS); |
178 | 1.26k | RESET_CDF_COUNTER(fc->cfl_alpha_cdf, CFL_ALPHABET_SIZE); |
179 | 1.26k | } |