]> icculus.org git repositories - icculus/xz.git/blob - src/liblzma/lzma/lzma_literal.c
Fix test_filter_flags to match the new restriction of lc+lp.
[icculus/xz.git] / src / liblzma / lzma / lzma_literal.c
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 /// \file       lzma_literal.c
4 /// \brief      Literal Coder
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 "lzma_literal.h"
22
23
24 extern lzma_ret
25 lzma_literal_init(lzma_literal_coder *coder,
26                 uint32_t literal_context_bits, uint32_t literal_pos_bits)
27 {
28         // Verify that arguments are sane.
29         if (literal_context_bits > LZMA_LITERAL_CONTEXT_BITS_MAX
30                         || literal_pos_bits > LZMA_LITERAL_POS_BITS_MAX)
31                 return LZMA_HEADER_ERROR;
32
33         // Calculate the number of states the literal coder must store.
34         const uint32_t states = literal_states(
35                         literal_pos_bits, literal_context_bits);
36
37         // Store the new settings.
38         coder->literal_context_bits = literal_context_bits;
39         coder->literal_pos_bits = literal_pos_bits;
40
41         // Calculate also the literal_pos_mask. It's not changed
42         // anywhere else than here.
43         coder->literal_pos_mask = (1 << literal_pos_bits) - 1;
44
45         // Reset the literal coder.
46         for (uint32_t i = 0; i < states; ++i)
47                 for (uint32_t j = 0; j < LIT_SIZE; ++j)
48                         bit_reset(coder->coders[i][j]);
49
50         return LZMA_OK;
51 }