1 ///////////////////////////////////////////////////////////////////////////////
3 /// \file delta_common.c
4 /// \brief Common stuff for Delta encoder and decoder
6 // Copyright (C) 2007 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_common.h"
24 delta_coder_end(lzma_coder *coder, lzma_allocator *allocator)
26 lzma_next_coder_end(&coder->next, allocator);
27 lzma_free(coder, allocator);
33 lzma_delta_coder_init(lzma_next_coder *next, lzma_allocator *allocator,
34 const lzma_filter_info *filters, lzma_code_function code)
36 // Allocate memory for the decoder if needed.
37 if (next->coder == NULL) {
38 next->coder = lzma_alloc(sizeof(lzma_coder), allocator);
39 if (next->coder == NULL)
40 return LZMA_MEM_ERROR;
42 // End function is the same for encoder and decoder.
43 next->end = &delta_coder_end;
44 next->coder->next = LZMA_NEXT_CODER_INIT;
47 // Coding function is different for encoder and decoder.
50 // Set the delta distance.
51 if (filters[0].options == NULL)
52 return LZMA_PROG_ERROR;
53 next->coder->distance = ((lzma_options_delta *)(filters[0].options))
55 if (next->coder->distance < LZMA_DELTA_DISTANCE_MIN
56 || next->coder->distance > LZMA_DELTA_DISTANCE_MAX)
57 return LZMA_HEADER_ERROR;
59 // Initialize the rest of the variables.
61 memzero(next->coder->history, LZMA_DELTA_DISTANCE_MAX);
63 // Initialize the next decoder in the chain, if any.
64 return lzma_next_filter_init(&next->coder->next,
65 allocator, filters + 1);