Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: third_party/brotli/enc/prefix.h

Issue 1956893002: Added brotli enc/ and tools/ directories. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated to most recent build tools Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/brotli/enc/port.h ('k') | third_party/brotli/enc/ringbuffer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /* Copyright 2013 Google Inc. All Rights Reserved.
2
3 Distributed under MIT license.
4 See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 */
6
7 // Functions for encoding of integers into prefix codes the amount of extra
8 // bits, and the actual values of the extra bits.
9
10 #ifndef BROTLI_ENC_PREFIX_H_
11 #define BROTLI_ENC_PREFIX_H_
12
13 #include "./fast_log.h"
14 #include "./types.h"
15
16 namespace brotli {
17
18 static const uint32_t kNumInsertLenPrefixes = 24;
19 static const uint32_t kNumCopyLenPrefixes = 24;
20 static const uint32_t kNumCommandPrefixes = 704;
21 static const uint32_t kNumBlockLenPrefixes = 26;
22 static const uint32_t kNumDistanceShortCodes = 16;
23 static const uint32_t kNumDistancePrefixes = 520;
24
25 // Represents the range of values belonging to a prefix code:
26 // [offset, offset + 2^nbits)
27 struct PrefixCodeRange {
28 uint32_t offset;
29 uint32_t nbits;
30 };
31
32 static const PrefixCodeRange kBlockLengthPrefixCode[kNumBlockLenPrefixes] = {
33 { 1, 2}, { 5, 2}, { 9, 2}, { 13, 2},
34 { 17, 3}, { 25, 3}, { 33, 3}, { 41, 3},
35 { 49, 4}, { 65, 4}, { 81, 4}, { 97, 4},
36 { 113, 5}, { 145, 5}, { 177, 5}, { 209, 5},
37 { 241, 6}, { 305, 6}, { 369, 7}, { 497, 8},
38 { 753, 9}, { 1265, 10}, {2289, 11}, {4337, 12},
39 {8433, 13}, {16625, 24}
40 };
41
42 inline void GetBlockLengthPrefixCode(uint32_t len, uint32_t* code,
43 uint32_t* n_extra, uint32_t* extra) {
44 *code = 0;
45 while (*code < 25 && len >= kBlockLengthPrefixCode[*code + 1].offset) {
46 ++(*code);
47 }
48 *n_extra = kBlockLengthPrefixCode[*code].nbits;
49 *extra = len - kBlockLengthPrefixCode[*code].offset;
50 }
51
52 inline void PrefixEncodeCopyDistance(size_t distance_code,
53 size_t num_direct_codes,
54 size_t postfix_bits,
55 uint16_t* code,
56 uint32_t* extra_bits) {
57 if (distance_code < kNumDistanceShortCodes + num_direct_codes) {
58 *code = static_cast<uint16_t>(distance_code);
59 *extra_bits = 0;
60 return;
61 }
62 distance_code -= kNumDistanceShortCodes + num_direct_codes; /* >= 0 */
63 distance_code += (1u << (postfix_bits + 2u)); /* > 0 */
64 size_t bucket = Log2FloorNonZero(distance_code) - 1;
65 size_t postfix_mask = (1 << postfix_bits) - 1;
66 size_t postfix = distance_code & postfix_mask;
67 size_t prefix = (distance_code >> bucket) & 1;
68 size_t offset = (2 + prefix) << bucket;
69 size_t nbits = bucket - postfix_bits;
70 *code = static_cast<uint16_t>(
71 (kNumDistanceShortCodes + num_direct_codes +
72 ((2 * (nbits - 1) + prefix) << postfix_bits) + postfix));
73 *extra_bits = static_cast<uint32_t>(
74 (nbits << 24) | ((distance_code - offset) >> postfix_bits));
75 }
76
77 } // namespace brotli
78
79 #endif // BROTLI_ENC_PREFIX_H_
OLDNEW
« no previous file with comments | « third_party/brotli/enc/port.h ('k') | third_party/brotli/enc/ringbuffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698