]> icculus.org git repositories - icculus/xz.git/blob - src/liblzma/rangecoder/price_table_init.c
Fix a memory leak in the Subblock encoder.
[icculus/xz.git] / src / liblzma / rangecoder / price_table_init.c
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 /// \file       price_table_init.c
4 /// \brief      Static initializations for the range encoder's prices array
5 //
6 //  Copyright (C) 1999-2006 Igor Pavlov
7 //  Copyright (C) 2007 Lasse Collin
8 //
9 //  This library is free software; you can redistribute it and/or
10 //  modify it under the terms of the GNU Lesser General Public
11 //  License as published by the Free Software Foundation; either
12 //  version 2.1 of the License, or (at your option) any later version.
13 //
14 //  This library is distributed in the hope that it will be useful,
15 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 //  Lesser General Public License for more details.
18 //
19 ///////////////////////////////////////////////////////////////////////////////
20
21 #ifdef HAVE_CONFIG_H
22 #       include "range_encoder.h"
23 #endif
24
25
26 #define NUM_BITS (BIT_MODEL_TOTAL_BITS - MOVE_REDUCING_BITS)
27
28
29 uint32_t lzma_rc_prob_prices[BIT_MODEL_TOTAL >> MOVE_REDUCING_BITS];
30
31
32 extern void
33 lzma_rc_init(void)
34 {
35         // Initialize lzma_rc_prob_prices[].
36         for (int i = NUM_BITS - 1; i >= 0; --i) {
37                 const uint32_t start = 1 << (NUM_BITS - i - 1);
38                 const uint32_t end = 1 << (NUM_BITS - i);
39
40                 for (uint32_t j = start; j < end; ++j) {
41                         lzma_rc_prob_prices[j] = (i << BIT_PRICE_SHIFT_BITS)
42                                 + (((end - j) << BIT_PRICE_SHIFT_BITS)
43                                 >> (NUM_BITS - i - 1));
44                 }
45         }
46
47         return;
48 }