/src/lzma-fuzz/sdk/C/Delta.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* Delta.c -- Delta converter |
2 | | 2009-05-26 : Igor Pavlov : Public domain */ |
3 | | |
4 | | #include "Precomp.h" |
5 | | |
6 | | #include "Delta.h" |
7 | | |
8 | | void Delta_Init(Byte *state) |
9 | 0 | { |
10 | 0 | unsigned i; |
11 | 0 | for (i = 0; i < DELTA_STATE_SIZE; i++) |
12 | 0 | state[i] = 0; |
13 | 0 | } |
14 | | |
15 | | static void MyMemCpy(Byte *dest, const Byte *src, unsigned size) |
16 | 0 | { |
17 | 0 | unsigned i; |
18 | 0 | for (i = 0; i < size; i++) |
19 | 0 | dest[i] = src[i]; |
20 | 0 | } |
21 | | |
22 | | void Delta_Encode(Byte *state, unsigned delta, Byte *data, SizeT size) |
23 | 0 | { |
24 | 0 | Byte buf[DELTA_STATE_SIZE]; |
25 | 0 | unsigned j = 0; |
26 | 0 | MyMemCpy(buf, state, delta); |
27 | 0 | { |
28 | 0 | SizeT i; |
29 | 0 | for (i = 0; i < size;) |
30 | 0 | { |
31 | 0 | for (j = 0; j < delta && i < size; i++, j++) |
32 | 0 | { |
33 | 0 | Byte b = data[i]; |
34 | 0 | data[i] = (Byte)(b - buf[j]); |
35 | 0 | buf[j] = b; |
36 | 0 | } |
37 | 0 | } |
38 | 0 | } |
39 | 0 | if (j == delta) |
40 | 0 | j = 0; |
41 | 0 | MyMemCpy(state, buf + j, delta - j); |
42 | 0 | MyMemCpy(state + delta - j, buf, j); |
43 | 0 | } |
44 | | |
45 | | void Delta_Decode(Byte *state, unsigned delta, Byte *data, SizeT size) |
46 | 0 | { |
47 | 0 | Byte buf[DELTA_STATE_SIZE]; |
48 | 0 | unsigned j = 0; |
49 | 0 | MyMemCpy(buf, state, delta); |
50 | 0 | { |
51 | 0 | SizeT i; |
52 | 0 | for (i = 0; i < size;) |
53 | 0 | { |
54 | 0 | for (j = 0; j < delta && i < size; i++, j++) |
55 | 0 | { |
56 | 0 | buf[j] = data[i] = (Byte)(buf[j] + data[i]); |
57 | 0 | } |
58 | 0 | } |
59 | 0 | } |
60 | 0 | if (j == delta) |
61 | 0 | j = 0; |
62 | 0 | MyMemCpy(state, buf + j, delta - j); |
63 | 0 | MyMemCpy(state + delta - j, buf, j); |
64 | 0 | } |