11cb0ef41Sopenharmony_ci/* NOLINT(build/header_guard) */ 21cb0ef41Sopenharmony_ci/* Copyright 2014 Google Inc. All Rights Reserved. 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_ci Distributed under MIT license. 51cb0ef41Sopenharmony_ci See file LICENSE for detail or copy at https://opensource.org/licenses/MIT 61cb0ef41Sopenharmony_ci*/ 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ci/* template parameters: FN */ 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ci#define HistogramType FN(Histogram) 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ci/* Creates entropy codes for all block types and stores them to the bit 131cb0ef41Sopenharmony_ci stream. */ 141cb0ef41Sopenharmony_cistatic void FN(BuildAndStoreEntropyCodes)(MemoryManager* m, BlockEncoder* self, 151cb0ef41Sopenharmony_ci const HistogramType* histograms, const size_t histograms_size, 161cb0ef41Sopenharmony_ci const size_t alphabet_size, HuffmanTree* tree, 171cb0ef41Sopenharmony_ci size_t* storage_ix, uint8_t* storage) { 181cb0ef41Sopenharmony_ci const size_t table_size = histograms_size * self->histogram_length_; 191cb0ef41Sopenharmony_ci self->depths_ = BROTLI_ALLOC(m, uint8_t, table_size); 201cb0ef41Sopenharmony_ci self->bits_ = BROTLI_ALLOC(m, uint16_t, table_size); 211cb0ef41Sopenharmony_ci if (BROTLI_IS_OOM(m)) return; 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ci { 241cb0ef41Sopenharmony_ci size_t i; 251cb0ef41Sopenharmony_ci for (i = 0; i < histograms_size; ++i) { 261cb0ef41Sopenharmony_ci size_t ix = i * self->histogram_length_; 271cb0ef41Sopenharmony_ci BuildAndStoreHuffmanTree(&histograms[i].data_[0], self->histogram_length_, 281cb0ef41Sopenharmony_ci alphabet_size, tree, &self->depths_[ix], &self->bits_[ix], 291cb0ef41Sopenharmony_ci storage_ix, storage); 301cb0ef41Sopenharmony_ci } 311cb0ef41Sopenharmony_ci } 321cb0ef41Sopenharmony_ci} 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_ci#undef HistogramType 35