| 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. */ |
| 14 |
static void FN(BuildAndStoreEntropyCodes)(MemoryManager* m, BlockEncoder* self, |
| 15 |
const HistogramType* histograms, const size_t histograms_size, |
| 16 |
const size_t alphabet_size, HuffmanTree* tree, |
| 17 |
size_t* storage_ix, uint8_t* storage) { |
| 18 |
const size_t table_size = histograms_size * self->histogram_length_; |
| 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 * self->histogram_length_; |
| 27 |
BuildAndStoreHuffmanTree(&histograms[i].data_[0], self->histogram_length_, |
| 28 |
alphabet_size, tree, &self->depths_[ix], &self->bits_[ix], |
| 29 |
storage_ix, storage); |
| 30 |
} |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
#undef HistogramType |