/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 | 873k | #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 | 5.14M | static INLINE vpx_prob get_prob(unsigned int num, unsigned int den) { |
49 | 5.14M | assert(den != 0); |
50 | 5.14M | { |
51 | 5.14M | const int p = (int)(((uint64_t)num * 256 + (den >> 1)) / den); |
52 | | // (p > 255) ? 255 : (p < 1) ? 1 : p; |
53 | 5.14M | const int clipped_prob = p | ((255 - p) >> 23) | (p == 0); |
54 | 5.14M | return (vpx_prob)clipped_prob; |
55 | 5.14M | } |
56 | 5.14M | } 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.96M | static INLINE vpx_prob get_prob(unsigned int num, unsigned int den) { | 49 | 1.96M | assert(den != 0); | 50 | 1.96M | { | 51 | 1.96M | const int p = (int)(((uint64_t)num * 256 + (den >> 1)) / den); | 52 | | // (p > 255) ? 255 : (p < 1) ? 1 : p; | 53 | 1.96M | const int clipped_prob = p | ((255 - p) >> 23) | (p == 0); | 54 | 1.96M | return (vpx_prob)clipped_prob; | 55 | 1.96M | } | 56 | 1.96M | } |
Unexecuted instantiation: bitreader.c:get_prob Unexecuted instantiation: vp9_alloccommon.c:get_prob Unexecuted instantiation: vp9_blockd.c:get_prob Line | Count | Source | 48 | 2.67M | static INLINE vpx_prob get_prob(unsigned int num, unsigned int den) { | 49 | 2.67M | assert(den != 0); | 50 | 2.67M | { | 51 | 2.67M | const int p = (int)(((uint64_t)num * 256 + (den >> 1)) / den); | 52 | | // (p > 255) ? 255 : (p < 1) ? 1 : p; | 53 | 2.67M | const int clipped_prob = p | ((255 - p) >> 23) | (p == 0); | 54 | 2.67M | return (vpx_prob)clipped_prob; | 55 | 2.67M | } | 56 | 2.67M | } |
vp9_entropymode.c:get_prob Line | Count | Source | 48 | 342k | static INLINE vpx_prob get_prob(unsigned int num, unsigned int den) { | 49 | 342k | assert(den != 0); | 50 | 342k | { | 51 | 342k | const int p = (int)(((uint64_t)num * 256 + (den >> 1)) / den); | 52 | | // (p > 255) ? 255 : (p < 1) ? 1 : p; | 53 | 342k | const int clipped_prob = p | ((255 - p) >> 23) | (p == 0); | 54 | 342k | return (vpx_prob)clipped_prob; | 55 | 342k | } | 56 | 342k | } |
Line | Count | Source | 48 | 166k | static INLINE vpx_prob get_prob(unsigned int num, unsigned int den) { | 49 | 166k | assert(den != 0); | 50 | 166k | { | 51 | 166k | const int p = (int)(((uint64_t)num * 256 + (den >> 1)) / den); | 52 | | // (p > 255) ? 255 : (p < 1) ? 1 : p; | 53 | 166k | const int clipped_prob = p | ((255 - p) >> 23) | (p == 0); | 54 | 166k | return (vpx_prob)clipped_prob; | 55 | 166k | } | 56 | 166k | } |
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 | 83.5M | static INLINE vpx_prob get_binary_prob(unsigned int n0, unsigned int n1) { |
59 | 83.5M | const unsigned int den = n0 + n1; |
60 | 83.5M | if (den == 0) return 128u; |
61 | 2.67M | return get_prob(n0, den); |
62 | 83.5M | } 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 | 83.5M | static INLINE vpx_prob get_binary_prob(unsigned int n0, unsigned int n1) { | 59 | 83.5M | const unsigned int den = n0 + n1; | 60 | 83.5M | if (den == 0) return 128u; | 61 | 2.67M | return get_prob(n0, den); | 62 | 83.5M | } |
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 | 85.9M | static INLINE vpx_prob weighted_prob(int prob1, int prob2, int factor) { |
66 | 85.9M | return ROUND_POWER_OF_TWO(prob1 * (256 - factor) + prob2 * factor, 8); |
67 | 85.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.96M | static INLINE vpx_prob weighted_prob(int prob1, int prob2, int factor) { | 66 | 1.96M | return ROUND_POWER_OF_TWO(prob1 * (256 - factor) + prob2 * factor, 8); | 67 | 1.96M | } |
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 | 83.5M | static INLINE vpx_prob weighted_prob(int prob1, int prob2, int factor) { | 66 | 83.5M | return ROUND_POWER_OF_TWO(prob1 * (256 - factor) + prob2 * factor, 8); | 67 | 83.5M | } |
vp9_entropymode.c:weighted_prob Line | Count | Source | 65 | 342k | static INLINE vpx_prob weighted_prob(int prob1, int prob2, int factor) { | 66 | 342k | return ROUND_POWER_OF_TWO(prob1 * (256 - factor) + prob2 * factor, 8); | 67 | 342k | } |
vp9_entropymv.c:weighted_prob Line | Count | Source | 65 | 166k | static INLINE vpx_prob weighted_prob(int prob1, int prob2, int factor) { | 66 | 166k | return ROUND_POWER_OF_TWO(prob1 * (256 - factor) + prob2 * factor, 8); | 67 | 166k | } |
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 | 83.5M | unsigned int max_update_factor) { |
72 | 83.5M | const vpx_prob prob = get_binary_prob(ct[0], ct[1]); |
73 | 83.5M | const unsigned int count = VPXMIN(ct[0] + ct[1], count_sat); |
74 | 83.5M | const unsigned int factor = max_update_factor * count / count_sat; |
75 | 83.5M | return weighted_prob(pre_prob, prob, factor); |
76 | 83.5M | } 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 | 83.5M | unsigned int max_update_factor) { | 72 | 83.5M | const vpx_prob prob = get_binary_prob(ct[0], ct[1]); | 73 | 83.5M | const unsigned int count = VPXMIN(ct[0] + ct[1], count_sat); | 74 | 83.5M | const unsigned int factor = max_update_factor * count / count_sat; | 75 | 83.5M | return weighted_prob(pre_prob, prob, factor); | 76 | 83.5M | } |
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 | 11.4M | const unsigned int ct[2]) { |
86 | 11.4M | const unsigned int den = ct[0] + ct[1]; |
87 | 11.4M | if (den == 0) { |
88 | 8.93M | return pre_prob; |
89 | 8.93M | } else { |
90 | 2.47M | const unsigned int count = VPXMIN(den, MODE_MV_COUNT_SAT); |
91 | 2.47M | const unsigned int factor = count_to_update_factor[count]; |
92 | 2.47M | const vpx_prob prob = get_prob(ct[0], den); |
93 | 2.47M | return weighted_prob(pre_prob, prob, factor); |
94 | 2.47M | } |
95 | 11.4M | } 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 | 9.34M | const unsigned int ct[2]) { | 86 | 9.34M | const unsigned int den = ct[0] + ct[1]; | 87 | 9.34M | if (den == 0) { | 88 | 7.37M | return pre_prob; | 89 | 7.37M | } else { | 90 | 1.96M | const unsigned int count = VPXMIN(den, MODE_MV_COUNT_SAT); | 91 | 1.96M | const unsigned int factor = count_to_update_factor[count]; | 92 | 1.96M | const vpx_prob prob = get_prob(ct[0], den); | 93 | 1.96M | return weighted_prob(pre_prob, prob, factor); | 94 | 1.96M | } | 95 | 9.34M | } |
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.13M | const unsigned int ct[2]) { | 86 | 1.13M | const unsigned int den = ct[0] + ct[1]; | 87 | 1.13M | if (den == 0) { | 88 | 796k | return pre_prob; | 89 | 796k | } else { | 90 | 342k | const unsigned int count = VPXMIN(den, MODE_MV_COUNT_SAT); | 91 | 342k | const unsigned int factor = count_to_update_factor[count]; | 92 | 342k | const vpx_prob prob = get_prob(ct[0], den); | 93 | 342k | return weighted_prob(pre_prob, prob, factor); | 94 | 342k | } | 95 | 1.13M | } |
vp9_entropymv.c:mode_mv_merge_probs Line | Count | Source | 85 | 934k | const unsigned int ct[2]) { | 86 | 934k | const unsigned int den = ct[0] + ct[1]; | 87 | 934k | if (den == 0) { | 88 | 767k | return pre_prob; | 89 | 767k | } else { | 90 | 166k | const unsigned int count = VPXMIN(den, MODE_MV_COUNT_SAT); | 91 | 166k | const unsigned int factor = count_to_update_factor[count]; | 92 | 166k | const vpx_prob prob = get_prob(ct[0], den); | 93 | 166k | return weighted_prob(pre_prob, prob, factor); | 94 | 166k | } | 95 | 934k | } |
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_ |