]> icculus.org git repositories - icculus/xz.git/blob - src/liblzma/delta/delta_decoder.c
Removed what I believe is an incorrect #ifdef HAVE_* test.
[icculus/xz.git] / src / liblzma / delta / delta_decoder.c
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 /// \file       delta_decoder.c
4 /// \brief      Delta filter decoder
5 //
6 //  Author:     Lasse Collin
7 //
8 //  This file has been put into the public domain.
9 //  You can do whatever you want with this file.
10 //
11 ///////////////////////////////////////////////////////////////////////////////
12
13 #include "delta_decoder.h"
14 #include "delta_private.h"
15
16
17 static void
18 decode_buffer(lzma_coder *coder, uint8_t *buffer, size_t size)
19 {
20         const size_t distance = coder->distance;
21         size_t i;
22
23         for (i = 0; i < size; ++i) {
24                 buffer[i] += coder->history[(distance + coder->pos) & 0xFF];
25                 coder->history[coder->pos-- & 0xFF] = buffer[i];
26         }
27 }
28
29
30 static lzma_ret
31 delta_decode(lzma_coder *coder, lzma_allocator *allocator,
32                 const uint8_t *restrict in, size_t *restrict in_pos,
33                 size_t in_size, uint8_t *restrict out,
34                 size_t *restrict out_pos, size_t out_size, lzma_action action)
35 {
36         assert(coder->next.code != NULL);
37
38         const size_t out_start = *out_pos;
39
40         const lzma_ret ret = coder->next.code(coder->next.coder, allocator,
41                         in, in_pos, in_size, out, out_pos, out_size,
42                         action);
43
44         decode_buffer(coder, out + out_start, *out_pos - out_start);
45
46         return ret;
47 }
48
49
50 extern lzma_ret
51 lzma_delta_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
52                 const lzma_filter_info *filters)
53 {
54         next->code = &delta_decode;
55         return lzma_delta_coder_init(next, allocator, filters);
56 }
57
58
59 extern lzma_ret
60 lzma_delta_props_decode(void **options, lzma_allocator *allocator,
61                 const uint8_t *props, size_t props_size)
62 {
63         if (props_size != 1)
64                 return LZMA_OPTIONS_ERROR;
65
66         lzma_options_delta *opt
67                         = lzma_alloc(sizeof(lzma_options_delta), allocator);
68         if (opt == NULL)
69                 return LZMA_MEM_ERROR;
70
71         opt->type = LZMA_DELTA_TYPE_BYTE;
72         opt->dist = props[0] + 1;
73
74         *options = opt;
75
76         return LZMA_OK;
77 }