block_encoder_inc.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  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. const size_t alphabet_size, HuffmanTree* tree,
  13. size_t* storage_ix, uint8_t* storage) {
  14. const size_t table_size = histograms_size * self->histogram_length_;
  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 * self->histogram_length_;
  22. BuildAndStoreHuffmanTree(&histograms[i].data_[0], self->histogram_length_,
  23. alphabet_size, tree, &self->depths_[ix], &self->bits_[ix],
  24. storage_ix, storage);
  25. }
  26. }
  27. }
  28. #undef HistogramType