37 bool need_dictionary_reset;
68 coder->
buf[
pos] = 0x80 + (3 << 5);
70 coder->
buf[
pos] = 0x80 + (2 << 5);
75 coder->
buf[
pos] = 0x80 + (1 << 5);
143 switch (coder->sequence) {
150 out[(*out_pos)++] = 0;
156 if (coder->need_state_reset)
158 coder->lzma, &coder->opt_cur));
160 coder->uncompressed_size = 0;
161 coder->compressed_size = 0;
162 coder->sequence = SEQ_LZMA_ENCODE;
166 case SEQ_LZMA_ENCODE: {
170 - coder->uncompressed_size;
173 if (left < mf->match_len_max) {
181 limit = mf->read_pos - mf->read_ahead
182 + left - mf->match_len_max;
187 const uint32_t read_start = mf->read_pos - mf->read_ahead;
192 &coder->compressed_size,
195 coder->uncompressed_size += mf->read_pos - mf->read_ahead
207 if (coder->compressed_size >= coder->uncompressed_size) {
208 coder->uncompressed_size += mf->read_ahead;
209 assert(coder->uncompressed_size
213 coder->need_state_reset =
true;
214 coder->sequence = SEQ_UNCOMPRESSED_HEADER;
222 coder->sequence = SEQ_LZMA_COPY;
231 coder->compressed_size,
233 if (coder->buf_pos != coder->compressed_size)
236 coder->sequence = SEQ_INIT;
239 case SEQ_UNCOMPRESSED_HEADER:
247 coder->sequence = SEQ_UNCOMPRESSED_COPY;
251 case SEQ_UNCOMPRESSED_COPY:
255 if (coder->uncompressed_size != 0)
258 coder->sequence = SEQ_INIT;
const lzma_allocator const uint8_t size_t uint8_t size_t * out_pos
const lzma_allocator * allocator
const lzma_allocator const uint8_t size_t uint8_t * out
const lzma_filter * filters
Kind of two-bit version of bit scan reverse.
static uint32_t get_dist_slot(uint32_t dist)
static const char struct stat static buf struct stat static buf static vhangup int options
lzma_ret lzma_lz_encoder_init(lzma_next_coder *next, const lzma_allocator *allocator, const lzma_filter_info *filters, lzma_ret(*lz_init)(lzma_lz_encoder *lz, const lzma_allocator *allocator, const void *options, lzma_lz_options *lz_options))
LZ in window and match finder API.
static void mf_read(lzma_mf *mf, uint8_t *out, size_t *out_pos, size_t out_size, size_t *left)
static uint32_t mf_unencoded(const lzma_mf *mf)
#define LZMA_DICT_SIZE_MIN
static lzma_ret lzma2_encoder_options_update(void *coder_ptr, const lzma_filter *filter)
static void lzma2_encoder_end(void *coder_ptr, const lzma_allocator *allocator)
static lzma_ret lzma2_encoder_init(lzma_lz_encoder *lz, const lzma_allocator *allocator, const void *options, lzma_lz_options *lz_options)
static void lzma2_header_lzma(lzma_lzma2_coder *coder)
lzma_ret lzma_lzma2_encoder_init(lzma_next_coder *next, const lzma_allocator *allocator, const lzma_filter_info *filters)
static void lzma2_header_uncompressed(lzma_lzma2_coder *coder)
static lzma_ret lzma2_encode(void *coder_ptr, lzma_mf *restrict mf, uint8_t *restrict out, size_t *restrict out_pos, size_t out_size)
uint64_t lzma_lzma2_block_size(const void *options)
lzma_ret lzma_lzma2_props_encode(const void *options, uint8_t *out)
uint64_t lzma_lzma2_encoder_memusage(const void *options)
#define LZMA2_HEADER_UNCOMPRESSED
Size of a header for uncompressed chunk.
#define LZMA2_CHUNK_MAX
Maximum number of bytes of actual data per chunk (no headers)
#define LZMA2_HEADER_MAX
Maximum size of LZMA2 headers.
#define LZMA2_UNCOMPRESSED_MAX
Maximum uncompressed size of LZMA chunk (no headers)
lzma_ret lzma_lzma_encode(lzma_lzma1_encoder *restrict coder, lzma_mf *restrict mf, uint8_t *restrict out, size_t *restrict out_pos, size_t out_size, uint32_t limit)
bool lzma_lzma_lclppb_encode(const lzma_options_lzma *options, uint8_t *byte)
Encodes lc/lp/pb into one byte. Returns false on success and true on error.
lzma_ret lzma_lzma_encoder_reset(lzma_lzma1_encoder *coder, const lzma_options_lzma *options)
uint64_t lzma_lzma_encoder_memusage(const void *options)
lzma_ret lzma_lzma_encoder_create(void **coder_ptr, const lzma_allocator *allocator, const lzma_options_lzma *options, lzma_lz_options *lz_options)
assert(limit<=UINT32_MAX/2)
static uint32_t const uint8_t uint32_t uint32_t limit
Custom functions for memory handling.
lzma_ret(* code)(void *coder, lzma_mf *restrict mf, uint8_t *restrict out, size_t *restrict out_pos, size_t out_size)
Function to encode from *dict to out[].
void(* end)(void *coder, const lzma_allocator *allocator)
Free allocated resources.
lzma_ret(* options_update)(void *coder, const lzma_filter *filter)
Update the options in the middle of the encoding.
void * coder
Data specific to the LZ-based encoder.
size_t dict_size
Size of the history buffer.
size_t uncompressed_size
Uncompressed size of LZMA chunk.
size_t buf_pos
Read position in buf[].
uint8_t buf[LZMA2_HEADER_MAX+LZMA2_CHUNK_MAX]
Buffer to hold the chunk header and LZMA compressed data.
@ SEQ_UNCOMPRESSED_HEADER
lzma_options_lzma opt_cur
LZMA options currently in use.
lzma_lz_decoder lzma
LZMA decoder.
bool need_dictionary_reset
Hold data and function pointers of the next filter in the chain.
Options specific to the LZMA1 and LZMA2 filters.
uint32_t lp
Number of literal position bits.
const uint8_t * preset_dict
Pointer to an initial dictionary.
uint32_t preset_dict_size
Size of the preset dictionary.
uint32_t lc
Number of literal context bits.
uint32_t pb
Number of position bits.
uint32_t dict_size
Dictionary size in bytes.
#define return_if_error(expr)
Return if expression doesn't evaluate to LZMA_OK.
void * lzma_alloc(size_t size, const lzma_allocator *allocator) lzma_attribute((__malloc__)) lzma_attr_alloc_size(1)
Allocates memory.
uint64_t uncompressed_size
lzma_ret
Return values used by several functions in liblzma.
@ LZMA_PROG_ERROR
Programming error.
@ LZMA_MEM_ERROR
Cannot allocate memory.
@ LZMA_STREAM_END
End of stream was reached.
@ LZMA_OPTIONS_ERROR
Invalid or unsupported options.
@ LZMA_OK
Operation completed successfully.
@ LZMA_FINISH
Finish the coding operation.
@ LZMA_RUN
Continue coding.
void lzma_free(void *ptr, const lzma_allocator *allocator)
Frees memory.
size_t lzma_bufcpy(const uint8_t *restrict in, size_t *restrict in_pos, size_t in_size, uint8_t *restrict out, size_t *restrict out_pos, size_t out_size)