1 ///////////////////////////////////////////////////////////////////////////////
3 /// \file lzma_literal.h
4 /// \brief Literal Coder
6 /// This is used as is by both LZMA encoder and decoder.
8 // Copyright (C) 1999-2006 Igor Pavlov
9 // Copyright (C) 2007 Lasse Collin
11 // This library is free software; you can redistribute it and/or
12 // modify it under the terms of the GNU Lesser General Public
13 // License as published by the Free Software Foundation; either
14 // version 2.1 of the License, or (at your option) any later version.
16 // This library is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 // Lesser General Public License for more details.
21 ///////////////////////////////////////////////////////////////////////////////
23 #ifndef LZMA_LITERAL_H
24 #define LZMA_LITERAL_H
28 // We need typedef of `probability'.
29 #include "range_common.h"
32 /// Each literal coder is divided in three sections:
33 /// - 0x001-0x0FF: Without match byte
34 /// - 0x101-0x1FF: With match byte; match bit is 0
35 /// - 0x201-0x2FF: With match byte; match bit is 1
36 #define LIT_SIZE 0x300
38 /// Calculate how many states are needed. Each state has
39 /// LIT_SIZE `probability' variables.
40 #define literal_states(literal_context_bits, literal_pos_bits) \
41 (1U << ((literal_context_bits) + (literal_pos_bits)))
43 /// Locate the literal coder for the next literal byte. The choice depends on
44 /// - the lowest literal_pos_bits bits of the position of the current
46 /// - the highest literal_context_bits bits of the previous byte.
47 #define literal_get_subcoder(literal_coder, pos, prev_byte) \
48 (literal_coder).coders[(((pos) & (literal_coder).literal_pos_mask) \
49 << (literal_coder).literal_context_bits) \
50 + ((prev_byte) >> (8 - (literal_coder).literal_context_bits))]
54 uint32_t literal_context_bits;
55 uint32_t literal_pos_bits;
57 /// literal_pos_mask is always (1 << literal_pos_bits) - 1.
58 uint32_t literal_pos_mask;
60 /// There are (1 << (literal_pos_bits + literal_context_bits))
62 probability coders[1 << LZMA_LITERAL_BITS_MAX][LIT_SIZE];
67 extern lzma_ret lzma_literal_init(
68 lzma_literal_coder *coder,
69 uint32_t literal_context_bits, uint32_t literal_pos_bits);