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