brotli_bit_stream.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* Copyright 2014 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. /* Functions to convert brotli-related data structures into the
  6. brotli bit stream. The functions here operate under
  7. assumption that there is enough space in the storage, i.e., there are
  8. no out-of-range checks anywhere.
  9. These functions do bit addressing into a byte array. The byte array
  10. is called "storage" and the index to the bit is called storage_ix
  11. in function arguments. */
  12. #ifndef BROTLI_ENC_BROTLI_BIT_STREAM_H_
  13. #define BROTLI_ENC_BROTLI_BIT_STREAM_H_
  14. #include "../common/context.h"
  15. #include "../common/platform.h"
  16. #include <brotli/types.h>
  17. #include "./command.h"
  18. #include "./entropy_encode.h"
  19. #include "./memory.h"
  20. #include "./metablock.h"
  21. #if defined(__cplusplus) || defined(c_plusplus)
  22. extern "C" {
  23. #endif
  24. /* All Store functions here will use a storage_ix, which is always the bit
  25. position for the current storage. */
  26. BROTLI_INTERNAL void BrotliStoreHuffmanTree(const uint8_t* depths, size_t num,
  27. HuffmanTree* tree, size_t* storage_ix, uint8_t* storage);
  28. BROTLI_INTERNAL void BrotliBuildAndStoreHuffmanTreeFast(
  29. MemoryManager* m, const uint32_t* histogram, const size_t histogram_total,
  30. const size_t max_bits, uint8_t* depth, uint16_t* bits, size_t* storage_ix,
  31. uint8_t* storage);
  32. /* REQUIRES: length > 0 */
  33. /* REQUIRES: length <= (1 << 24) */
  34. BROTLI_INTERNAL void BrotliStoreMetaBlock(MemoryManager* m,
  35. const uint8_t* input, size_t start_pos, size_t length, size_t mask,
  36. uint8_t prev_byte, uint8_t prev_byte2, BROTLI_BOOL is_last,
  37. const BrotliEncoderParams* params, ContextType literal_context_mode,
  38. const Command* commands, size_t n_commands, const MetaBlockSplit* mb,
  39. size_t* storage_ix, uint8_t* storage);
  40. /* Stores the meta-block without doing any block splitting, just collects
  41. one histogram per block category and uses that for entropy coding.
  42. REQUIRES: length > 0
  43. REQUIRES: length <= (1 << 24) */
  44. BROTLI_INTERNAL void BrotliStoreMetaBlockTrivial(MemoryManager* m,
  45. const uint8_t* input, size_t start_pos, size_t length, size_t mask,
  46. BROTLI_BOOL is_last, const BrotliEncoderParams* params,
  47. const Command* commands, size_t n_commands,
  48. size_t* storage_ix, uint8_t* storage);
  49. /* Same as above, but uses static prefix codes for histograms with a only a few
  50. symbols, and uses static code length prefix codes for all other histograms.
  51. REQUIRES: length > 0
  52. REQUIRES: length <= (1 << 24) */
  53. BROTLI_INTERNAL void BrotliStoreMetaBlockFast(MemoryManager* m,
  54. const uint8_t* input, size_t start_pos, size_t length, size_t mask,
  55. BROTLI_BOOL is_last, const BrotliEncoderParams* params,
  56. const Command* commands, size_t n_commands,
  57. size_t* storage_ix, uint8_t* storage);
  58. /* This is for storing uncompressed blocks (simple raw storage of
  59. bytes-as-bytes).
  60. REQUIRES: length > 0
  61. REQUIRES: length <= (1 << 24) */
  62. BROTLI_INTERNAL void BrotliStoreUncompressedMetaBlock(
  63. BROTLI_BOOL is_final_block, const uint8_t* BROTLI_RESTRICT input,
  64. size_t position, size_t mask, size_t len,
  65. size_t* BROTLI_RESTRICT storage_ix, uint8_t* BROTLI_RESTRICT storage);
  66. #if defined(__cplusplus) || defined(c_plusplus)
  67. } /* extern "C" */
  68. #endif
  69. #endif /* BROTLI_ENC_BROTLI_BIT_STREAM_H_ */