1*77c1e3ccSAndroid Build Coastguard Worker /*
2*77c1e3ccSAndroid Build Coastguard Worker * Copyright (c) 2016, Alliance for Open Media. All rights reserved.
3*77c1e3ccSAndroid Build Coastguard Worker *
4*77c1e3ccSAndroid Build Coastguard Worker * This source code is subject to the terms of the BSD 2 Clause License and
5*77c1e3ccSAndroid Build Coastguard Worker * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6*77c1e3ccSAndroid Build Coastguard Worker * was not distributed with this source code in the LICENSE file, you can
7*77c1e3ccSAndroid Build Coastguard Worker * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8*77c1e3ccSAndroid Build Coastguard Worker * Media Patent License 1.0 was not distributed with this source code in the
9*77c1e3ccSAndroid Build Coastguard Worker * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10*77c1e3ccSAndroid Build Coastguard Worker */
11*77c1e3ccSAndroid Build Coastguard Worker #include <assert.h>
12*77c1e3ccSAndroid Build Coastguard Worker
13*77c1e3ccSAndroid Build Coastguard Worker #include "av1/encoder/cost.h"
14*77c1e3ccSAndroid Build Coastguard Worker #include "av1/common/entropy.h"
15*77c1e3ccSAndroid Build Coastguard Worker
16*77c1e3ccSAndroid Build Coastguard Worker // round(-log2(i/256.) * (1 << AV1_PROB_COST_SHIFT)); i = 128~255.
17*77c1e3ccSAndroid Build Coastguard Worker const uint16_t av1_prob_cost[128] = {
18*77c1e3ccSAndroid Build Coastguard Worker 512, 506, 501, 495, 489, 484, 478, 473, 467, 462, 456, 451, 446, 441, 435,
19*77c1e3ccSAndroid Build Coastguard Worker 430, 425, 420, 415, 410, 405, 400, 395, 390, 385, 380, 375, 371, 366, 361,
20*77c1e3ccSAndroid Build Coastguard Worker 356, 352, 347, 343, 338, 333, 329, 324, 320, 316, 311, 307, 302, 298, 294,
21*77c1e3ccSAndroid Build Coastguard Worker 289, 285, 281, 277, 273, 268, 264, 260, 256, 252, 248, 244, 240, 236, 232,
22*77c1e3ccSAndroid Build Coastguard Worker 228, 224, 220, 216, 212, 209, 205, 201, 197, 194, 190, 186, 182, 179, 175,
23*77c1e3ccSAndroid Build Coastguard Worker 171, 168, 164, 161, 157, 153, 150, 146, 143, 139, 136, 132, 129, 125, 122,
24*77c1e3ccSAndroid Build Coastguard Worker 119, 115, 112, 109, 105, 102, 99, 95, 92, 89, 86, 82, 79, 76, 73,
25*77c1e3ccSAndroid Build Coastguard Worker 70, 66, 63, 60, 57, 54, 51, 48, 45, 42, 38, 35, 32, 29, 26,
26*77c1e3ccSAndroid Build Coastguard Worker 23, 20, 18, 15, 12, 9, 6, 3,
27*77c1e3ccSAndroid Build Coastguard Worker };
28*77c1e3ccSAndroid Build Coastguard Worker
av1_cost_tokens_from_cdf(int * costs,const aom_cdf_prob * cdf,const int * inv_map)29*77c1e3ccSAndroid Build Coastguard Worker void av1_cost_tokens_from_cdf(int *costs, const aom_cdf_prob *cdf,
30*77c1e3ccSAndroid Build Coastguard Worker const int *inv_map) {
31*77c1e3ccSAndroid Build Coastguard Worker int i;
32*77c1e3ccSAndroid Build Coastguard Worker aom_cdf_prob prev_cdf = 0;
33*77c1e3ccSAndroid Build Coastguard Worker for (i = 0;; ++i) {
34*77c1e3ccSAndroid Build Coastguard Worker aom_cdf_prob p15 = AOM_ICDF(cdf[i]) - prev_cdf;
35*77c1e3ccSAndroid Build Coastguard Worker p15 = (p15 < EC_MIN_PROB) ? EC_MIN_PROB : p15;
36*77c1e3ccSAndroid Build Coastguard Worker prev_cdf = AOM_ICDF(cdf[i]);
37*77c1e3ccSAndroid Build Coastguard Worker
38*77c1e3ccSAndroid Build Coastguard Worker if (inv_map)
39*77c1e3ccSAndroid Build Coastguard Worker costs[inv_map[i]] = av1_cost_symbol(p15);
40*77c1e3ccSAndroid Build Coastguard Worker else
41*77c1e3ccSAndroid Build Coastguard Worker costs[i] = av1_cost_symbol(p15);
42*77c1e3ccSAndroid Build Coastguard Worker
43*77c1e3ccSAndroid Build Coastguard Worker // Stop once we reach the end of the CDF
44*77c1e3ccSAndroid Build Coastguard Worker if (cdf[i] == AOM_ICDF(CDF_PROB_TOP)) break;
45*77c1e3ccSAndroid Build Coastguard Worker }
46*77c1e3ccSAndroid Build Coastguard Worker }
47