Coverage Report

Created: 2026-11-12 08:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/aom/av1/encoder/cost.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
#include <assert.h>
12
13
#include "aom_dsp/entcode.h"
14
#include "av1/encoder/cost.h"
15
#include "av1/common/entropy.h"
16
17
// round(-log2(i/256.) * (1 << AV1_PROB_COST_SHIFT)); i = 128~255 (plus 128th
18
// duplicate for 256).
19
const uint16_t av1_prob_cost[129] = {
20
  512, 506, 501, 495, 489, 484, 478, 473, 467, 462, 456, 451, 446, 441, 435,
21
  430, 425, 420, 415, 410, 405, 400, 395, 390, 385, 380, 375, 371, 366, 361,
22
  356, 352, 347, 343, 338, 333, 329, 324, 320, 316, 311, 307, 302, 298, 294,
23
  289, 285, 281, 277, 273, 268, 264, 260, 256, 252, 248, 244, 240, 236, 232,
24
  228, 224, 220, 216, 212, 209, 205, 201, 197, 194, 190, 186, 182, 179, 175,
25
  171, 168, 164, 161, 157, 153, 150, 146, 143, 139, 136, 132, 129, 125, 122,
26
  119, 115, 112, 109, 105, 102, 99,  95,  92,  89,  86,  82,  79,  76,  73,
27
  70,  66,  63,  60,  57,  54,  51,  48,  45,  42,  38,  35,  32,  29,  26,
28
  23,  20,  18,  15,  12,  9,   6,   3,   3,
29
};
30
31
void av1_cost_tokens_from_cdf(int *costs, const aom_cdf_prob *cdf,
32
0
                              const int *inv_map) {
33
0
  int prev_icdf = CDF_PROB_TOP;
34
0
  if (inv_map) {
35
0
    for (int i = 0;; ++i) {
36
0
      const int cur_icdf = cdf[i];
37
0
      const int p15 =
38
0
          clamp(prev_icdf - cur_icdf, EC_MIN_PROB, CDF_PROB_TOP - 1);
39
0
      prev_icdf = cur_icdf;
40
0
      costs[inv_map[i]] = av1_cost_symbol_clamped(p15);
41
0
      if (cur_icdf == 0) break;
42
0
    }
43
0
  } else {
44
0
    for (int i = 0;; ++i) {
45
0
      const int cur_icdf = cdf[i];
46
0
      const int p15 =
47
0
          clamp(prev_icdf - cur_icdf, EC_MIN_PROB, CDF_PROB_TOP - 1);
48
0
      prev_icdf = cur_icdf;
49
0
      costs[i] = av1_cost_symbol_clamped(p15);
50
0
      if (cur_icdf == 0) break;
51
0
    }
52
0
  }
53
0
}