]> icculus.org git repositories - icculus/xz.git/blob - src/liblzma/rangecoder/range_encoder.c
Imported to git.
[icculus/xz.git] / src / liblzma / rangecoder / range_encoder.c
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 /// \file       range_encoder.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 #include "range_encoder.h"
22
23
24 #define NUM_BITS (BIT_MODEL_TOTAL_BITS - MOVE_REDUCING_BITS)
25
26
27 uint32_t lzma_rc_prob_prices[BIT_MODEL_TOTAL >> MOVE_REDUCING_BITS];
28
29
30 extern void
31 lzma_rc_init(void)
32 {
33         // Initialize lzma_rc_prob_prices[].
34         for (int i = NUM_BITS - 1; i >= 0; --i) {
35                 const uint32_t start = 1 << (NUM_BITS - i - 1);
36                 const uint32_t end = 1 << (NUM_BITS - i);
37
38                 for (uint32_t j = start; j < end; ++j) {
39                         lzma_rc_prob_prices[j] = (i << BIT_PRICE_SHIFT_BITS)
40                                 + (((end - j) << BIT_PRICE_SHIFT_BITS)
41                                 >> (NUM_BITS - i - 1));
42                 }
43         }
44
45         return;
46 }