brotli_bit_stream.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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/types.h"
  15. #include "./command.h"
  16. #include "./context.h"
  17. #include "./entropy_encode.h"
  18. #include "./memory.h"
  19. #include "./metablock.h"
  20. #include "./port.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,
  36. size_t start_pos,
  37. size_t length,
  38. size_t mask,
  39. uint8_t prev_byte,
  40. uint8_t prev_byte2,
  41. int is_final_block,
  42. uint32_t num_direct_distance_codes,
  43. uint32_t distance_postfix_bits,
  44. ContextType literal_context_mode,
  45. const Command* commands,
  46. size_t n_commands,
  47. const MetaBlockSplit* mb,
  48. size_t* storage_ix,
  49. uint8_t* storage);
  50. /* Stores the meta-block without doing any block splitting, just collects
  51. one histogram per block category and uses that for entropy coding.
  52. REQUIRES: length > 0
  53. REQUIRES: length <= (1 << 24) */
  54. BROTLI_INTERNAL void BrotliStoreMetaBlockTrivial(MemoryManager* m,
  55. const uint8_t* input,
  56. size_t start_pos,
  57. size_t length,
  58. size_t mask,
  59. int is_last,
  60. const Command *commands,
  61. size_t n_commands,
  62. size_t* storage_ix,
  63. uint8_t* storage);
  64. /* Same as above, but uses static prefix codes for histograms with a only a few
  65. symbols, and uses static code length prefix codes for all other histograms.
  66. REQUIRES: length > 0
  67. REQUIRES: length <= (1 << 24) */
  68. BROTLI_INTERNAL void BrotliStoreMetaBlockFast(MemoryManager* m,
  69. const uint8_t* input,
  70. size_t start_pos,
  71. size_t length,
  72. size_t mask,
  73. int is_last,
  74. const Command *commands,
  75. size_t n_commands,
  76. size_t* storage_ix,
  77. uint8_t* storage);
  78. /* This is for storing uncompressed blocks (simple raw storage of
  79. bytes-as-bytes).
  80. REQUIRES: length > 0
  81. REQUIRES: length <= (1 << 24) */
  82. BROTLI_INTERNAL void BrotliStoreUncompressedMetaBlock(
  83. int is_final_block, const uint8_t* input, size_t position, size_t mask,
  84. size_t len, size_t* storage_ix, uint8_t* storage);
  85. /* Stores an empty metadata meta-block and syncs to a byte boundary. */
  86. BROTLI_INTERNAL void BrotliStoreSyncMetaBlock(size_t* storage_ix,
  87. uint8_t* storage);
  88. #if defined(__cplusplus) || defined(c_plusplus)
  89. } /* extern "C" */
  90. #endif
  91. #endif /* BROTLI_ENC_BROTLI_BIT_STREAM_H_ */