Remove building with NOCRYPTO option
[minix3.git] / external / public-domain / xz / dist / src / liblzma / delta / delta_decoder.c
blob726d023991c071fed331f26c03196dce00e2d9cc
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.
11 ///////////////////////////////////////////////////////////////////////////////
13 #include "delta_decoder.h"
14 #include "delta_private.h"
17 static void
18 decode_buffer(lzma_coder *coder, uint8_t *buffer, size_t size)
20 const size_t distance = coder->distance;
22 for (size_t i = 0; i < size; ++i) {
23 buffer[i] += coder->history[(distance + coder->pos) & 0xFF];
24 coder->history[coder->pos-- & 0xFF] = buffer[i];
29 static lzma_ret
30 delta_decode(lzma_coder *coder, const lzma_allocator *allocator,
31 const uint8_t *restrict in, size_t *restrict in_pos,
32 size_t in_size, uint8_t *restrict out,
33 size_t *restrict out_pos, size_t out_size, lzma_action action)
35 assert(coder->next.code != NULL);
37 const size_t out_start = *out_pos;
39 const lzma_ret ret = coder->next.code(coder->next.coder, allocator,
40 in, in_pos, in_size, out, out_pos, out_size,
41 action);
43 decode_buffer(coder, out + out_start, *out_pos - out_start);
45 return ret;
49 extern lzma_ret
50 lzma_delta_decoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
51 const lzma_filter_info *filters)
53 next->code = &delta_decode;
54 return lzma_delta_coder_init(next, allocator, filters);
58 extern lzma_ret
59 lzma_delta_props_decode(void **options, const lzma_allocator *allocator,
60 const uint8_t *props, size_t props_size)
62 if (props_size != 1)
63 return LZMA_OPTIONS_ERROR;
65 lzma_options_delta *opt
66 = lzma_alloc(sizeof(lzma_options_delta), allocator);
67 if (opt == NULL)
68 return LZMA_MEM_ERROR;
70 opt->type = LZMA_DELTA_TYPE_BYTE;
71 opt->dist = props[0] + 1;
73 *options = opt;
75 return LZMA_OK;