block_encoder_inc.h 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. /* NOLINT(build/header_guard) */
  2. /* Copyright 2014 Google Inc. All Rights Reserved.
  3. Distributed under MIT license.
  4. See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
  5. */
  6. /* template parameters: FN */
  7. #define HistogramType FN(Histogram)
  8. /* Creates entropy codes for all block types and stores them to the bit
  9. stream. */
  10. static void FN(BuildAndStoreEntropyCodes)(MemoryManager* m, BlockEncoder* self,
  11. const HistogramType* histograms, const size_t histograms_size,
  12. HuffmanTree* tree, size_t* storage_ix, uint8_t* storage) {
  13. const size_t alphabet_size = self->alphabet_size_;
  14. const size_t table_size = histograms_size * alphabet_size;
  15. self->depths_ = BROTLI_ALLOC(m, uint8_t, table_size);
  16. self->bits_ = BROTLI_ALLOC(m, uint16_t, table_size);
  17. if (BROTLI_IS_OOM(m)) return;
  18. {
  19. size_t i;
  20. for (i = 0; i < histograms_size; ++i) {
  21. size_t ix = i * alphabet_size;
  22. BuildAndStoreHuffmanTree(&histograms[i].data_[0], alphabet_size, tree,
  23. &self->depths_[ix], &self->bits_[ix], storage_ix, storage);
  24. }
  25. }
  26. }
  27. #undef HistogramType