2008-01-19 14:19:21 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
/// \file delta_decoder.c
|
|
|
|
/// \brief Delta filter decoder
|
|
|
|
//
|
2009-04-13 10:27:40 +02:00
|
|
|
// Author: Lasse Collin
|
2008-01-19 14:19:21 +01:00
|
|
|
//
|
2009-04-13 10:27:40 +02:00
|
|
|
// This file has been put into the public domain.
|
|
|
|
// You can do whatever you want with this file.
|
2008-01-19 14:19:21 +01:00
|
|
|
//
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "delta_decoder.h"
|
2008-12-01 15:30:11 +01:00
|
|
|
#include "delta_private.h"
|
2008-01-19 14:19:21 +01:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
2016-11-21 19:24:50 +01:00
|
|
|
decode_buffer(lzma_delta_coder *coder, uint8_t *buffer, size_t size)
|
2008-01-19 14:19:21 +01:00
|
|
|
{
|
|
|
|
const size_t distance = coder->distance;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < size; ++i) {
|
|
|
|
buffer[i] += coder->history[(distance + coder->pos) & 0xFF];
|
|
|
|
coder->history[coder->pos-- & 0xFF] = buffer[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static lzma_ret
|
2016-11-21 19:24:50 +01:00
|
|
|
delta_decode(void *coder_ptr, const lzma_allocator *allocator,
|
2008-01-19 14:19:21 +01:00
|
|
|
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, lzma_action action)
|
|
|
|
{
|
2016-11-21 19:24:50 +01:00
|
|
|
lzma_delta_coder *coder = coder_ptr;
|
|
|
|
|
2008-06-18 17:02:10 +02:00
|
|
|
assert(coder->next.code != NULL);
|
2008-01-19 14:19:21 +01:00
|
|
|
|
2008-06-18 17:02:10 +02:00
|
|
|
const size_t out_start = *out_pos;
|
2008-01-19 14:19:21 +01:00
|
|
|
|
2008-06-18 17:02:10 +02:00
|
|
|
const lzma_ret ret = coder->next.code(coder->next.coder, allocator,
|
|
|
|
in, in_pos, in_size, out, out_pos, out_size,
|
|
|
|
action);
|
2008-01-19 14:19:21 +01:00
|
|
|
|
2008-06-18 17:02:10 +02:00
|
|
|
decode_buffer(coder, out + out_start, *out_pos - out_start);
|
2008-01-19 14:19:21 +01:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extern lzma_ret
|
2012-07-17 17:19:59 +02:00
|
|
|
lzma_delta_decoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
|
2008-01-19 14:19:21 +01:00
|
|
|
const lzma_filter_info *filters)
|
|
|
|
{
|
2009-11-14 17:59:19 +01:00
|
|
|
next->code = &delta_decode;
|
|
|
|
return lzma_delta_coder_init(next, allocator, filters);
|
2008-01-19 14:19:21 +01:00
|
|
|
}
|
2008-08-28 21:53:15 +02:00
|
|
|
|
|
|
|
|
|
|
|
extern lzma_ret
|
2012-07-17 17:19:59 +02:00
|
|
|
lzma_delta_props_decode(void **options, const lzma_allocator *allocator,
|
2008-08-28 21:53:15 +02:00
|
|
|
const uint8_t *props, size_t props_size)
|
|
|
|
{
|
|
|
|
if (props_size != 1)
|
2008-09-13 11:10:43 +02:00
|
|
|
return LZMA_OPTIONS_ERROR;
|
2008-08-28 21:53:15 +02:00
|
|
|
|
|
|
|
lzma_options_delta *opt
|
|
|
|
= lzma_alloc(sizeof(lzma_options_delta), allocator);
|
|
|
|
if (opt == NULL)
|
|
|
|
return LZMA_MEM_ERROR;
|
|
|
|
|
|
|
|
opt->type = LZMA_DELTA_TYPE_BYTE;
|
2019-06-23 20:38:56 +02:00
|
|
|
opt->dist = props[0] + 1U;
|
2008-08-28 21:53:15 +02:00
|
|
|
|
|
|
|
*options = opt;
|
|
|
|
|
|
|
|
return LZMA_OK;
|
|
|
|
}
|