equal
deleted
inserted
replaced
1 unit uFLDrawnMap; |
1 unit uFLDrawnMap; |
2 interface |
2 interface |
|
3 uses SDLh; |
3 |
4 |
4 function decodeDrawnMap(data: ansistring): ansistring; |
5 procedure decodeDrawnMap(data: ansistring; dataSize: Longword; var mapData: PByteArray; var size: Longword); |
5 |
6 |
6 implementation |
7 implementation |
7 uses uUtils; |
8 uses uUtils, zlib; |
8 |
9 |
9 function decodeDrawnMap(data: ansistring): ansistring; |
10 procedure decodeDrawnMap(data: ansistring; dataSize: Longword; var mapData: PByteArray; var size: Longword); |
|
11 var i, cl: Longword; |
|
12 ul: uLong; |
|
13 s: shortstring; |
|
14 r: LongInt; |
|
15 compressedBuf, uncompressedData: PByteArray; |
10 begin |
16 begin |
|
17 if dataSize = 0 then |
|
18 begin |
|
19 mapData:= nil; |
|
20 size:= 0; |
|
21 exit; |
|
22 end; |
|
23 |
|
24 compressedBuf:= GetMem(dataSize * 3 div 4); |
|
25 cl:= 0; |
|
26 i:= 1; |
|
27 |
|
28 while i < dataSize do |
|
29 begin |
|
30 if dataSize - i > 240 then |
|
31 s:= copy(data, i, 240) |
|
32 else |
|
33 s:= copy(data, i, dataSize - i + 1); |
|
34 |
|
35 s:= DecodeBase64(s); |
|
36 Move(s[1], compressedBuf^[cl], byte(s[0])); |
|
37 inc(i, 240); |
|
38 inc(cl, byte(s[0])); |
|
39 end; |
|
40 |
|
41 ul:= SDLNet_Read32(compressedBuf); |
|
42 uncompressedData:= GetMem(ul); |
|
43 r:= uncompress(pBytef(uncompressedData), @ul, @(compressedBuf^[4]), cl - 4); |
|
44 FreeMem(compressedBuf, dataSize * 3 div 4); |
|
45 |
|
46 if r = Z_OK then |
|
47 begin |
|
48 mapData:= uncompressedData; |
|
49 size:= ul |
|
50 end else |
|
51 begin |
|
52 FreeMem(uncompressedData, ul); |
|
53 mapData:= nil; |
|
54 size:= 0 |
|
55 end; |
11 end; |
56 end; |
12 |
57 |
13 end. |
58 end. |