Coverage Report

Created: 2025-12-31 06:49

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/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
58.7k
static int get_q_ctx(int q) {
25
58.7k
  if (q <= 20) return 0;
26
28.1k
  if (q <= 60) return 1;
27
14.5k
  if (q <= 120) return 2;
28
10.5k
  return 3;
29
14.5k
}
30
31
58.7k
void av1_default_coef_probs(AV1_COMMON *cm) {
32
58.7k
  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
58.7k
  av1_copy(cm->fc->txb_skip_cdf, av1_default_txb_skip_cdfs[index]);
38
58.7k
  av1_copy(cm->fc->eob_extra_cdf, av1_default_eob_extra_cdfs[index]);
39
58.7k
  av1_copy(cm->fc->dc_sign_cdf, av1_default_dc_sign_cdfs[index]);
40
58.7k
  av1_copy(cm->fc->coeff_br_cdf, av1_default_coeff_lps_multi_cdfs[index]);
41
58.7k
  av1_copy(cm->fc->coeff_base_cdf, av1_default_coeff_base_multi_cdfs[index]);
42
58.7k
  av1_copy(cm->fc->coeff_base_eob_cdf,
43
58.7k
           av1_default_coeff_base_eob_multi_cdfs[index]);
44
58.7k
  av1_copy(cm->fc->eob_flag_cdf16, av1_default_eob_multi16_cdfs[index]);
45
58.7k
  av1_copy(cm->fc->eob_flag_cdf32, av1_default_eob_multi32_cdfs[index]);
46
58.7k
  av1_copy(cm->fc->eob_flag_cdf64, av1_default_eob_multi64_cdfs[index]);
47
58.7k
  av1_copy(cm->fc->eob_flag_cdf128, av1_default_eob_multi128_cdfs[index]);
48
58.7k
  av1_copy(cm->fc->eob_flag_cdf256, av1_default_eob_multi256_cdfs[index]);
49
58.7k
  av1_copy(cm->fc->eob_flag_cdf512, av1_default_eob_multi512_cdfs[index]);
50
58.7k
  av1_copy(cm->fc->eob_flag_cdf1024, av1_default_eob_multi1024_cdfs[index]);
51
58.7k
}
52
53
static inline void reset_cdf_symbol_counter(aom_cdf_prob *cdf_ptr, int num_cdfs,
54
2.03M
                                            int cdf_stride, int nsymbs) {
55
24.5M
  for (int i = 0; i < num_cdfs; i++) {
56
22.5M
    cdf_ptr[i * cdf_stride + nsymbs] = 0;
57
22.5M
  }
58
2.03M
}
59
60
#define RESET_CDF_COUNTER(cname, nsymbs) \
61
1.61M
  RESET_CDF_COUNTER_STRIDE(cname, nsymbs, CDF_SIZE(nsymbs))
62
63
#define RESET_CDF_COUNTER_STRIDE(cname, nsymbs, cdf_stride)          \
64
2.03M
  do {                                                               \
65
2.03M
    aom_cdf_prob *cdf_ptr = (aom_cdf_prob *)cname;                   \
66
2.03M
    int array_size = (int)sizeof(cname) / sizeof(aom_cdf_prob);      \
67
2.03M
    int num_cdfs = array_size / cdf_stride;                          \
68
2.03M
    reset_cdf_symbol_counter(cdf_ptr, num_cdfs, cdf_stride, nsymbs); \
69
2.03M
  } while (0)
70
71
29.0k
static inline void reset_nmv_counter(nmv_context *nmv) {
72
29.0k
  RESET_CDF_COUNTER(nmv->joints_cdf, 4);
73
87.1k
  for (int i = 0; i < 2; i++) {
74
58.1k
    RESET_CDF_COUNTER(nmv->comps[i].classes_cdf, MV_CLASSES);
75
58.1k
    RESET_CDF_COUNTER(nmv->comps[i].class0_fp_cdf, MV_FP_SIZE);
76
58.1k
    RESET_CDF_COUNTER(nmv->comps[i].fp_cdf, MV_FP_SIZE);
77
58.1k
    RESET_CDF_COUNTER(nmv->comps[i].sign_cdf, 2);
78
58.1k
    RESET_CDF_COUNTER(nmv->comps[i].class0_hp_cdf, 2);
79
58.1k
    RESET_CDF_COUNTER(nmv->comps[i].hp_cdf, 2);
80
58.1k
    RESET_CDF_COUNTER(nmv->comps[i].class0_cdf, CLASS0_SIZE);
81
58.1k
    RESET_CDF_COUNTER(nmv->comps[i].bits_cdf, 2);
82
58.1k
  }
83
29.0k
}
84
85
14.5k
void av1_reset_cdf_symbol_counters(FRAME_CONTEXT *fc) {
86
14.5k
  RESET_CDF_COUNTER(fc->txb_skip_cdf, 2);
87
14.5k
  RESET_CDF_COUNTER(fc->eob_extra_cdf, 2);
88
14.5k
  RESET_CDF_COUNTER(fc->dc_sign_cdf, 2);
89
14.5k
  RESET_CDF_COUNTER(fc->eob_flag_cdf16, 5);
90
14.5k
  RESET_CDF_COUNTER(fc->eob_flag_cdf32, 6);
91
14.5k
  RESET_CDF_COUNTER(fc->eob_flag_cdf64, 7);
92
14.5k
  RESET_CDF_COUNTER(fc->eob_flag_cdf128, 8);
93
14.5k
  RESET_CDF_COUNTER(fc->eob_flag_cdf256, 9);
94
14.5k
  RESET_CDF_COUNTER(fc->eob_flag_cdf512, 10);
95
14.5k
  RESET_CDF_COUNTER(fc->eob_flag_cdf1024, 11);
96
14.5k
  RESET_CDF_COUNTER(fc->coeff_base_eob_cdf, 3);
97
14.5k
  RESET_CDF_COUNTER(fc->coeff_base_cdf, 4);
98
14.5k
  RESET_CDF_COUNTER(fc->coeff_br_cdf, BR_CDF_SIZE);
99
14.5k
  RESET_CDF_COUNTER(fc->newmv_cdf, 2);
100
14.5k
  RESET_CDF_COUNTER(fc->zeromv_cdf, 2);
101
14.5k
  RESET_CDF_COUNTER(fc->refmv_cdf, 2);
102
14.5k
  RESET_CDF_COUNTER(fc->drl_cdf, 2);
103
14.5k
  RESET_CDF_COUNTER(fc->inter_compound_mode_cdf, INTER_COMPOUND_MODES);
104
14.5k
  RESET_CDF_COUNTER(fc->compound_type_cdf, MASKED_COMPOUND_TYPES);
105
14.5k
  RESET_CDF_COUNTER(fc->wedge_idx_cdf, 16);
106
14.5k
  RESET_CDF_COUNTER(fc->interintra_cdf, 2);
107
14.5k
  RESET_CDF_COUNTER(fc->wedge_interintra_cdf, 2);
108
14.5k
  RESET_CDF_COUNTER(fc->interintra_mode_cdf, INTERINTRA_MODES);
109
14.5k
  RESET_CDF_COUNTER(fc->motion_mode_cdf, MOTION_MODES);
110
14.5k
  RESET_CDF_COUNTER(fc->obmc_cdf, 2);
111
14.5k
  RESET_CDF_COUNTER(fc->palette_y_size_cdf, PALETTE_SIZES);
112
14.5k
  RESET_CDF_COUNTER(fc->palette_uv_size_cdf, PALETTE_SIZES);
113
116k
  for (int j = 0; j < PALETTE_SIZES; j++) {
114
101k
    int nsymbs = j + PALETTE_MIN_SIZE;
115
101k
    RESET_CDF_COUNTER_STRIDE(fc->palette_y_color_index_cdf[j], nsymbs,
116
101k
                             CDF_SIZE(PALETTE_COLORS));
117
101k
    RESET_CDF_COUNTER_STRIDE(fc->palette_uv_color_index_cdf[j], nsymbs,
118
101k
                             CDF_SIZE(PALETTE_COLORS));
119
101k
  }
120
14.5k
  RESET_CDF_COUNTER(fc->palette_y_mode_cdf, 2);
121
14.5k
  RESET_CDF_COUNTER(fc->palette_uv_mode_cdf, 2);
122
14.5k
  RESET_CDF_COUNTER(fc->comp_inter_cdf, 2);
123
14.5k
  RESET_CDF_COUNTER(fc->single_ref_cdf, 2);
124
14.5k
  RESET_CDF_COUNTER(fc->comp_ref_type_cdf, 2);
125
14.5k
  RESET_CDF_COUNTER(fc->uni_comp_ref_cdf, 2);
126
14.5k
  RESET_CDF_COUNTER(fc->comp_ref_cdf, 2);
127
14.5k
  RESET_CDF_COUNTER(fc->comp_bwdref_cdf, 2);
128
14.5k
  RESET_CDF_COUNTER(fc->txfm_partition_cdf, 2);
129
14.5k
  RESET_CDF_COUNTER(fc->compound_index_cdf, 2);
130
14.5k
  RESET_CDF_COUNTER(fc->comp_group_idx_cdf, 2);
131
14.5k
  RESET_CDF_COUNTER(fc->skip_mode_cdfs, 2);
132
14.5k
  RESET_CDF_COUNTER(fc->skip_txfm_cdfs, 2);
133
14.5k
  RESET_CDF_COUNTER(fc->intra_inter_cdf, 2);
134
14.5k
  reset_nmv_counter(&fc->nmvc);
135
14.5k
  reset_nmv_counter(&fc->ndvc);
136
14.5k
  RESET_CDF_COUNTER(fc->intrabc_cdf, 2);
137
14.5k
  RESET_CDF_COUNTER(fc->seg.pred_cdf, 2);
138
14.5k
  RESET_CDF_COUNTER(fc->seg.spatial_pred_seg_cdf, MAX_SEGMENTS);
139
14.5k
  RESET_CDF_COUNTER(fc->filter_intra_cdfs, 2);
140
14.5k
  RESET_CDF_COUNTER(fc->filter_intra_mode_cdf, FILTER_INTRA_MODES);
141
14.5k
  RESET_CDF_COUNTER(fc->switchable_restore_cdf, RESTORE_SWITCHABLE_TYPES);
142
14.5k
  RESET_CDF_COUNTER(fc->wiener_restore_cdf, 2);
143
14.5k
  RESET_CDF_COUNTER(fc->sgrproj_restore_cdf, 2);
144
14.5k
  RESET_CDF_COUNTER(fc->y_mode_cdf, INTRA_MODES);
145
14.5k
  RESET_CDF_COUNTER_STRIDE(fc->uv_mode_cdf[0], UV_INTRA_MODES - 1,
146
14.5k
                           CDF_SIZE(UV_INTRA_MODES));
147
14.5k
  RESET_CDF_COUNTER(fc->uv_mode_cdf[1], UV_INTRA_MODES);
148
305k
  for (int i = 0; i < PARTITION_CONTEXTS; i++) {
149
290k
    if (i < 4) {
150
58.1k
      RESET_CDF_COUNTER_STRIDE(fc->partition_cdf[i], 4, CDF_SIZE(10));
151
232k
    } else if (i < 16) {
152
174k
      RESET_CDF_COUNTER(fc->partition_cdf[i], 10);
153
174k
    } else {
154
58.1k
      RESET_CDF_COUNTER_STRIDE(fc->partition_cdf[i], 8, CDF_SIZE(10));
155
58.1k
    }
156
290k
  }
157
14.5k
  RESET_CDF_COUNTER(fc->switchable_interp_cdf, SWITCHABLE_FILTERS);
158
14.5k
  RESET_CDF_COUNTER(fc->kf_y_cdf, INTRA_MODES);
159
14.5k
  RESET_CDF_COUNTER(fc->angle_delta_cdf, 2 * MAX_ANGLE_DELTA + 1);
160
14.5k
  RESET_CDF_COUNTER_STRIDE(fc->tx_size_cdf[0], MAX_TX_DEPTH,
161
14.5k
                           CDF_SIZE(MAX_TX_DEPTH + 1));
162
14.5k
  RESET_CDF_COUNTER(fc->tx_size_cdf[1], MAX_TX_DEPTH + 1);
163
14.5k
  RESET_CDF_COUNTER(fc->tx_size_cdf[2], MAX_TX_DEPTH + 1);
164
14.5k
  RESET_CDF_COUNTER(fc->tx_size_cdf[3], MAX_TX_DEPTH + 1);
165
14.5k
  RESET_CDF_COUNTER(fc->delta_q_cdf, DELTA_Q_PROBS + 1);
166
14.5k
  RESET_CDF_COUNTER(fc->delta_lf_cdf, DELTA_LF_PROBS + 1);
167
72.6k
  for (int i = 0; i < FRAME_LF_COUNT; i++) {
168
58.1k
    RESET_CDF_COUNTER(fc->delta_lf_multi_cdf[i], DELTA_LF_PROBS + 1);
169
58.1k
  }
170
14.5k
  RESET_CDF_COUNTER_STRIDE(fc->intra_ext_tx_cdf[1], 7, CDF_SIZE(TX_TYPES));
171
14.5k
  RESET_CDF_COUNTER_STRIDE(fc->intra_ext_tx_cdf[2], 5, CDF_SIZE(TX_TYPES));
172
14.5k
  RESET_CDF_COUNTER_STRIDE(fc->inter_ext_tx_cdf[1], 16, CDF_SIZE(TX_TYPES));
173
14.5k
  RESET_CDF_COUNTER_STRIDE(fc->inter_ext_tx_cdf[2], 12, CDF_SIZE(TX_TYPES));
174
14.5k
  RESET_CDF_COUNTER_STRIDE(fc->inter_ext_tx_cdf[3], 2, CDF_SIZE(TX_TYPES));
175
14.5k
  RESET_CDF_COUNTER(fc->cfl_sign_cdf, CFL_JOINT_SIGNS);
176
14.5k
  RESET_CDF_COUNTER(fc->cfl_alpha_cdf, CFL_ALPHABET_SIZE);
177
14.5k
}