lzma_decoder.c (292588) | lzma_decoder.c (312518) |
---|---|
1/////////////////////////////////////////////////////////////////////////////// 2// 3/// \file lzma_decoder.c 4/// \brief LZMA decoder 5/// 6// Authors: Igor Pavlov 7// Lasse Collin 8// --- 147 unchanged lines hidden (view full) --- 156 probability choice; 157 probability choice2; 158 probability low[POS_STATES_MAX][LEN_LOW_SYMBOLS]; 159 probability mid[POS_STATES_MAX][LEN_MID_SYMBOLS]; 160 probability high[LEN_HIGH_SYMBOLS]; 161} lzma_length_decoder; 162 163 | 1/////////////////////////////////////////////////////////////////////////////// 2// 3/// \file lzma_decoder.c 4/// \brief LZMA decoder 5/// 6// Authors: Igor Pavlov 7// Lasse Collin 8// --- 147 unchanged lines hidden (view full) --- 156 probability choice; 157 probability choice2; 158 probability low[POS_STATES_MAX][LEN_LOW_SYMBOLS]; 159 probability mid[POS_STATES_MAX][LEN_MID_SYMBOLS]; 160 probability high[LEN_HIGH_SYMBOLS]; 161} lzma_length_decoder; 162 163 |
164struct lzma_coder_s { | 164typedef struct { |
165 /////////////////// 166 // Probabilities // 167 /////////////////// 168 169 /// Literals; see comments in lzma_common.h. 170 probability literal[LITERAL_CODERS_MAX][LITERAL_CODER_SIZE]; 171 172 /// If 1, it's a match. Otherwise it's a single 8-bit literal. --- 99 unchanged lines hidden (view full) --- 272 273 /// Matched literal decoder: 0x100 or 0 to help avoiding branches. 274 /// Bittree reverse decoders: Offset of the next bit: 1 << offset 275 uint32_t offset; 276 277 /// If decoding a literal: match byte. 278 /// If decoding a match: length of the match. 279 uint32_t len; | 165 /////////////////// 166 // Probabilities // 167 /////////////////// 168 169 /// Literals; see comments in lzma_common.h. 170 probability literal[LITERAL_CODERS_MAX][LITERAL_CODER_SIZE]; 171 172 /// If 1, it's a match. Otherwise it's a single 8-bit literal. --- 99 unchanged lines hidden (view full) --- 272 273 /// Matched literal decoder: 0x100 or 0 to help avoiding branches. 274 /// Bittree reverse decoders: Offset of the next bit: 1 << offset 275 uint32_t offset; 276 277 /// If decoding a literal: match byte. 278 /// If decoding a match: length of the match. 279 uint32_t len; |
280}; | 280} lzma_lzma1_decoder; |
281 282 283static lzma_ret | 281 282 283static lzma_ret |
284lzma_decode(lzma_coder *restrict coder, lzma_dict *restrict dictptr, | 284lzma_decode(void *coder_ptr, lzma_dict *restrict dictptr, |
285 const uint8_t *restrict in, 286 size_t *restrict in_pos, size_t in_size) 287{ | 285 const uint8_t *restrict in, 286 size_t *restrict in_pos, size_t in_size) 287{ |
288 lzma_lzma1_decoder *restrict coder = coder_ptr; 289 |
|
288 //////////////////// 289 // Initialization // 290 //////////////////// 291 292 { 293 const lzma_ret ret = rc_read_init( 294 &coder->rc, in, in_pos, in_size); 295 if (ret != LZMA_STREAM_END) --- 539 unchanged lines hidden (view full) --- 835 } 836 837 return ret; 838} 839 840 841 842static void | 290 //////////////////// 291 // Initialization // 292 //////////////////// 293 294 { 295 const lzma_ret ret = rc_read_init( 296 &coder->rc, in, in_pos, in_size); 297 if (ret != LZMA_STREAM_END) --- 539 unchanged lines hidden (view full) --- 837 } 838 839 return ret; 840} 841 842 843 844static void |
843lzma_decoder_uncompressed(lzma_coder *coder, lzma_vli uncompressed_size) | 845lzma_decoder_uncompressed(void *coder_ptr, lzma_vli uncompressed_size) |
844{ | 846{ |
847 lzma_lzma1_decoder *coder = coder_ptr; |
|
845 coder->uncompressed_size = uncompressed_size; 846} 847 | 848 coder->uncompressed_size = uncompressed_size; 849} 850 |
848/* 849extern void 850lzma_lzma_decoder_uncompressed(void *coder_ptr, lzma_vli uncompressed_size) 851{ 852 // This is hack. 853 (*(lzma_coder **)(coder))->uncompressed_size = uncompressed_size; 854} 855*/ | |
856 857static void | 851 852static void |
858lzma_decoder_reset(lzma_coder *coder, const void *opt) | 853lzma_decoder_reset(void *coder_ptr, const void *opt) |
859{ | 854{ |
855 lzma_lzma1_decoder *coder = coder_ptr; |
|
860 const lzma_options_lzma *options = opt; 861 862 // NOTE: We assume that lc/lp/pb are valid since they were 863 // successfully decoded with lzma_lzma_decode_properties(). 864 865 // Calculate pos_mask. We don't need pos_bits as is for anything. 866 coder->pos_mask = (1U << options->pb) - 1; 867 --- 68 unchanged lines hidden (view full) --- 936} 937 938 939extern lzma_ret 940lzma_lzma_decoder_create(lzma_lz_decoder *lz, const lzma_allocator *allocator, 941 const void *opt, lzma_lz_options *lz_options) 942{ 943 if (lz->coder == NULL) { | 856 const lzma_options_lzma *options = opt; 857 858 // NOTE: We assume that lc/lp/pb are valid since they were 859 // successfully decoded with lzma_lzma_decode_properties(). 860 861 // Calculate pos_mask. We don't need pos_bits as is for anything. 862 coder->pos_mask = (1U << options->pb) - 1; 863 --- 68 unchanged lines hidden (view full) --- 932} 933 934 935extern lzma_ret 936lzma_lzma_decoder_create(lzma_lz_decoder *lz, const lzma_allocator *allocator, 937 const void *opt, lzma_lz_options *lz_options) 938{ 939 if (lz->coder == NULL) { |
944 lz->coder = lzma_alloc(sizeof(lzma_coder), allocator); | 940 lz->coder = lzma_alloc(sizeof(lzma_lzma1_decoder), allocator); |
945 if (lz->coder == NULL) 946 return LZMA_MEM_ERROR; 947 948 lz->code = &lzma_decode; 949 lz->reset = &lzma_decoder_reset; 950 lz->set_uncompressed = &lzma_decoder_uncompressed; 951 } 952 --- 56 unchanged lines hidden (view full) --- 1009 return options->lc + options->lp > LZMA_LCLP_MAX; 1010} 1011 1012 1013extern uint64_t 1014lzma_lzma_decoder_memusage_nocheck(const void *options) 1015{ 1016 const lzma_options_lzma *const opt = options; | 941 if (lz->coder == NULL) 942 return LZMA_MEM_ERROR; 943 944 lz->code = &lzma_decode; 945 lz->reset = &lzma_decoder_reset; 946 lz->set_uncompressed = &lzma_decoder_uncompressed; 947 } 948 --- 56 unchanged lines hidden (view full) --- 1005 return options->lc + options->lp > LZMA_LCLP_MAX; 1006} 1007 1008 1009extern uint64_t 1010lzma_lzma_decoder_memusage_nocheck(const void *options) 1011{ 1012 const lzma_options_lzma *const opt = options; |
1017 return sizeof(lzma_coder) + lzma_lz_decoder_memusage(opt->dict_size); | 1013 return sizeof(lzma_lzma1_decoder) 1014 + lzma_lz_decoder_memusage(opt->dict_size); |
1018} 1019 1020 1021extern uint64_t 1022lzma_lzma_decoder_memusage(const void *options) 1023{ 1024 if (!is_lclppb_valid(options)) 1025 return UINT64_MAX; --- 36 unchanged lines hidden --- | 1015} 1016 1017 1018extern uint64_t 1019lzma_lzma_decoder_memusage(const void *options) 1020{ 1021 if (!is_lclppb_valid(options)) 1022 return UINT64_MAX; --- 36 unchanged lines hidden --- |