• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 one-pass processing: when we find a backward
9    match, we immediately emit the corresponding command and literal codes to
10    the bit stream. */
11 
12 #ifndef BROTLI_ENC_COMPRESS_FRAGMENT_H_
13 #define BROTLI_ENC_COMPRESS_FRAGMENT_H_
14 
15 #include <brotli/types.h>
16 
17 #include "../common/constants.h"
18 #include "../common/platform.h"
19 #include "entropy_encode.h"
20 
21 #if defined(__cplusplus) || defined(c_plusplus)
22 extern "C" {
23 #endif
24 
25 typedef struct BrotliOnePassArena {
26   uint8_t lit_depth[256];
27   uint16_t lit_bits[256];
28 
29   /* Command and distance prefix codes (each 64 symbols, stored back-to-back)
30      used for the next block. The command prefix code is over a smaller alphabet
31      with the following 64 symbols:
32         0 - 15: insert length code 0, copy length code 0 - 15, same distance
33        16 - 39: insert length code 0, copy length code 0 - 23
34        40 - 63: insert length code 0 - 23, copy length code 0
35      Note that symbols 16 and 40 represent the same code in the full alphabet,
36      but we do not use either of them. */
37   uint8_t cmd_depth[128];
38   uint16_t cmd_bits[128];
39   uint32_t cmd_histo[128];
40 
41   /* The compressed form of the command and distance prefix codes for the next
42      block. */
43   uint8_t cmd_code[512];
44   size_t cmd_code_numbits;
45 
46   HuffmanTree tree[2 * BROTLI_NUM_LITERAL_SYMBOLS + 1];
47   uint32_t histogram[256];
48   uint8_t tmp_depth[BROTLI_NUM_COMMAND_SYMBOLS];
49   uint16_t tmp_bits[64];
50 } BrotliOnePassArena;
51 
52 /* Compresses "input" string to the "*storage" buffer as one or more complete
53    meta-blocks, and updates the "*storage_ix" bit position.
54 
55    If "is_last" is 1, emits an additional empty last meta-block.
56 
57    "cmd_depth" and "cmd_bits" contain the command and distance prefix codes
58    (see comment in encode.h) used for the encoding of this input fragment.
59    If "is_last" is 0, they are updated to reflect the statistics
60    of this input fragment, to be used for the encoding of the next fragment.
61 
62    "*cmd_code_numbits" is the number of bits of the compressed representation
63    of the command and distance prefix codes, and "cmd_code" is an array of
64    at least "(*cmd_code_numbits + 7) >> 3" size that contains the compressed
65    command and distance prefix codes. If "is_last" is 0, these are also
66    updated to represent the updated "cmd_depth" and "cmd_bits".
67 
68    REQUIRES: "input_size" is greater than zero, or "is_last" is 1.
69    REQUIRES: "input_size" is less or equal to maximal metablock size (1 << 24).
70    REQUIRES: All elements in "table[0..table_size-1]" are initialized to zero.
71    REQUIRES: "table_size" is an odd (9, 11, 13, 15) power of two
72    OUTPUT: maximal copy distance <= |input_size|
73    OUTPUT: maximal copy distance <= BROTLI_MAX_BACKWARD_LIMIT(18) */
74 BROTLI_INTERNAL void BrotliCompressFragmentFast(BrotliOnePassArena* s,
75                                                 const uint8_t* input,
76                                                 size_t input_size,
77                                                 BROTLI_BOOL is_last,
78                                                 int* table, size_t table_size,
79                                                 size_t* storage_ix,
80                                                 uint8_t* storage);
81 
82 #if defined(__cplusplus) || defined(c_plusplus)
83 }  /* extern "C" */
84 #endif
85 
86 #endif  /* BROTLI_ENC_COMPRESS_FRAGMENT_H_ */
87