1 ///////////////////////////////////////////////////////////////////////////////
3 /// \file delta_decoder.c
4 /// \brief Delta filter decoder
6 // Copyright (C) 2007, 2008 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 "delta_decoder.h"
21 #include "delta_common.h"
25 decode_buffer(lzma_coder *coder, uint8_t *buffer, size_t size)
27 const size_t distance = coder->distance;
29 for (size_t i = 0; i < size; ++i) {
30 buffer[i] += coder->history[(distance + coder->pos) & 0xFF];
31 coder->history[coder->pos-- & 0xFF] = buffer[i];
37 delta_decode(lzma_coder *coder, lzma_allocator *allocator,
38 const uint8_t *restrict in, size_t *restrict in_pos,
39 size_t in_size, uint8_t *restrict out,
40 size_t *restrict out_pos, size_t out_size, lzma_action action)
42 assert(coder->next.code != NULL);
44 const size_t out_start = *out_pos;
46 const lzma_ret ret = coder->next.code(coder->next.coder, allocator,
47 in, in_pos, in_size, out, out_pos, out_size,
50 decode_buffer(coder, out + out_start, *out_pos - out_start);
57 lzma_delta_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
58 const lzma_filter_info *filters)
60 return lzma_delta_coder_init(next, allocator, filters, &delta_decode);
65 lzma_delta_props_decode(void **options, lzma_allocator *allocator,
66 const uint8_t *props, size_t props_size)
69 return LZMA_OPTIONS_ERROR;
71 lzma_options_delta *opt
72 = lzma_alloc(sizeof(lzma_options_delta), allocator);
74 return LZMA_MEM_ERROR;
76 opt->type = LZMA_DELTA_TYPE_BYTE;
77 opt->dist = props[0] + 1;