1 /* Delta.c -- Delta converter
2 2009-05-26 : Igor Pavlov : Public domain */
8 void Delta_Init(Byte
*state
)
11 for (i
= 0; i
< DELTA_STATE_SIZE
; i
++)
15 static void MyMemCpy(Byte
*dest
, const Byte
*src
, unsigned size
)
18 for (i
= 0; i
< size
; i
++)
22 void Delta_Encode(Byte
*state
, unsigned delta
, Byte
*data
, SizeT size
)
24 Byte buf
[DELTA_STATE_SIZE
];
26 MyMemCpy(buf
, state
, delta
);
29 for (i
= 0; i
< size
;)
31 for (j
= 0; j
< delta
&& i
< size
; i
++, j
++)
34 data
[i
] = (Byte
)(b
- buf
[j
]);
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
];
49 MyMemCpy(buf
, state
, delta
);
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
]);
62 MyMemCpy(state
, buf
+ j
, delta
- j
);
63 MyMemCpy(state
+ delta
- j
, buf
, j
);