compress_fragment.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* Copyright 2015 Google Inc. All Rights Reserved.
  2. Distributed under MIT license.
  3. See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
  4. */
  5. /* Function for fast encoding of an input fragment, independently from the input
  6. history. This function uses one-pass processing: when we find a backward
  7. match, we immediately emit the corresponding command and literal codes to
  8. the bit stream. */
  9. #ifndef BROTLI_ENC_COMPRESS_FRAGMENT_H_
  10. #define BROTLI_ENC_COMPRESS_FRAGMENT_H_
  11. #include "../common/platform.h"
  12. #include <brotli/types.h>
  13. #include "./memory.h"
  14. #if defined(__cplusplus) || defined(c_plusplus)
  15. extern "C" {
  16. #endif
  17. /* Compresses "input" string to the "*storage" buffer as one or more complete
  18. meta-blocks, and updates the "*storage_ix" bit position.
  19. If "is_last" is 1, emits an additional empty last meta-block.
  20. "cmd_depth" and "cmd_bits" contain the command and distance prefix codes
  21. (see comment in encode.h) used for the encoding of this input fragment.
  22. If "is_last" is 0, they are updated to reflect the statistics
  23. of this input fragment, to be used for the encoding of the next fragment.
  24. "*cmd_code_numbits" is the number of bits of the compressed representation
  25. of the command and distance prefix codes, and "cmd_code" is an array of
  26. at least "(*cmd_code_numbits + 7) >> 3" size that contains the compressed
  27. command and distance prefix codes. If "is_last" is 0, these are also
  28. updated to represent the updated "cmd_depth" and "cmd_bits".
  29. REQUIRES: "input_size" is greater than zero, or "is_last" is 1.
  30. REQUIRES: "input_size" is less or equal to maximal metablock size (1 << 24).
  31. REQUIRES: All elements in "table[0..table_size-1]" are initialized to zero.
  32. REQUIRES: "table_size" is an odd (9, 11, 13, 15) power of two
  33. OUTPUT: maximal copy distance <= |input_size|
  34. OUTPUT: maximal copy distance <= BROTLI_MAX_BACKWARD_LIMIT(18) */
  35. BROTLI_INTERNAL void BrotliCompressFragmentFast(MemoryManager* m,
  36. const uint8_t* input,
  37. size_t input_size,
  38. BROTLI_BOOL is_last,
  39. int* table, size_t table_size,
  40. uint8_t cmd_depth[128],
  41. uint16_t cmd_bits[128],
  42. size_t* cmd_code_numbits,
  43. uint8_t* cmd_code,
  44. size_t* storage_ix,
  45. uint8_t* storage);
  46. #if defined(__cplusplus) || defined(c_plusplus)
  47. } /* extern "C" */
  48. #endif
  49. #endif /* BROTLI_ENC_COMPRESS_FRAGMENT_H_ */