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/platform.h"
17#include <brotli/types.h>
18#include "./memory.h"
19
20#if defined(__cplusplus) || defined(c_plusplus)
21extern "C" {
22#endif
23
24static const size_t kCompressFragmentTwoPassBlockSize = 1 << 17;
25
26/* Compresses "input" string to the "*storage" buffer as one or more complete
27   meta-blocks, and updates the "*storage_ix" bit position.
28
29   If "is_last" is 1, emits an additional empty last meta-block.
30
31   REQUIRES: "input_size" is greater than zero, or "is_last" is 1.
32   REQUIRES: "input_size" is less or equal to maximal metablock size (1 << 24).
33   REQUIRES: "command_buf" and "literal_buf" point to at least
34              kCompressFragmentTwoPassBlockSize long arrays.
35   REQUIRES: All elements in "table[0..table_size-1]" are initialized to zero.
36   REQUIRES: "table_size" is a power of two
37   OUTPUT: maximal copy distance <= |input_size|
38   OUTPUT: maximal copy distance <= BROTLI_MAX_BACKWARD_LIMIT(18) */
39BROTLI_INTERNAL void BrotliCompressFragmentTwoPass(MemoryManager* m,
40                                                   const uint8_t* input,
41                                                   size_t input_size,
42                                                   BROTLI_BOOL is_last,
43                                                   uint32_t* command_buf,
44                                                   uint8_t* literal_buf,
45                                                   int* table,
46                                                   size_t table_size,
47                                                   size_t* storage_ix,
48                                                   uint8_t* storage);
49
50#if defined(__cplusplus) || defined(c_plusplus)
51}  /* extern "C" */
52#endif
53
54#endif  /* BROTLI_ENC_COMPRESS_FRAGMENT_TWO_PASS_H_ */
55