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