Linux multi-monitor fullscreen support
[ryzomcore.git] / nel / 3rdparty / seven_zip / Delta.c
blobe3edd21edbb9f6db73f1e2a5f4069ea5ad47bae2
1 /* Delta.c -- Delta converter
2 2009-05-26 : Igor Pavlov : Public domain */
4 #include "Precomp.h"
6 #include "Delta.h"
8 void Delta_Init(Byte *state)
10 unsigned i;
11 for (i = 0; i < DELTA_STATE_SIZE; i++)
12 state[i] = 0;
15 static void MyMemCpy(Byte *dest, const Byte *src, unsigned size)
17 unsigned i;
18 for (i = 0; i < size; i++)
19 dest[i] = src[i];
22 void Delta_Encode(Byte *state, unsigned delta, Byte *data, SizeT size)
24 Byte buf[DELTA_STATE_SIZE];
25 unsigned j = 0;
26 MyMemCpy(buf, state, delta);
28 SizeT i;
29 for (i = 0; i < size;)
31 for (j = 0; j < delta && i < size; i++, j++)
33 Byte b = data[i];
34 data[i] = (Byte)(b - buf[j]);
35 buf[j] = b;
39 if (j == delta)
40 j = 0;
41 MyMemCpy(state, buf + j, delta - j);
42 MyMemCpy(state + delta - j, buf, j);
45 void Delta_Decode(Byte *state, unsigned delta, Byte *data, SizeT size)
47 Byte buf[DELTA_STATE_SIZE];
48 unsigned j = 0;
49 MyMemCpy(buf, state, delta);
51 SizeT i;
52 for (i = 0; i < size;)
54 for (j = 0; j < delta && i < size; i++, j++)
56 buf[j] = data[i] = (Byte)(buf[j] + data[i]);
60 if (j == delta)
61 j = 0;
62 MyMemCpy(state, buf + j, delta - j);
63 MyMemCpy(state + delta - j, buf, j);