-
Notifications
You must be signed in to change notification settings - Fork 1
/
rle.c
46 lines (41 loc) · 831 Bytes
/
rle.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#define RunMarker 0x91
unsigned long rle_decode(register unsigned char *out, register unsigned char *in, register unsigned long len)
{
register unsigned long PosIn=0;
register unsigned long PosOut=0;
register unsigned char byte;
//register unsigned char freq;
register short freq;
register unsigned char i;
while(PosIn<len)
{
if(in[PosIn]==RunMarker)
{
PosIn++;
byte=in[PosIn++];
freq=(unsigned char)(in[PosIn++]-1); //make a zero into 255 for the loop
if(out)
{
freq++;
for(i=0;i<freq;i++)
out[PosOut++]=byte;
//out[PosOut++]=byte; //write the last byte
}
else
{
PosOut+=freq+1;
}
}
else
{
if(out)
out[PosOut++]=in[PosIn++];
else
{
PosOut++;
PosIn++;
}
}
}
return PosOut;
}