/src/libvpx/vp8/encoder/boolhuff.h
Line | Count | Source |
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 | 163M | struct vpx_internal_error_info *error) { |
50 | 163M | if (start + len > start && start + len < end) { |
51 | 163M | return 1; |
52 | 163M | } else { |
53 | 3 | vpx_internal_error(error, VPX_CODEC_CORRUPT_FRAME, |
54 | 3 | "Truncated packet or corrupt partition "); |
55 | 3 | } |
56 | | |
57 | 3 | return 0; |
58 | 163M | } 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 | 160M | struct vpx_internal_error_info *error) { | 50 | 160M | if (start + len > start && start + len < end) { | 51 | 160M | return 1; | 52 | 160M | } else { | 53 | 3 | vpx_internal_error(error, VPX_CODEC_CORRUPT_FRAME, | 54 | 3 | "Truncated packet or corrupt partition "); | 55 | 3 | } | 56 | | | 57 | 3 | return 0; | 58 | 160M | } |
boolhuff.c:validate_buffer Line | Count | Source | 49 | 2.90M | struct vpx_internal_error_info *error) { | 50 | 2.90M | if (start + len > start && start + len < end) { | 51 | 2.90M | return 1; | 52 | 2.90M | } 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.90M | } |
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 | 703k | struct vpx_internal_error_info *error) { | 50 | 703k | if (start + len > start && start + len < end) { | 51 | 703k | return 1; | 52 | 703k | } 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 | 703k | } |
Unexecuted instantiation: firstpass.c:validate_buffer Unexecuted instantiation: mcomp.c:validate_buffer Unexecuted instantiation: modecosts.c:validate_buffer |
59 | 188M | static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) { |
60 | 188M | unsigned int split; |
61 | 188M | int count = bc->count; |
62 | 188M | unsigned int range = bc->range; |
63 | 188M | unsigned int lowvalue = bc->lowvalue; |
64 | 188M | int shift; |
65 | | |
66 | 188M | split = 1 + (((range - 1) * probability) >> 8); |
67 | | |
68 | 188M | range = split; |
69 | | |
70 | 188M | if (bit) { |
71 | 30.1M | lowvalue += split; |
72 | 30.1M | range = bc->range - split; |
73 | 30.1M | } |
74 | | |
75 | 188M | shift = vp8_norm[range]; |
76 | | |
77 | 188M | range <<= shift; |
78 | 188M | count += shift; |
79 | | |
80 | 188M | if (count >= 0) { |
81 | 8.62M | int offset = shift - count; |
82 | | |
83 | 8.62M | if ((lowvalue << (offset - 1)) & 0x80000000) { |
84 | 524 | int x = bc->pos - 1; |
85 | | |
86 | 2.43k | while (x >= 0 && bc->buffer[x] == 0xff) { |
87 | 1.91k | bc->buffer[x] = (unsigned char)0; |
88 | 1.91k | x--; |
89 | 1.91k | } |
90 | | |
91 | 524 | bc->buffer[x] += 1; |
92 | 524 | } |
93 | | |
94 | 8.62M | validate_buffer(bc->buffer + bc->pos, 1, bc->buffer_end, bc->error); |
95 | 8.62M | bc->buffer[bc->pos++] = (lowvalue >> (24 - offset) & 0xff); |
96 | | |
97 | 8.62M | shift = count; |
98 | 8.62M | lowvalue = (int)(((uint64_t)lowvalue << offset) & 0xffffff); |
99 | 8.62M | count -= 8; |
100 | 8.62M | } |
101 | | |
102 | 188M | lowvalue <<= shift; |
103 | 188M | bc->count = count; |
104 | 188M | bc->lowvalue = lowvalue; |
105 | 188M | bc->range = range; |
106 | 188M | } 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 | 151M | static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) { | 60 | 151M | unsigned int split; | 61 | 151M | int count = bc->count; | 62 | 151M | unsigned int range = bc->range; | 63 | 151M | unsigned int lowvalue = bc->lowvalue; | 64 | 151M | int shift; | 65 | | | 66 | 151M | split = 1 + (((range - 1) * probability) >> 8); | 67 | | | 68 | 151M | range = split; | 69 | | | 70 | 151M | if (bit) { | 71 | 20.0M | lowvalue += split; | 72 | 20.0M | range = bc->range - split; | 73 | 20.0M | } | 74 | | | 75 | 151M | shift = vp8_norm[range]; | 76 | | | 77 | 151M | range <<= shift; | 78 | 151M | count += shift; | 79 | | | 80 | 151M | if (count >= 0) { | 81 | 5.01M | int offset = shift - count; | 82 | | | 83 | 5.01M | if ((lowvalue << (offset - 1)) & 0x80000000) { | 84 | 472 | int x = bc->pos - 1; | 85 | | | 86 | 2.27k | while (x >= 0 && bc->buffer[x] == 0xff) { | 87 | 1.80k | bc->buffer[x] = (unsigned char)0; | 88 | 1.80k | x--; | 89 | 1.80k | } | 90 | | | 91 | 472 | bc->buffer[x] += 1; | 92 | 472 | } | 93 | | | 94 | 5.01M | validate_buffer(bc->buffer + bc->pos, 1, bc->buffer_end, bc->error); | 95 | 5.01M | bc->buffer[bc->pos++] = (lowvalue >> (24 - offset) & 0xff); | 96 | | | 97 | 5.01M | shift = count; | 98 | 5.01M | lowvalue = (int)(((uint64_t)lowvalue << offset) & 0xffffff); | 99 | 5.01M | count -= 8; | 100 | 5.01M | } | 101 | | | 102 | 151M | lowvalue <<= shift; | 103 | 151M | bc->count = count; | 104 | 151M | bc->lowvalue = lowvalue; | 105 | 151M | bc->range = range; | 106 | 151M | } |
boolhuff.c:vp8_encode_bool Line | Count | Source | 59 | 25.7M | static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) { | 60 | 25.7M | unsigned int split; | 61 | 25.7M | int count = bc->count; | 62 | 25.7M | unsigned int range = bc->range; | 63 | 25.7M | unsigned int lowvalue = bc->lowvalue; | 64 | 25.7M | int shift; | 65 | | | 66 | 25.7M | split = 1 + (((range - 1) * probability) >> 8); | 67 | | | 68 | 25.7M | range = split; | 69 | | | 70 | 25.7M | if (bit) { | 71 | 7.62M | lowvalue += split; | 72 | 7.62M | range = bc->range - split; | 73 | 7.62M | } | 74 | | | 75 | 25.7M | shift = vp8_norm[range]; | 76 | | | 77 | 25.7M | range <<= shift; | 78 | 25.7M | count += shift; | 79 | | | 80 | 25.7M | if (count >= 0) { | 81 | 2.90M | int offset = shift - count; | 82 | | | 83 | 2.90M | if ((lowvalue << (offset - 1)) & 0x80000000) { | 84 | 18 | int x = bc->pos - 1; | 85 | | | 86 | 42 | while (x >= 0 && bc->buffer[x] == 0xff) { | 87 | 24 | bc->buffer[x] = (unsigned char)0; | 88 | 24 | x--; | 89 | 24 | } | 90 | | | 91 | 18 | bc->buffer[x] += 1; | 92 | 18 | } | 93 | | | 94 | 2.90M | validate_buffer(bc->buffer + bc->pos, 1, bc->buffer_end, bc->error); | 95 | 2.90M | bc->buffer[bc->pos++] = (lowvalue >> (24 - offset) & 0xff); | 96 | | | 97 | 2.90M | shift = count; | 98 | 2.90M | lowvalue = (int)(((uint64_t)lowvalue << offset) & 0xffffff); | 99 | 2.90M | count -= 8; | 100 | 2.90M | } | 101 | | | 102 | 25.7M | lowvalue <<= shift; | 103 | 25.7M | bc->count = count; | 104 | 25.7M | bc->lowvalue = lowvalue; | 105 | 25.7M | bc->range = range; | 106 | 25.7M | } |
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 | 11.1M | static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) { | 60 | 11.1M | unsigned int split; | 61 | 11.1M | int count = bc->count; | 62 | 11.1M | unsigned int range = bc->range; | 63 | 11.1M | unsigned int lowvalue = bc->lowvalue; | 64 | 11.1M | int shift; | 65 | | | 66 | 11.1M | split = 1 + (((range - 1) * probability) >> 8); | 67 | | | 68 | 11.1M | range = split; | 69 | | | 70 | 11.1M | if (bit) { | 71 | 2.42M | lowvalue += split; | 72 | 2.42M | range = bc->range - split; | 73 | 2.42M | } | 74 | | | 75 | 11.1M | shift = vp8_norm[range]; | 76 | | | 77 | 11.1M | range <<= shift; | 78 | 11.1M | count += shift; | 79 | | | 80 | 11.1M | if (count >= 0) { | 81 | 703k | int offset = shift - count; | 82 | | | 83 | 703k | if ((lowvalue << (offset - 1)) & 0x80000000) { | 84 | 34 | int x = bc->pos - 1; | 85 | | | 86 | 116 | while (x >= 0 && bc->buffer[x] == 0xff) { | 87 | 82 | bc->buffer[x] = (unsigned char)0; | 88 | 82 | x--; | 89 | 82 | } | 90 | | | 91 | 34 | bc->buffer[x] += 1; | 92 | 34 | } | 93 | | | 94 | 703k | validate_buffer(bc->buffer + bc->pos, 1, bc->buffer_end, bc->error); | 95 | 703k | bc->buffer[bc->pos++] = (lowvalue >> (24 - offset) & 0xff); | 96 | | | 97 | 703k | shift = count; | 98 | 703k | lowvalue = (int)(((uint64_t)lowvalue << offset) & 0xffffff); | 99 | 703k | count -= 8; | 100 | 703k | } | 101 | | | 102 | 11.1M | lowvalue <<= shift; | 103 | 11.1M | bc->count = count; | 104 | 11.1M | bc->lowvalue = lowvalue; | 105 | 11.1M | bc->range = range; | 106 | 11.1M | } |
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_ |