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