-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrle90.pas
75 lines (61 loc) · 1.45 KB
/
rle90.pas
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
unit rle90;
{$mode objfpc}{$H+}
//PV Unpack
//https://github.com/PascalVault
//Licence: MIT
//Last update: 2023-11-11
interface
uses
Classes, SysUtils;
type
{ TRLE90 }
TRLE90 = class
private
FInStream: TStream;
FOutStream: TStream;
public
constructor Create(InStream, OutStream: TStream);
procedure Decode(PackedSize: Int64);
end;
implementation
constructor TRLE90.Create(InStream, OutStream: TStream);
begin
FInStream := InStream;
FOutStream := OutStream;
end;
procedure TRLE90.Decode(PackedSize: Int64);
const NoHistory = 0;
InLoop = 1;
var i, k: Integer;
Code: Byte;
C: Byte;
LastC: Byte;
state: Byte;
begin
Code := $90;
i := 0;
state := NoHistory;
while i < packedSize do begin
FInStream.Read(C, 1);
case state of
NoHistory: begin
if C = $90 then state := InLoop
else begin
FOutStream.Write(C, 1);
LastC := C;
end;
end;
InLoop: begin
if c <> 0 then begin
for k:=0 to c-2 do
FOutStream.Write(LastC, 1);
end
else FOutStream.Write(Code, 1);
state := NoHistory;
end;
else raise Exception.Create('Invalid state');
end;
Inc(i);
end;
end;
end.