compress_fragment_two_pass.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 two-pass processing: in the first pass we save
  7. the found backward matches and literal bytes into a buffer, and in the
  8. second pass we emit them into the bit stream using prefix codes built based
  9. on the actual command and literal byte histograms. */
  10. #ifndef BROTLI_ENC_COMPRESS_FRAGMENT_TWO_PASS_H_
  11. #define BROTLI_ENC_COMPRESS_FRAGMENT_TWO_PASS_H_
  12. #include "../common/platform.h"
  13. #include <brotli/types.h>
  14. #include "./memory.h"
  15. #if defined(__cplusplus) || defined(c_plusplus)
  16. extern "C" {
  17. #endif
  18. static const size_t kCompressFragmentTwoPassBlockSize = 1 << 17;
  19. /* Compresses "input" string to the "*storage" buffer as one or more complete
  20. meta-blocks, and updates the "*storage_ix" bit position.
  21. If "is_last" is 1, emits an additional empty last meta-block.
  22. REQUIRES: "input_size" is greater than zero, or "is_last" is 1.
  23. REQUIRES: "input_size" is less or equal to maximal metablock size (1 << 24).
  24. REQUIRES: "command_buf" and "literal_buf" point to at least
  25. kCompressFragmentTwoPassBlockSize long arrays.
  26. REQUIRES: All elements in "table[0..table_size-1]" are initialized to zero.
  27. REQUIRES: "table_size" is a power of two
  28. OUTPUT: maximal copy distance <= |input_size|
  29. OUTPUT: maximal copy distance <= BROTLI_MAX_BACKWARD_LIMIT(18) */
  30. BROTLI_INTERNAL void BrotliCompressFragmentTwoPass(MemoryManager* m,
  31. const uint8_t* input,
  32. size_t input_size,
  33. BROTLI_BOOL is_last,
  34. uint32_t* command_buf,
  35. uint8_t* literal_buf,
  36. int* table,
  37. size_t table_size,
  38. size_t* storage_ix,
  39. uint8_t* storage);
  40. #if defined(__cplusplus) || defined(c_plusplus)
  41. } /* extern "C" */
  42. #endif
  43. #endif /* BROTLI_ENC_COMPRESS_FRAGMENT_TWO_PASS_H_ */