Debian Codegraph @

libs/brotli/enc/compress_fragment_two_pass.h

raw
1 /* Copyright 2015 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 /* Function for fast encoding of an input fragment, independently from the input
8 history. This function uses two-pass processing: in the first pass we save
9 the found backward matches and literal bytes into a buffer, and in the
10 second pass we emit them into the bit stream using prefix codes built based
11 on the actual command and literal byte histograms. */
12
13 #ifndef BROTLI_ENC_COMPRESS_FRAGMENT_TWO_PASS_H_
14 #define BROTLI_ENC_COMPRESS_FRAGMENT_TWO_PASS_H_
15
16 #include "../common/constants.h"
17 #include "../common/platform.h"
18 #include "entropy_encode.h"
19
20 #if defined(__cplusplus) || defined(c_plusplus)
21 extern "C" {
22 #endif
23
24 /* TODO(eustas): turn to macro. */
25 static const size_t kCompressFragmentTwoPassBlockSize = 1 << 17;
26
27 typedef struct BrotliTwoPassArena {
28 uint32_t lit_histo[256];
29 uint8_t lit_depth[256];
30 uint16_t lit_bits[256];
31
32 uint32_t cmd_histo[128];
33 uint8_t cmd_depth[128];
34 uint16_t cmd_bits[128];
35
36 /* BuildAndStoreCommandPrefixCode */
37 HuffmanTree tmp_tree[2 * BROTLI_NUM_LITERAL_SYMBOLS + 1];
38 uint8_t tmp_depth[BROTLI_NUM_COMMAND_SYMBOLS];
39 uint16_t tmp_bits[64];
40 } BrotliTwoPassArena;
41
42 /* Compresses "input" string to the "*storage" buffer as one or more complete
43 meta-blocks, and updates the "*storage_ix" bit position.
44
45 If "is_last" is 1, emits an additional empty last meta-block.
46
47 REQUIRES: "input_size" is greater than zero, or "is_last" is 1.
48 REQUIRES: "input_size" is less or equal to maximal metablock size (1 << 24).
49 REQUIRES: "command_buf" and "literal_buf" point to at least
50 kCompressFragmentTwoPassBlockSize long arrays.
51 REQUIRES: All elements in "table[0..table_size-1]" are initialized to zero.
52 REQUIRES: "table_size" is a power of two
53 OUTPUT: maximal copy distance <= |input_size|
54 OUTPUT: maximal copy distance <= BROTLI_MAX_BACKWARD_LIMIT(18) */
55 BROTLI_INTERNAL void BrotliCompressFragmentTwoPass(BrotliTwoPassArena* s,
56 const uint8_t* input,
57 size_t input_size,
58 BROTLI_BOOL is_last,
59 uint32_t* command_buf,
60 uint8_t* literal_buf,
61 int* table,
62 size_t table_size,
63 size_t* storage_ix,
64 uint8_t* storage);
65
66 #if defined(__cplusplus) || defined(c_plusplus)
67 } /* extern "C" */
68 #endif
69
70 #endif /* BROTLI_ENC_COMPRESS_FRAGMENT_TWO_PASS_H_ */