Debian Codegraph @

src/lzma/LzmaLib.c

raw
1 /* LzmaLib.c -- LZMA library wrapper
2 2008-08-05
3 Igor Pavlov
4 Public domain */
5 // ----------------------------------------------------------------------------
6 // Copyright (C) 2014
7 // David Freese, W1HKJ
8 //
9 // This file is part of flmsg
10 //
11 // flrig is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation; either version 3 of the License, or
14 // (at your option) any later version.
15 //
16 // flrig is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 // ----------------------------------------------------------------------------
24
25 #include "LzmaEnc.h"
26 #include "LzmaDec.h"
27 #include "Alloc.h"
28 #include "LzmaLib.h"
29
30 static void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }
31 static void SzFree(void *p, void *address) { p = p; MyFree(address); }
32 static ISzAlloc g_Alloc = { SzAlloc, SzFree };
33
34 MY_STDAPI LzmaCompress(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t srcLen,
35 unsigned char *outProps, size_t *outPropsSize,
36 int level, /* 0 <= level <= 9, default = 5 */
37 unsigned dictSize, /* use (1 << N) or (3 << N). 4 KB < dictSize <= 128 MB */
38 int lc, /* 0 <= lc <= 8, default = 3 */
39 int lp, /* 0 <= lp <= 4, default = 0 */
40 int pb, /* 0 <= pb <= 4, default = 2 */
41 int fb, /* 5 <= fb <= 273, default = 32 */
42 int numThreads /* 1 or 2, default = 2 */
43 )
44 {
45 CLzmaEncProps props;
46 LzmaEncProps_Init(&props);
47 props.level = level;
48 props.dictSize = dictSize;
49 props.lc = lc;
50 props.lp = lp;
51 props.pb = pb;
52 props.fb = fb;
53 props.numThreads = numThreads;
54
55 return LzmaEncode(dest, destLen, src, srcLen, &props, outProps, outPropsSize, 0,
56 NULL, &g_Alloc, &g_Alloc);
57 }
58
59
60 MY_STDAPI LzmaUncompress(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t *srcLen,
61 const unsigned char *props, size_t propsSize)
62 {
63 ELzmaStatus status;
64 return LzmaDecode(dest, destLen, src, srcLen, props, (unsigned)propsSize, LZMA_FINISH_ANY, &status, &g_Alloc);
65 }