1 ///////////////////////////////////////////////////////////////////////////////
4 /// \brief Calculates preferred alignments of different filters
6 // Copyright (C) 2007 Lasse Collin
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Lesser General Public
10 // License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
18 ///////////////////////////////////////////////////////////////////////////////
23 extern LZMA_API uint32_t
24 lzma_alignment_input(const lzma_filter *filters, uint32_t guess)
26 for (size_t i = 0; filters[i].id != LZMA_VLI_VALUE_UNKNOWN; ++i) {
27 switch (filters[i].id) {
28 case LZMA_FILTER_DELTA:
29 // The same as the input, check the next filter.
32 case LZMA_FILTER_SUBBLOCK:
33 if (filters[i].options == NULL)
34 return LZMA_SUBBLOCK_ALIGNMENT_DEFAULT;
36 return ((const lzma_options_subblock *)(
37 filters[i].options))->alignment;
42 case LZMA_FILTER_ARMTHUMB:
45 case LZMA_FILTER_POWERPC:
47 case LZMA_FILTER_SPARC:
50 case LZMA_FILTER_IA64:
53 case LZMA_FILTER_LZMA: {
54 const lzma_options_lzma *lzma = filters[i].options;
55 return 1 << MAX(lzma->pos_bits,
56 lzma->literal_pos_bits);
68 extern LZMA_API uint32_t
69 lzma_alignment_output(const lzma_filter *filters, uint32_t guess)
71 if (filters[0].id == LZMA_VLI_VALUE_UNKNOWN)
74 // Find the last filter in the chain.
76 while (filters[i + 1].id != LZMA_VLI_VALUE_UNKNOWN)
80 switch (filters[i].id) {
81 case LZMA_FILTER_DELTA:
82 // It's the same as the input alignment, so
83 // check the next filter.
86 case LZMA_FILTER_SUBBLOCK:
87 if (filters[i].options == NULL)
88 return LZMA_SUBBLOCK_ALIGNMENT_DEFAULT;
90 return ((const lzma_options_subblock *)(
91 filters[i].options))->alignment;
94 case LZMA_FILTER_LZMA:
97 case LZMA_FILTER_ARMTHUMB:
100 case LZMA_FILTER_POWERPC:
101 case LZMA_FILTER_ARM:
102 case LZMA_FILTER_SPARC:
105 case LZMA_FILTER_IA64:
113 // If we get here, we have the same alignment as the input data.