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_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_LZMA1: {
54 const lzma_options_lzma *lzma = filters[i].options;
55 return 1 << MAX(lzma->pb, lzma->lp);
67 extern LZMA_API uint32_t
68 lzma_alignment_output(const lzma_filter *filters, uint32_t guess)
70 if (filters[0].id == LZMA_VLI_UNKNOWN)
73 // Find the last filter in the chain.
75 while (filters[i + 1].id != LZMA_VLI_UNKNOWN)
79 switch (filters[i].id) {
80 case LZMA_FILTER_DELTA:
81 // It's the same as the input alignment, so
82 // check the next filter.
85 case LZMA_FILTER_SUBBLOCK:
86 if (filters[i].options == NULL)
87 return LZMA_SUBBLOCK_ALIGNMENT_DEFAULT;
89 return ((const lzma_options_subblock *)(
90 filters[i].options))->alignment;
93 case LZMA_FILTER_LZMA1:
96 case LZMA_FILTER_ARMTHUMB:
99 case LZMA_FILTER_POWERPC:
100 case LZMA_FILTER_ARM:
101 case LZMA_FILTER_SPARC:
104 case LZMA_FILTER_IA64:
112 // If we get here, we have the same alignment as the input data.