simple_coder.c | simple_coder.c | |||
---|---|---|---|---|
skipping to change at line 20 | skipping to change at line 20 | |||
// | // | |||
// This file has been put into the public domain. | // This file has been put into the public domain. | |||
// You can do whatever you want with this file. | // You can do whatever you want with this file. | |||
// | // | |||
/////////////////////////////////////////////////////////////////////////// //// | /////////////////////////////////////////////////////////////////////////// //// | |||
#include "simple_private.h" | #include "simple_private.h" | |||
/// Copied or encodes/decodes more data to out[]. | /// Copied or encodes/decodes more data to out[]. | |||
static lzma_ret | static lzma_ret | |||
copy_or_code(lzma_coder *coder, lzma_allocator *allocator, | copy_or_code(lzma_coder *coder, const lzma_allocator *allocator, | |||
const uint8_t *restrict in, size_t *restrict in_pos, | const uint8_t *restrict in, size_t *restrict in_pos, | |||
size_t in_size, uint8_t *restrict out, | size_t in_size, uint8_t *restrict out, | |||
size_t *restrict out_pos, size_t out_size, lzma_action actio n) | size_t *restrict out_pos, size_t out_size, lzma_action actio n) | |||
{ | { | |||
assert(!coder->end_was_reached); | assert(!coder->end_was_reached); | |||
if (coder->next.code == NULL) { | if (coder->next.code == NULL) { | |||
lzma_bufcpy(in, in_pos, in_size, out, out_pos, out_size); | lzma_bufcpy(in, in_pos, in_size, out, out_pos, out_size); | |||
// Check if end of stream was reached. | // Check if end of stream was reached. | |||
skipping to change at line 66 | skipping to change at line 66 | |||
call_filter(lzma_coder *coder, uint8_t *buffer, size_t size) | call_filter(lzma_coder *coder, uint8_t *buffer, size_t size) | |||
{ | { | |||
const size_t filtered = coder->filter(coder->simple, | const size_t filtered = coder->filter(coder->simple, | |||
coder->now_pos, coder->is_encoder, | coder->now_pos, coder->is_encoder, | |||
buffer, size); | buffer, size); | |||
coder->now_pos += filtered; | coder->now_pos += filtered; | |||
return filtered; | return filtered; | |||
} | } | |||
static lzma_ret | static lzma_ret | |||
simple_code(lzma_coder *coder, lzma_allocator *allocator, | simple_code(lzma_coder *coder, const lzma_allocator *allocator, | |||
const uint8_t *restrict in, size_t *restrict in_pos, | const uint8_t *restrict in, size_t *restrict in_pos, | |||
size_t in_size, uint8_t *restrict out, | size_t in_size, uint8_t *restrict out, | |||
size_t *restrict out_pos, size_t out_size, lzma_action actio n) | size_t *restrict out_pos, size_t out_size, lzma_action actio n) | |||
{ | { | |||
// TODO: Add partial support for LZMA_SYNC_FLUSH. We can support it | // TODO: Add partial support for LZMA_SYNC_FLUSH. We can support it | |||
// in cases when the filter is able to filter everything. With most | // in cases when the filter is able to filter everything. With most | |||
// simple filters it can be done at offset that is a multiple of 2, | // simple filters it can be done at offset that is a multiple of 2, | |||
// 4, or 16. With x86 filter, it needs good luck, and thus cannot | // 4, or 16. With x86 filter, it needs good luck, and thus cannot | |||
// be made to work predictably. | // be made to work predictably. | |||
if (action == LZMA_SYNC_FLUSH) | if (action == LZMA_SYNC_FLUSH) | |||
skipping to change at line 197 | skipping to change at line 197 | |||
} | } | |||
// Check if we got everything done. | // Check if we got everything done. | |||
if (coder->end_was_reached && coder->pos == coder->size) | if (coder->end_was_reached && coder->pos == coder->size) | |||
return LZMA_STREAM_END; | return LZMA_STREAM_END; | |||
return LZMA_OK; | return LZMA_OK; | |||
} | } | |||
static void | static void | |||
simple_coder_end(lzma_coder *coder, lzma_allocator *allocator) | simple_coder_end(lzma_coder *coder, const lzma_allocator *allocator) | |||
{ | { | |||
lzma_next_end(&coder->next, allocator); | lzma_next_end(&coder->next, allocator); | |||
lzma_free(coder->simple, allocator); | lzma_free(coder->simple, allocator); | |||
lzma_free(coder, allocator); | lzma_free(coder, allocator); | |||
return; | return; | |||
} | } | |||
static lzma_ret | static lzma_ret | |||
simple_coder_update(lzma_coder *coder, lzma_allocator *allocator, | simple_coder_update(lzma_coder *coder, const lzma_allocator *allocator, | |||
const lzma_filter *filters_null lzma_attribute((__unused__)) , | const lzma_filter *filters_null lzma_attribute((__unused__)) , | |||
const lzma_filter *reversed_filters) | const lzma_filter *reversed_filters) | |||
{ | { | |||
// No update support, just call the next filter in the chain. | // No update support, just call the next filter in the chain. | |||
return lzma_next_filter_update( | return lzma_next_filter_update( | |||
&coder->next, allocator, reversed_filters + 1); | &coder->next, allocator, reversed_filters + 1); | |||
} | } | |||
extern lzma_ret | extern lzma_ret | |||
lzma_simple_coder_init(lzma_next_coder *next, lzma_allocator *allocator, | lzma_simple_coder_init(lzma_next_coder *next, const lzma_allocator *allocat or, | |||
const lzma_filter_info *filters, | const lzma_filter_info *filters, | |||
size_t (*filter)(lzma_simple *simple, uint32_t now_pos, | size_t (*filter)(lzma_simple *simple, uint32_t now_pos, | |||
bool is_encoder, uint8_t *buffer, size_t size), | bool is_encoder, uint8_t *buffer, size_t size), | |||
size_t simple_size, size_t unfiltered_max, | size_t simple_size, size_t unfiltered_max, | |||
uint32_t alignment, bool is_encoder) | uint32_t alignment, bool is_encoder) | |||
{ | { | |||
// Allocate memory for the lzma_coder structure if needed. | // Allocate memory for the lzma_coder structure if needed. | |||
if (next->coder == NULL) { | if (next->coder == NULL) { | |||
// Here we allocate space also for the temporary buffer. We | // Here we allocate space also for the temporary buffer. We | |||
// need twice the size of unfiltered_max, because then it | // need twice the size of unfiltered_max, because then it | |||
End of changes. 5 change blocks. | ||||
5 lines changed or deleted | 5 lines changed or added | |||
This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/ |