1 ///////////////////////////////////////////////////////////////////////////////
3 /// \file raw_encoder.c
4 /// \brief Raw encoder initialization API
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 ///////////////////////////////////////////////////////////////////////////////
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"
28 static lzma_init_function
29 get_function(lzma_vli id)
32 #ifdef HAVE_FILTER_COPY
33 case LZMA_FILTER_COPY:
34 return &lzma_copy_encoder_init;
37 #ifdef HAVE_FILTER_SUBBLOCK
38 case LZMA_FILTER_SUBBLOCK:
39 return &lzma_subblock_encoder_init;
42 #ifdef HAVE_FILTER_X86
44 return &lzma_simple_x86_encoder_init;
47 #ifdef HAVE_FILTER_POWERPC
48 case LZMA_FILTER_POWERPC:
49 return &lzma_simple_powerpc_encoder_init;
52 #ifdef HAVE_FILTER_IA64
53 case LZMA_FILTER_IA64:
54 return &lzma_simple_ia64_encoder_init;
57 #ifdef HAVE_FILTER_ARM
59 return &lzma_simple_arm_encoder_init;
62 #ifdef HAVE_FILTER_ARMTHUMB
63 case LZMA_FILTER_ARMTHUMB:
64 return &lzma_simple_armthumb_encoder_init;
67 #ifdef HAVE_FILTER_SPARC
68 case LZMA_FILTER_SPARC:
69 return &lzma_simple_sparc_encoder_init;
72 #ifdef HAVE_FILTER_DELTA
73 case LZMA_FILTER_DELTA:
74 return &lzma_delta_encoder_init;
77 #ifdef HAVE_FILTER_LZMA
78 case LZMA_FILTER_LZMA:
79 return &lzma_lzma_encoder_init;
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)
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);
100 lzma_next_coder_end(next, allocator);
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)
110 return_if_error(lzma_strm_init(strm));
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;
116 const lzma_ret ret = lzma_raw_coder_init(&strm->internal->next,
117 strm->allocator, options, uncompressed_size,
118 &get_function, allow_implicit, true);