Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1 | /* |
Yaowu Xu | bde4ac8 | 2016-11-28 15:26:06 -0800 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3 | * |
Yaowu Xu | bde4ac8 | 2016-11-28 15:26:06 -0800 | [diff] [blame] | 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. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
James Zern | e1cbb13 | 2018-08-22 14:10:36 -0700 | [diff] [blame^] | 12 | #ifndef AOM_AV1_ENCODER_COST_H_ |
| 13 | #define AOM_AV1_ENCODER_COST_H_ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 14 | |
| 15 | #include "aom_dsp/prob.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 16 | #include "aom/aom_integer.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 17 | |
| 18 | #ifdef __cplusplus |
| 19 | extern "C" { |
| 20 | #endif |
| 21 | |
Hui Su | c1cd519 | 2018-01-24 11:05:06 -0800 | [diff] [blame] | 22 | extern const uint16_t av1_prob_cost[128]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 23 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 24 | // The factor to scale from cost in bits to cost in av1_prob_cost units. |
| 25 | #define AV1_PROB_COST_SHIFT 9 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 26 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 27 | // Cost of coding an n bit literal, using 128 (i.e. 50%) probability |
| 28 | // for each bit. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 29 | #define av1_cost_literal(n) ((n) * (1 << AV1_PROB_COST_SHIFT)) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 30 | |
Nathan E. Egge | 50f1911 | 2017-06-27 21:07:57 -0400 | [diff] [blame] | 31 | // Calculate the cost of a symbol with probability p15 / 2^15 |
| 32 | static INLINE int av1_cost_symbol(aom_cdf_prob p15) { |
| 33 | assert(0 < p15 && p15 < CDF_PROB_TOP); |
| 34 | const int shift = CDF_PROB_BITS - 1 - get_msb(p15); |
Hui Su | c1cd519 | 2018-01-24 11:05:06 -0800 | [diff] [blame] | 35 | const int prob = get_prob(p15 << shift, CDF_PROB_TOP); |
| 36 | assert(prob >= 128); |
| 37 | return av1_prob_cost[prob - 128] + av1_cost_literal(shift); |
Nathan E. Egge | 50f1911 | 2017-06-27 21:07:57 -0400 | [diff] [blame] | 38 | } |
| 39 | |
Nathan E. Egge | 50f1911 | 2017-06-27 21:07:57 -0400 | [diff] [blame] | 40 | void av1_cost_tokens_from_cdf(int *costs, const aom_cdf_prob *cdf, |
| 41 | const int *inv_map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 42 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 43 | #ifdef __cplusplus |
| 44 | } // extern "C" |
| 45 | #endif |
| 46 | |
James Zern | e1cbb13 | 2018-08-22 14:10:36 -0700 | [diff] [blame^] | 47 | #endif // AOM_AV1_ENCODER_COST_H_ |