| 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/platform.h" |
| 16 | #include <brotli/types.h> |
| 17 | #include "./memory.h" |
| 18 | |
| 19 | #if defined(__cplusplus) || defined(c_plusplus) |
| 20 | extern "C" { |
| 21 | #endif |
| 22 | |
| 23 | /* Compresses "input" string to the "*storage" buffer as one or more complete |
| 24 | meta-blocks, and updates the "*storage_ix" bit position. |
| 25 | |
| 26 | If "is_last" is 1, emits an additional empty last meta-block. |
| 27 | |
| 28 | "cmd_depth" and "cmd_bits" contain the command and distance prefix codes |
| 29 | (see comment in encode.h) used for the encoding of this input fragment. |
| 30 | If "is_last" is 0, they are updated to reflect the statistics |
| 31 | of this input fragment, to be used for the encoding of the next fragment. |
| 32 | |
| 33 | "*cmd_code_numbits" is the number of bits of the compressed representation |
| 34 | of the command and distance prefix codes, and "cmd_code" is an array of |
| 35 | at least "(*cmd_code_numbits + 7) >> 3" size that contains the compressed |
| 36 | command and distance prefix codes. If "is_last" is 0, these are also |
| 37 | updated to represent the updated "cmd_depth" and "cmd_bits". |
| 38 | |
| 39 | REQUIRES: "input_size" is greater than zero, or "is_last" is 1. |
| 40 | REQUIRES: "input_size" is less or equal to maximal metablock size (1 << 24). |
| 41 | REQUIRES: All elements in "table[0..table_size-1]" are initialized to zero. |
| 42 | REQUIRES: "table_size" is an odd (9, 11, 13, 15) power of two |
| 43 | OUTPUT: maximal copy distance <= |input_size| |
| 44 | OUTPUT: maximal copy distance <= BROTLI_MAX_BACKWARD_LIMIT(18) */ |
| 45 | BROTLI_INTERNAL void BrotliCompressFragmentFast(MemoryManager* m, |
| 46 | const uint8_t* input, |
| 47 | size_t input_size, |
| 48 | BROTLI_BOOL is_last, |
| 49 | int* table, size_t table_size, |
| 50 | uint8_t cmd_depth[128], |
| 51 | uint16_t cmd_bits[128], |
| 52 | size_t* cmd_code_numbits, |
| 53 | uint8_t* cmd_code, |
| 54 | size_t* storage_ix, |
| 55 | uint8_t* storage); |
| 56 | |
| 57 | #if defined(__cplusplus) || defined(c_plusplus) |
| 58 | } /* extern "C" */ |
| 59 | #endif |
| 60 | |
| 61 | #endif /* BROTLI_ENC_COMPRESS_FRAGMENT_H_ */ |
| 62 | |