/src/libvpx/vpx_dsp/prob.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2013 The WebM project authors. All Rights Reserved. |
3 | | * |
4 | | * Use of this source code is governed by a BSD-style license |
5 | | * that can be found in the LICENSE file in the root of the source |
6 | | * tree. An additional intellectual property rights grant can be found |
7 | | * in the file PATENTS. All contributing project authors may |
8 | | * be found in the AUTHORS file in the root of the source tree. |
9 | | */ |
10 | | |
11 | | #ifndef VPX_VPX_DSP_PROB_H_ |
12 | | #define VPX_VPX_DSP_PROB_H_ |
13 | | |
14 | | #include <assert.h> |
15 | | |
16 | | #include "./vpx_config.h" |
17 | | #include "./vpx_dsp_common.h" |
18 | | |
19 | | #include "vpx_ports/mem.h" |
20 | | |
21 | | #ifdef __cplusplus |
22 | | extern "C" { |
23 | | #endif |
24 | | |
25 | | typedef uint8_t vpx_prob; |
26 | | |
27 | 689k | #define MAX_PROB 255 |
28 | | |
29 | | #define vpx_prob_half ((vpx_prob)128) |
30 | | |
31 | | typedef int8_t vpx_tree_index; |
32 | | |
33 | | #define TREE_SIZE(leaf_count) (2 * (leaf_count) - 2) |
34 | | |
35 | | #define vpx_complement(x) (255 - (x)) |
36 | | |
37 | | #define MODE_MV_COUNT_SAT 20 |
38 | | |
39 | | /* We build coding trees compactly in arrays. |
40 | | Each node of the tree is a pair of vpx_tree_indices. |
41 | | Array index often references a corresponding probability table. |
42 | | Index <= 0 means done encoding/decoding and value = -Index, |
43 | | Index > 0 means need another bit, specification at index. |
44 | | Nonnegative indices are always even; processing begins at node 0. */ |
45 | | |
46 | | typedef const vpx_tree_index vpx_tree[]; |
47 | | |
48 | 4.13M | static INLINE vpx_prob get_prob(unsigned int num, unsigned int den) { |
49 | 4.13M | assert(den != 0); |
50 | 4.13M | { |
51 | 4.13M | const int p = (int)(((uint64_t)num * 256 + (den >> 1)) / den); |
52 | | // (p > 255) ? 255 : (p < 1) ? 1 : p; |
53 | 4.13M | const int clipped_prob = p | ((255 - p) >> 23) | (p == 0); |
54 | 4.13M | return (vpx_prob)clipped_prob; |
55 | 4.13M | } |
56 | 4.13M | } Unexecuted instantiation: vp9_dx_iface.c:get_prob Unexecuted instantiation: vp9_decodeframe.c:get_prob Unexecuted instantiation: vp9_detokenize.c:get_prob Unexecuted instantiation: vp9_decoder.c:get_prob Unexecuted instantiation: vp9_dsubexp.c:get_prob Unexecuted instantiation: yv12config.c:get_prob Line | Count | Source | 48 | 1.82M | static INLINE vpx_prob get_prob(unsigned int num, unsigned int den) { | 49 | 1.82M | assert(den != 0); | 50 | 1.82M | { | 51 | 1.82M | const int p = (int)(((uint64_t)num * 256 + (den >> 1)) / den); | 52 | | // (p > 255) ? 255 : (p < 1) ? 1 : p; | 53 | 1.82M | const int clipped_prob = p | ((255 - p) >> 23) | (p == 0); | 54 | 1.82M | return (vpx_prob)clipped_prob; | 55 | 1.82M | } | 56 | 1.82M | } |
Unexecuted instantiation: bitreader.c:get_prob Unexecuted instantiation: vp9_alloccommon.c:get_prob Unexecuted instantiation: vp9_blockd.c:get_prob Line | Count | Source | 48 | 1.88M | static INLINE vpx_prob get_prob(unsigned int num, unsigned int den) { | 49 | 1.88M | assert(den != 0); | 50 | 1.88M | { | 51 | 1.88M | const int p = (int)(((uint64_t)num * 256 + (den >> 1)) / den); | 52 | | // (p > 255) ? 255 : (p < 1) ? 1 : p; | 53 | 1.88M | const int clipped_prob = p | ((255 - p) >> 23) | (p == 0); | 54 | 1.88M | return (vpx_prob)clipped_prob; | 55 | 1.88M | } | 56 | 1.88M | } |
vp9_entropymode.c:get_prob Line | Count | Source | 48 | 298k | static INLINE vpx_prob get_prob(unsigned int num, unsigned int den) { | 49 | 298k | assert(den != 0); | 50 | 298k | { | 51 | 298k | const int p = (int)(((uint64_t)num * 256 + (den >> 1)) / den); | 52 | | // (p > 255) ? 255 : (p < 1) ? 1 : p; | 53 | 298k | const int clipped_prob = p | ((255 - p) >> 23) | (p == 0); | 54 | 298k | return (vpx_prob)clipped_prob; | 55 | 298k | } | 56 | 298k | } |
Line | Count | Source | 48 | 135k | static INLINE vpx_prob get_prob(unsigned int num, unsigned int den) { | 49 | 135k | assert(den != 0); | 50 | 135k | { | 51 | 135k | const int p = (int)(((uint64_t)num * 256 + (den >> 1)) / den); | 52 | | // (p > 255) ? 255 : (p < 1) ? 1 : p; | 53 | 135k | const int clipped_prob = p | ((255 - p) >> 23) | (p == 0); | 54 | 135k | return (vpx_prob)clipped_prob; | 55 | 135k | } | 56 | 135k | } |
Unexecuted instantiation: vp9_idct.c:get_prob Unexecuted instantiation: vp9_pred_common.c:get_prob Unexecuted instantiation: vp9_seg_common.c:get_prob Unexecuted instantiation: vp9_tile_common.c:get_prob Unexecuted instantiation: vp9_loopfilter.c:get_prob Unexecuted instantiation: vp9_thread_common.c:get_prob Unexecuted instantiation: vp9_quant_common.c:get_prob Unexecuted instantiation: vp9_reconinter.c:get_prob Unexecuted instantiation: vp9_reconintra.c:get_prob Unexecuted instantiation: vp9_scan.c:get_prob Unexecuted instantiation: vp9_decodemv.c:get_prob |
57 | | |
58 | 75.6M | static INLINE vpx_prob get_binary_prob(unsigned int n0, unsigned int n1) { |
59 | 75.6M | const unsigned int den = n0 + n1; |
60 | 75.6M | if (den == 0) return 128u; |
61 | 1.88M | return get_prob(n0, den); |
62 | 75.6M | } Unexecuted instantiation: vp9_dx_iface.c:get_binary_prob Unexecuted instantiation: vp9_decodeframe.c:get_binary_prob Unexecuted instantiation: vp9_detokenize.c:get_binary_prob Unexecuted instantiation: vp9_decoder.c:get_binary_prob Unexecuted instantiation: vp9_dsubexp.c:get_binary_prob Unexecuted instantiation: yv12config.c:get_binary_prob Unexecuted instantiation: prob.c:get_binary_prob Unexecuted instantiation: bitreader.c:get_binary_prob Unexecuted instantiation: vp9_alloccommon.c:get_binary_prob Unexecuted instantiation: vp9_blockd.c:get_binary_prob vp9_entropy.c:get_binary_prob Line | Count | Source | 58 | 75.6M | static INLINE vpx_prob get_binary_prob(unsigned int n0, unsigned int n1) { | 59 | 75.6M | const unsigned int den = n0 + n1; | 60 | 75.6M | if (den == 0) return 128u; | 61 | 1.88M | return get_prob(n0, den); | 62 | 75.6M | } |
Unexecuted instantiation: vp9_entropymode.c:get_binary_prob Unexecuted instantiation: vp9_entropymv.c:get_binary_prob Unexecuted instantiation: vp9_idct.c:get_binary_prob Unexecuted instantiation: vp9_pred_common.c:get_binary_prob Unexecuted instantiation: vp9_seg_common.c:get_binary_prob Unexecuted instantiation: vp9_tile_common.c:get_binary_prob Unexecuted instantiation: vp9_loopfilter.c:get_binary_prob Unexecuted instantiation: vp9_thread_common.c:get_binary_prob Unexecuted instantiation: vp9_quant_common.c:get_binary_prob Unexecuted instantiation: vp9_reconinter.c:get_binary_prob Unexecuted instantiation: vp9_reconintra.c:get_binary_prob Unexecuted instantiation: vp9_scan.c:get_binary_prob Unexecuted instantiation: vp9_decodemv.c:get_binary_prob |
63 | | |
64 | | /* This function assumes prob1 and prob2 are already within [1,255] range. */ |
65 | 77.9M | static INLINE vpx_prob weighted_prob(int prob1, int prob2, int factor) { |
66 | 77.9M | return ROUND_POWER_OF_TWO(prob1 * (256 - factor) + prob2 * factor, 8); |
67 | 77.9M | } Unexecuted instantiation: vp9_dx_iface.c:weighted_prob Unexecuted instantiation: vp9_decodeframe.c:weighted_prob Unexecuted instantiation: vp9_detokenize.c:weighted_prob Unexecuted instantiation: vp9_decoder.c:weighted_prob Unexecuted instantiation: vp9_dsubexp.c:weighted_prob Unexecuted instantiation: yv12config.c:weighted_prob Line | Count | Source | 65 | 1.82M | static INLINE vpx_prob weighted_prob(int prob1, int prob2, int factor) { | 66 | 1.82M | return ROUND_POWER_OF_TWO(prob1 * (256 - factor) + prob2 * factor, 8); | 67 | 1.82M | } |
Unexecuted instantiation: bitreader.c:weighted_prob Unexecuted instantiation: vp9_alloccommon.c:weighted_prob Unexecuted instantiation: vp9_blockd.c:weighted_prob vp9_entropy.c:weighted_prob Line | Count | Source | 65 | 75.6M | static INLINE vpx_prob weighted_prob(int prob1, int prob2, int factor) { | 66 | 75.6M | return ROUND_POWER_OF_TWO(prob1 * (256 - factor) + prob2 * factor, 8); | 67 | 75.6M | } |
vp9_entropymode.c:weighted_prob Line | Count | Source | 65 | 298k | static INLINE vpx_prob weighted_prob(int prob1, int prob2, int factor) { | 66 | 298k | return ROUND_POWER_OF_TWO(prob1 * (256 - factor) + prob2 * factor, 8); | 67 | 298k | } |
vp9_entropymv.c:weighted_prob Line | Count | Source | 65 | 135k | static INLINE vpx_prob weighted_prob(int prob1, int prob2, int factor) { | 66 | 135k | return ROUND_POWER_OF_TWO(prob1 * (256 - factor) + prob2 * factor, 8); | 67 | 135k | } |
Unexecuted instantiation: vp9_idct.c:weighted_prob Unexecuted instantiation: vp9_pred_common.c:weighted_prob Unexecuted instantiation: vp9_seg_common.c:weighted_prob Unexecuted instantiation: vp9_tile_common.c:weighted_prob Unexecuted instantiation: vp9_loopfilter.c:weighted_prob Unexecuted instantiation: vp9_thread_common.c:weighted_prob Unexecuted instantiation: vp9_quant_common.c:weighted_prob Unexecuted instantiation: vp9_reconinter.c:weighted_prob Unexecuted instantiation: vp9_reconintra.c:weighted_prob Unexecuted instantiation: vp9_scan.c:weighted_prob Unexecuted instantiation: vp9_decodemv.c:weighted_prob |
68 | | |
69 | | static INLINE vpx_prob merge_probs(vpx_prob pre_prob, const unsigned int ct[2], |
70 | | unsigned int count_sat, |
71 | 75.6M | unsigned int max_update_factor) { |
72 | 75.6M | const vpx_prob prob = get_binary_prob(ct[0], ct[1]); |
73 | 75.6M | const unsigned int count = VPXMIN(ct[0] + ct[1], count_sat); |
74 | 75.6M | const unsigned int factor = max_update_factor * count / count_sat; |
75 | 75.6M | return weighted_prob(pre_prob, prob, factor); |
76 | 75.6M | } Unexecuted instantiation: vp9_dx_iface.c:merge_probs Unexecuted instantiation: vp9_decodeframe.c:merge_probs Unexecuted instantiation: vp9_detokenize.c:merge_probs Unexecuted instantiation: vp9_decoder.c:merge_probs Unexecuted instantiation: vp9_dsubexp.c:merge_probs Unexecuted instantiation: yv12config.c:merge_probs Unexecuted instantiation: prob.c:merge_probs Unexecuted instantiation: bitreader.c:merge_probs Unexecuted instantiation: vp9_alloccommon.c:merge_probs Unexecuted instantiation: vp9_blockd.c:merge_probs vp9_entropy.c:merge_probs Line | Count | Source | 71 | 75.6M | unsigned int max_update_factor) { | 72 | 75.6M | const vpx_prob prob = get_binary_prob(ct[0], ct[1]); | 73 | 75.6M | const unsigned int count = VPXMIN(ct[0] + ct[1], count_sat); | 74 | 75.6M | const unsigned int factor = max_update_factor * count / count_sat; | 75 | 75.6M | return weighted_prob(pre_prob, prob, factor); | 76 | 75.6M | } |
Unexecuted instantiation: vp9_entropymode.c:merge_probs Unexecuted instantiation: vp9_entropymv.c:merge_probs Unexecuted instantiation: vp9_idct.c:merge_probs Unexecuted instantiation: vp9_pred_common.c:merge_probs Unexecuted instantiation: vp9_seg_common.c:merge_probs Unexecuted instantiation: vp9_tile_common.c:merge_probs Unexecuted instantiation: vp9_loopfilter.c:merge_probs Unexecuted instantiation: vp9_thread_common.c:merge_probs Unexecuted instantiation: vp9_quant_common.c:merge_probs Unexecuted instantiation: vp9_reconinter.c:merge_probs Unexecuted instantiation: vp9_reconintra.c:merge_probs Unexecuted instantiation: vp9_scan.c:merge_probs Unexecuted instantiation: vp9_decodemv.c:merge_probs |
77 | | |
78 | | // MODE_MV_MAX_UPDATE_FACTOR (128) * count / MODE_MV_COUNT_SAT; |
79 | | static const int count_to_update_factor[MODE_MV_COUNT_SAT + 1] = { |
80 | | 0, 6, 12, 19, 25, 32, 38, 44, 51, 57, 64, |
81 | | 70, 76, 83, 89, 96, 102, 108, 115, 121, 128 |
82 | | }; |
83 | | |
84 | | static INLINE vpx_prob mode_mv_merge_probs(vpx_prob pre_prob, |
85 | 9.94M | const unsigned int ct[2]) { |
86 | 9.94M | const unsigned int den = ct[0] + ct[1]; |
87 | 9.94M | if (den == 0) { |
88 | 7.68M | return pre_prob; |
89 | 7.68M | } else { |
90 | 2.25M | const unsigned int count = VPXMIN(den, MODE_MV_COUNT_SAT); |
91 | 2.25M | const unsigned int factor = count_to_update_factor[count]; |
92 | 2.25M | const vpx_prob prob = get_prob(ct[0], den); |
93 | 2.25M | return weighted_prob(pre_prob, prob, factor); |
94 | 2.25M | } |
95 | 9.94M | } Unexecuted instantiation: vp9_dx_iface.c:mode_mv_merge_probs Unexecuted instantiation: vp9_decodeframe.c:mode_mv_merge_probs Unexecuted instantiation: vp9_detokenize.c:mode_mv_merge_probs Unexecuted instantiation: vp9_decoder.c:mode_mv_merge_probs Unexecuted instantiation: vp9_dsubexp.c:mode_mv_merge_probs Unexecuted instantiation: yv12config.c:mode_mv_merge_probs prob.c:mode_mv_merge_probs Line | Count | Source | 85 | 8.12M | const unsigned int ct[2]) { | 86 | 8.12M | const unsigned int den = ct[0] + ct[1]; | 87 | 8.12M | if (den == 0) { | 88 | 6.30M | return pre_prob; | 89 | 6.30M | } else { | 90 | 1.82M | const unsigned int count = VPXMIN(den, MODE_MV_COUNT_SAT); | 91 | 1.82M | const unsigned int factor = count_to_update_factor[count]; | 92 | 1.82M | const vpx_prob prob = get_prob(ct[0], den); | 93 | 1.82M | return weighted_prob(pre_prob, prob, factor); | 94 | 1.82M | } | 95 | 8.12M | } |
Unexecuted instantiation: bitreader.c:mode_mv_merge_probs Unexecuted instantiation: vp9_alloccommon.c:mode_mv_merge_probs Unexecuted instantiation: vp9_blockd.c:mode_mv_merge_probs Unexecuted instantiation: vp9_entropy.c:mode_mv_merge_probs vp9_entropymode.c:mode_mv_merge_probs Line | Count | Source | 85 | 1.01M | const unsigned int ct[2]) { | 86 | 1.01M | const unsigned int den = ct[0] + ct[1]; | 87 | 1.01M | if (den == 0) { | 88 | 712k | return pre_prob; | 89 | 712k | } else { | 90 | 298k | const unsigned int count = VPXMIN(den, MODE_MV_COUNT_SAT); | 91 | 298k | const unsigned int factor = count_to_update_factor[count]; | 92 | 298k | const vpx_prob prob = get_prob(ct[0], den); | 93 | 298k | return weighted_prob(pre_prob, prob, factor); | 94 | 298k | } | 95 | 1.01M | } |
vp9_entropymv.c:mode_mv_merge_probs Line | Count | Source | 85 | 807k | const unsigned int ct[2]) { | 86 | 807k | const unsigned int den = ct[0] + ct[1]; | 87 | 807k | if (den == 0) { | 88 | 671k | return pre_prob; | 89 | 671k | } else { | 90 | 135k | const unsigned int count = VPXMIN(den, MODE_MV_COUNT_SAT); | 91 | 135k | const unsigned int factor = count_to_update_factor[count]; | 92 | 135k | const vpx_prob prob = get_prob(ct[0], den); | 93 | 135k | return weighted_prob(pre_prob, prob, factor); | 94 | 135k | } | 95 | 807k | } |
Unexecuted instantiation: vp9_idct.c:mode_mv_merge_probs Unexecuted instantiation: vp9_pred_common.c:mode_mv_merge_probs Unexecuted instantiation: vp9_seg_common.c:mode_mv_merge_probs Unexecuted instantiation: vp9_tile_common.c:mode_mv_merge_probs Unexecuted instantiation: vp9_loopfilter.c:mode_mv_merge_probs Unexecuted instantiation: vp9_thread_common.c:mode_mv_merge_probs Unexecuted instantiation: vp9_quant_common.c:mode_mv_merge_probs Unexecuted instantiation: vp9_reconinter.c:mode_mv_merge_probs Unexecuted instantiation: vp9_reconintra.c:mode_mv_merge_probs Unexecuted instantiation: vp9_scan.c:mode_mv_merge_probs Unexecuted instantiation: vp9_decodemv.c:mode_mv_merge_probs |
96 | | |
97 | | void vpx_tree_merge_probs(const vpx_tree_index *tree, const vpx_prob *pre_probs, |
98 | | const unsigned int *counts, vpx_prob *probs); |
99 | | |
100 | | DECLARE_ALIGNED(16, extern const uint8_t, vpx_norm[256]); |
101 | | |
102 | | #ifdef __cplusplus |
103 | | } // extern "C" |
104 | | #endif |
105 | | |
106 | | #endif // VPX_VPX_DSP_PROB_H_ |