/src/libvpx/vp8/encoder/boolhuff.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2010 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 | | /**************************************************************************** |
12 | | * |
13 | | * Module Title : boolhuff.h |
14 | | * |
15 | | * Description : Bool Coder header file. |
16 | | * |
17 | | ****************************************************************************/ |
18 | | #ifndef VPX_VP8_ENCODER_BOOLHUFF_H_ |
19 | | #define VPX_VP8_ENCODER_BOOLHUFF_H_ |
20 | | |
21 | | #include "vpx_ports/mem.h" |
22 | | #include "vpx/internal/vpx_codec_internal.h" |
23 | | |
24 | | #ifdef __cplusplus |
25 | | extern "C" { |
26 | | #endif |
27 | | |
28 | | typedef struct { |
29 | | unsigned int lowvalue; |
30 | | unsigned int range; |
31 | | int count; |
32 | | unsigned int pos; |
33 | | unsigned char *buffer; |
34 | | unsigned char *buffer_end; |
35 | | struct vpx_internal_error_info *error; |
36 | | } BOOL_CODER; |
37 | | |
38 | | void vp8_start_encode(BOOL_CODER *bc, unsigned char *source, |
39 | | unsigned char *source_end); |
40 | | |
41 | | void vp8_encode_value(BOOL_CODER *bc, int data, int bits); |
42 | | void vp8_stop_encode(BOOL_CODER *bc); |
43 | | extern const unsigned int vp8_prob_cost[256]; |
44 | | |
45 | | DECLARE_ALIGNED(16, extern const unsigned char, vp8_norm[256]); |
46 | | |
47 | | static int validate_buffer(const unsigned char *start, size_t len, |
48 | | const unsigned char *end, |
49 | 229M | struct vpx_internal_error_info *error) { |
50 | 229M | if (start + len > start && start + len < end) { |
51 | 229M | return 1; |
52 | 229M | } else { |
53 | 0 | vpx_internal_error(error, VPX_CODEC_CORRUPT_FRAME, |
54 | 0 | "Truncated packet or corrupt partition "); |
55 | 0 | } |
56 | | |
57 | 0 | return 0; |
58 | 229M | } Unexecuted instantiation: vp8_cx_iface.c:validate_buffer Unexecuted instantiation: ethreading.c:validate_buffer Unexecuted instantiation: onyx_if.c:validate_buffer Unexecuted instantiation: pickinter.c:validate_buffer Unexecuted instantiation: picklpf.c:validate_buffer Unexecuted instantiation: vp8_quantize.c:validate_buffer Unexecuted instantiation: ratectrl.c:validate_buffer Unexecuted instantiation: rdopt.c:validate_buffer Unexecuted instantiation: segmentation.c:validate_buffer Unexecuted instantiation: vp8_skin_detection.c:validate_buffer Unexecuted instantiation: tokenize.c:validate_buffer Unexecuted instantiation: treewriter.c:validate_buffer Unexecuted instantiation: temporal_filter.c:validate_buffer bitstream.c:validate_buffer Line | Count | Source | 49 | 226M | struct vpx_internal_error_info *error) { | 50 | 226M | if (start + len > start && start + len < end) { | 51 | 226M | return 1; | 52 | 226M | } else { | 53 | 0 | vpx_internal_error(error, VPX_CODEC_CORRUPT_FRAME, | 54 | 0 | "Truncated packet or corrupt partition "); | 55 | 0 | } | 56 | | | 57 | 0 | return 0; | 58 | 226M | } |
boolhuff.c:validate_buffer Line | Count | Source | 49 | 2.53M | struct vpx_internal_error_info *error) { | 50 | 2.53M | if (start + len > start && start + len < end) { | 51 | 2.53M | return 1; | 52 | 2.53M | } else { | 53 | 0 | vpx_internal_error(error, VPX_CODEC_CORRUPT_FRAME, | 54 | 0 | "Truncated packet or corrupt partition "); | 55 | 0 | } | 56 | | | 57 | 0 | return 0; | 58 | 2.53M | } |
Unexecuted instantiation: encodeframe.c:validate_buffer Unexecuted instantiation: encodeintra.c:validate_buffer Unexecuted instantiation: encodemb.c:validate_buffer encodemv.c:validate_buffer Line | Count | Source | 49 | 670k | struct vpx_internal_error_info *error) { | 50 | 670k | if (start + len > start && start + len < end) { | 51 | 670k | return 1; | 52 | 670k | } else { | 53 | 0 | vpx_internal_error(error, VPX_CODEC_CORRUPT_FRAME, | 54 | 0 | "Truncated packet or corrupt partition "); | 55 | 0 | } | 56 | | | 57 | 0 | return 0; | 58 | 670k | } |
Unexecuted instantiation: firstpass.c:validate_buffer Unexecuted instantiation: mcomp.c:validate_buffer Unexecuted instantiation: modecosts.c:validate_buffer |
59 | 147M | static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) { |
60 | 147M | unsigned int split; |
61 | 147M | int count = bc->count; |
62 | 147M | unsigned int range = bc->range; |
63 | 147M | unsigned int lowvalue = bc->lowvalue; |
64 | 147M | int shift; |
65 | | |
66 | 147M | split = 1 + (((range - 1) * probability) >> 8); |
67 | | |
68 | 147M | range = split; |
69 | | |
70 | 147M | if (bit) { |
71 | 33.6M | lowvalue += split; |
72 | 33.6M | range = bc->range - split; |
73 | 33.6M | } |
74 | | |
75 | 147M | shift = vp8_norm[range]; |
76 | | |
77 | 147M | range <<= shift; |
78 | 147M | count += shift; |
79 | | |
80 | 147M | if (count >= 0) { |
81 | 9.14M | int offset = shift - count; |
82 | | |
83 | 9.14M | if ((lowvalue << (offset - 1)) & 0x80000000) { |
84 | 362 | int x = bc->pos - 1; |
85 | | |
86 | 2.07k | while (x >= 0 && bc->buffer[x] == 0xff) { |
87 | 1.71k | bc->buffer[x] = (unsigned char)0; |
88 | 1.71k | x--; |
89 | 1.71k | } |
90 | | |
91 | 362 | bc->buffer[x] += 1; |
92 | 362 | } |
93 | | |
94 | 9.14M | validate_buffer(bc->buffer + bc->pos, 1, bc->buffer_end, bc->error); |
95 | 9.14M | bc->buffer[bc->pos++] = (lowvalue >> (24 - offset) & 0xff); |
96 | | |
97 | 9.14M | shift = count; |
98 | 9.14M | lowvalue = (int)(((uint64_t)lowvalue << offset) & 0xffffff); |
99 | 9.14M | count -= 8; |
100 | 9.14M | } |
101 | | |
102 | 147M | lowvalue <<= shift; |
103 | 147M | bc->count = count; |
104 | 147M | bc->lowvalue = lowvalue; |
105 | 147M | bc->range = range; |
106 | 147M | } Unexecuted instantiation: vp8_cx_iface.c:vp8_encode_bool Unexecuted instantiation: ethreading.c:vp8_encode_bool Unexecuted instantiation: onyx_if.c:vp8_encode_bool Unexecuted instantiation: pickinter.c:vp8_encode_bool Unexecuted instantiation: picklpf.c:vp8_encode_bool Unexecuted instantiation: vp8_quantize.c:vp8_encode_bool Unexecuted instantiation: ratectrl.c:vp8_encode_bool Unexecuted instantiation: rdopt.c:vp8_encode_bool Unexecuted instantiation: segmentation.c:vp8_encode_bool Unexecuted instantiation: vp8_skin_detection.c:vp8_encode_bool Unexecuted instantiation: tokenize.c:vp8_encode_bool Unexecuted instantiation: treewriter.c:vp8_encode_bool Unexecuted instantiation: temporal_filter.c:vp8_encode_bool bitstream.c:vp8_encode_bool Line | Count | Source | 59 | 116M | static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) { | 60 | 116M | unsigned int split; | 61 | 116M | int count = bc->count; | 62 | 116M | unsigned int range = bc->range; | 63 | 116M | unsigned int lowvalue = bc->lowvalue; | 64 | 116M | int shift; | 65 | | | 66 | 116M | split = 1 + (((range - 1) * probability) >> 8); | 67 | | | 68 | 116M | range = split; | 69 | | | 70 | 116M | if (bit) { | 71 | 23.9M | lowvalue += split; | 72 | 23.9M | range = bc->range - split; | 73 | 23.9M | } | 74 | | | 75 | 116M | shift = vp8_norm[range]; | 76 | | | 77 | 116M | range <<= shift; | 78 | 116M | count += shift; | 79 | | | 80 | 116M | if (count >= 0) { | 81 | 5.94M | int offset = shift - count; | 82 | | | 83 | 5.94M | if ((lowvalue << (offset - 1)) & 0x80000000) { | 84 | 343 | int x = bc->pos - 1; | 85 | | | 86 | 1.95k | while (x >= 0 && bc->buffer[x] == 0xff) { | 87 | 1.61k | bc->buffer[x] = (unsigned char)0; | 88 | 1.61k | x--; | 89 | 1.61k | } | 90 | | | 91 | 343 | bc->buffer[x] += 1; | 92 | 343 | } | 93 | | | 94 | 5.94M | validate_buffer(bc->buffer + bc->pos, 1, bc->buffer_end, bc->error); | 95 | 5.94M | bc->buffer[bc->pos++] = (lowvalue >> (24 - offset) & 0xff); | 96 | | | 97 | 5.94M | shift = count; | 98 | 5.94M | lowvalue = (int)(((uint64_t)lowvalue << offset) & 0xffffff); | 99 | 5.94M | count -= 8; | 100 | 5.94M | } | 101 | | | 102 | 116M | lowvalue <<= shift; | 103 | 116M | bc->count = count; | 104 | 116M | bc->lowvalue = lowvalue; | 105 | 116M | bc->range = range; | 106 | 116M | } |
boolhuff.c:vp8_encode_bool Line | Count | Source | 59 | 21.8M | static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) { | 60 | 21.8M | unsigned int split; | 61 | 21.8M | int count = bc->count; | 62 | 21.8M | unsigned int range = bc->range; | 63 | 21.8M | unsigned int lowvalue = bc->lowvalue; | 64 | 21.8M | int shift; | 65 | | | 66 | 21.8M | split = 1 + (((range - 1) * probability) >> 8); | 67 | | | 68 | 21.8M | range = split; | 69 | | | 70 | 21.8M | if (bit) { | 71 | 7.27M | lowvalue += split; | 72 | 7.27M | range = bc->range - split; | 73 | 7.27M | } | 74 | | | 75 | 21.8M | shift = vp8_norm[range]; | 76 | | | 77 | 21.8M | range <<= shift; | 78 | 21.8M | count += shift; | 79 | | | 80 | 21.8M | if (count >= 0) { | 81 | 2.53M | int offset = shift - count; | 82 | | | 83 | 2.53M | if ((lowvalue << (offset - 1)) & 0x80000000) { | 84 | 6 | int x = bc->pos - 1; | 85 | | | 86 | 25 | while (x >= 0 && bc->buffer[x] == 0xff) { | 87 | 19 | bc->buffer[x] = (unsigned char)0; | 88 | 19 | x--; | 89 | 19 | } | 90 | | | 91 | 6 | bc->buffer[x] += 1; | 92 | 6 | } | 93 | | | 94 | 2.53M | validate_buffer(bc->buffer + bc->pos, 1, bc->buffer_end, bc->error); | 95 | 2.53M | bc->buffer[bc->pos++] = (lowvalue >> (24 - offset) & 0xff); | 96 | | | 97 | 2.53M | shift = count; | 98 | 2.53M | lowvalue = (int)(((uint64_t)lowvalue << offset) & 0xffffff); | 99 | 2.53M | count -= 8; | 100 | 2.53M | } | 101 | | | 102 | 21.8M | lowvalue <<= shift; | 103 | 21.8M | bc->count = count; | 104 | 21.8M | bc->lowvalue = lowvalue; | 105 | 21.8M | bc->range = range; | 106 | 21.8M | } |
Unexecuted instantiation: encodeframe.c:vp8_encode_bool Unexecuted instantiation: encodeintra.c:vp8_encode_bool Unexecuted instantiation: encodemb.c:vp8_encode_bool encodemv.c:vp8_encode_bool Line | Count | Source | 59 | 9.41M | static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) { | 60 | 9.41M | unsigned int split; | 61 | 9.41M | int count = bc->count; | 62 | 9.41M | unsigned int range = bc->range; | 63 | 9.41M | unsigned int lowvalue = bc->lowvalue; | 64 | 9.41M | int shift; | 65 | | | 66 | 9.41M | split = 1 + (((range - 1) * probability) >> 8); | 67 | | | 68 | 9.41M | range = split; | 69 | | | 70 | 9.41M | if (bit) { | 71 | 2.34M | lowvalue += split; | 72 | 2.34M | range = bc->range - split; | 73 | 2.34M | } | 74 | | | 75 | 9.41M | shift = vp8_norm[range]; | 76 | | | 77 | 9.41M | range <<= shift; | 78 | 9.41M | count += shift; | 79 | | | 80 | 9.41M | if (count >= 0) { | 81 | 670k | int offset = shift - count; | 82 | | | 83 | 670k | if ((lowvalue << (offset - 1)) & 0x80000000) { | 84 | 13 | int x = bc->pos - 1; | 85 | | | 86 | 91 | while (x >= 0 && bc->buffer[x] == 0xff) { | 87 | 78 | bc->buffer[x] = (unsigned char)0; | 88 | 78 | x--; | 89 | 78 | } | 90 | | | 91 | 13 | bc->buffer[x] += 1; | 92 | 13 | } | 93 | | | 94 | 670k | validate_buffer(bc->buffer + bc->pos, 1, bc->buffer_end, bc->error); | 95 | 670k | bc->buffer[bc->pos++] = (lowvalue >> (24 - offset) & 0xff); | 96 | | | 97 | 670k | shift = count; | 98 | 670k | lowvalue = (int)(((uint64_t)lowvalue << offset) & 0xffffff); | 99 | 670k | count -= 8; | 100 | 670k | } | 101 | | | 102 | 9.41M | lowvalue <<= shift; | 103 | 9.41M | bc->count = count; | 104 | 9.41M | bc->lowvalue = lowvalue; | 105 | 9.41M | bc->range = range; | 106 | 9.41M | } |
Unexecuted instantiation: firstpass.c:vp8_encode_bool Unexecuted instantiation: mcomp.c:vp8_encode_bool Unexecuted instantiation: modecosts.c:vp8_encode_bool |
107 | | |
108 | | #ifdef __cplusplus |
109 | | } // extern "C" |
110 | | #endif |
111 | | |
112 | | #endif // VPX_VP8_ENCODER_BOOLHUFF_H_ |