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