]> icculus.org git repositories - icculus/xz.git/blob - src/liblzma/common/raw_encoder.c
Imported to git.
[icculus/xz.git] / src / liblzma / common / raw_encoder.c
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 /// \file       raw_encoder.c
4 /// \brief      Raw encoder initialization API
5 //
6 //  Copyright (C) 2007 Lasse Collin
7 //
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.
12 //
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.
17 //
18 ///////////////////////////////////////////////////////////////////////////////
19
20 #include "raw_encoder.h"
21 #include "copy_coder.h"
22 #include "simple_coder.h"
23 #include "subblock_encoder.h"
24 #include "delta_coder.h"
25 #include "lzma_encoder.h"
26
27
28 static lzma_init_function
29 get_function(lzma_vli id)
30 {
31         switch (id) {
32 #ifdef HAVE_FILTER_COPY
33         case LZMA_FILTER_COPY:
34                 return &lzma_copy_encoder_init;
35 #endif
36
37 #ifdef HAVE_FILTER_SUBBLOCK
38         case LZMA_FILTER_SUBBLOCK:
39                 return &lzma_subblock_encoder_init;
40 #endif
41
42 #ifdef HAVE_FILTER_X86
43         case LZMA_FILTER_X86:
44                 return &lzma_simple_x86_encoder_init;
45 #endif
46
47 #ifdef HAVE_FILTER_POWERPC
48         case LZMA_FILTER_POWERPC:
49                 return &lzma_simple_powerpc_encoder_init;
50 #endif
51
52 #ifdef HAVE_FILTER_IA64
53         case LZMA_FILTER_IA64:
54                 return &lzma_simple_ia64_encoder_init;
55 #endif
56
57 #ifdef HAVE_FILTER_ARM
58         case LZMA_FILTER_ARM:
59                 return &lzma_simple_arm_encoder_init;
60 #endif
61
62 #ifdef HAVE_FILTER_ARMTHUMB
63         case LZMA_FILTER_ARMTHUMB:
64                 return &lzma_simple_armthumb_encoder_init;
65 #endif
66
67 #ifdef HAVE_FILTER_SPARC
68         case LZMA_FILTER_SPARC:
69                 return &lzma_simple_sparc_encoder_init;
70 #endif
71
72 #ifdef HAVE_FILTER_DELTA
73         case LZMA_FILTER_DELTA:
74                 return &lzma_delta_encoder_init;
75 #endif
76
77 #ifdef HAVE_FILTER_LZMA
78         case LZMA_FILTER_LZMA:
79                 return &lzma_lzma_encoder_init;
80 #endif
81         }
82
83         return NULL;
84 }
85
86
87 extern lzma_ret
88 lzma_raw_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
89                 const lzma_options_filter *options,
90                 lzma_vli uncompressed_size, bool allow_implicit)
91 {
92         // lzma_raw_coder_init() accesses get_function() via function pointer,
93         // because this way linker doesn't statically link both encoder and
94         // decoder functions if user needs only encoder or decoder.
95         const lzma_ret ret = lzma_raw_coder_init(next, allocator,
96                         options, uncompressed_size, &get_function,
97                         allow_implicit, true);
98
99         if (ret != LZMA_OK)
100                 lzma_next_coder_end(next, allocator);
101
102         return ret;
103 }
104
105
106 extern LZMA_API lzma_ret
107 lzma_raw_encoder(lzma_stream *strm, const lzma_options_filter *options,
108                 lzma_vli uncompressed_size, lzma_bool allow_implicit)
109 {
110         return_if_error(lzma_strm_init(strm));
111
112         strm->internal->supported_actions[LZMA_RUN] = true;
113         strm->internal->supported_actions[LZMA_SYNC_FLUSH] = true;
114         strm->internal->supported_actions[LZMA_FINISH] = true;
115
116         const lzma_ret ret = lzma_raw_coder_init(&strm->internal->next,
117                         strm->allocator, options, uncompressed_size,
118                         &get_function, allow_implicit, true);
119
120         if (ret != LZMA_OK)
121                 lzma_end(strm);
122
123         return ret;
124 }