blob: 323e2aed58f4948fba25569c5110946c2e15116f [file] [log] [blame]
Yaowu Xuc27fc142016-08-22 16:08:15 -07001/*
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Yaowu Xuc27fc142016-08-22 16:08:15 -07003 *
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07004 * 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.
Yaowu Xuc27fc142016-08-22 16:08:15 -070010 */
11#include <assert.h>
12
13#include "av1/encoder/cost.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070014#include "av1/common/entropy.h"
15
Hui Suc1cd5192018-01-24 11:05:06 -080016// round(-log2(i/256.) * (1 << AV1_PROB_COST_SHIFT)); i = 128~255.
17const uint16_t av1_prob_cost[128] = {
18 512, 506, 501, 495, 489, 484, 478, 473, 467, 462, 456, 451, 446, 441, 435,
19 430, 425, 420, 415, 410, 405, 400, 395, 390, 385, 380, 375, 371, 366, 361,
20 356, 352, 347, 343, 338, 333, 329, 324, 320, 316, 311, 307, 302, 298, 294,
21 289, 285, 281, 277, 273, 268, 264, 260, 256, 252, 248, 244, 240, 236, 232,
22 228, 224, 220, 216, 212, 209, 205, 201, 197, 194, 190, 186, 182, 179, 175,
23 171, 168, 164, 161, 157, 153, 150, 146, 143, 139, 136, 132, 129, 125, 122,
24 119, 115, 112, 109, 105, 102, 99, 95, 92, 89, 86, 82, 79, 76, 73,
25 70, 66, 63, 60, 57, 54, 51, 48, 45, 42, 38, 35, 32, 29, 26,
26 23, 20, 18, 15, 12, 9, 6, 3,
Yaowu Xuc27fc142016-08-22 16:08:15 -070027};
28
Nathan E. Egge50f19112017-06-27 21:07:57 -040029void av1_cost_tokens_from_cdf(int *costs, const aom_cdf_prob *cdf,
30 const int *inv_map) {
31 int i;
32 aom_cdf_prob prev_cdf = 0;
33 for (i = 0;; ++i) {
Thomas Davies736ddef2017-11-09 09:46:08 +000034 aom_cdf_prob p15 = AOM_ICDF(cdf[i]) - prev_cdf;
Dake Heb79f1b62017-11-19 12:10:59 -080035 p15 = (p15 < EC_MIN_PROB) ? EC_MIN_PROB : p15;
Nathan E. Egge50f19112017-06-27 21:07:57 -040036 prev_cdf = AOM_ICDF(cdf[i]);
37
38 if (inv_map)
39 costs[inv_map[i]] = av1_cost_symbol(p15);
40 else
41 costs[i] = av1_cost_symbol(p15);
42
43 // Stop once we reach the end of the CDF
44 if (cdf[i] == AOM_ICDF(CDF_PROB_TOP)) break;
45 }
46}