source upload
This commit is contained in:
54
imports/GrittibanzliDLL.pas
Normal file
54
imports/GrittibanzliDLL.pas
Normal file
@@ -0,0 +1,54 @@
|
||||
unit GrittibanzliDLL;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
WinAPI.Windows,
|
||||
System.SysUtils, System.Classes;
|
||||
|
||||
var
|
||||
Grittibanzli: function(const src: Pointer; srcSize: Cardinal; dst1: Pointer;
|
||||
dst1Capacity: PCardinal; dst2: Pointer; dst2Capacity: PCardinal)
|
||||
: boolean cdecl;
|
||||
Ungrittibanzli: function(const src1: Pointer; src1Size: Cardinal;
|
||||
const src2: Pointer; src2Size: Cardinal; dst: Pointer;
|
||||
dstCapacity: PCardinal): boolean cdecl;
|
||||
DLLLoaded: boolean = False;
|
||||
|
||||
implementation
|
||||
|
||||
var
|
||||
DLLHandle: THandle;
|
||||
|
||||
procedure Init;
|
||||
begin
|
||||
DLLHandle := LoadLibrary(PChar(ExtractFilePath(ParamStr(0)) +
|
||||
'grittibanzli_dll.dll'));
|
||||
if DLLHandle >= 32 then
|
||||
begin
|
||||
DLLLoaded := True;
|
||||
@Grittibanzli := GetProcAddress(DLLHandle, '__Grittibanzli');
|
||||
Assert(@Grittibanzli <> nil);
|
||||
@Ungrittibanzli := GetProcAddress(DLLHandle, '__Ungrittibanzli');
|
||||
Assert(@Ungrittibanzli <> nil);
|
||||
end
|
||||
else
|
||||
DLLLoaded := False;
|
||||
end;
|
||||
|
||||
procedure Deinit;
|
||||
begin
|
||||
if not DLLLoaded then
|
||||
exit;
|
||||
FreeLibrary(DLLHandle);
|
||||
end;
|
||||
|
||||
initialization
|
||||
|
||||
Init;
|
||||
|
||||
finalization
|
||||
|
||||
Deinit;
|
||||
|
||||
end.
|
68
imports/LZ4DLL.pas
Normal file
68
imports/LZ4DLL.pas
Normal file
@@ -0,0 +1,68 @@
|
||||
unit LZ4DLL;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
MemoryModule,
|
||||
WinAPI.Windows,
|
||||
System.SysUtils, System.Classes;
|
||||
|
||||
var
|
||||
LZ4_decompress_safe: function(source: Pointer; dest: Pointer;
|
||||
compressedSize: integer; maxDecompressedSize: integer): integer cdecl;
|
||||
LZ4_decompress_fast: function(source: Pointer; dest: Pointer;
|
||||
originalSize: integer): integer cdecl;
|
||||
LZ4_compress_default: function(src, dst: Pointer;
|
||||
srcSize, dstCapacity: integer): integer cdecl;
|
||||
LZ4_compress_fast: function(src, dst: Pointer; srcSize, dstCapacity: integer;
|
||||
acceleration: integer): integer cdecl;
|
||||
LZ4_compress_HC: function(const src: Pointer; dst: Pointer; srcSize: integer;
|
||||
maxDstSize: integer; compressionLevel: integer): integer cdecl;
|
||||
DLLLoaded: Boolean = False;
|
||||
|
||||
implementation
|
||||
|
||||
var
|
||||
DLLHandle: THandle;
|
||||
|
||||
procedure Init;
|
||||
begin
|
||||
if DLLLoaded then
|
||||
Exit;
|
||||
DLLHandle := 0;
|
||||
DLLHandle := LoadLibrary(PWideChar(ExtractFilePath(ParamStr(0)) +
|
||||
'liblz4.dll'));
|
||||
if DLLHandle >= 32 then
|
||||
begin
|
||||
DLLLoaded := True;
|
||||
@LZ4_decompress_safe := GetProcAddress(DLLHandle, 'LZ4_decompress_safe');
|
||||
Assert(@LZ4_decompress_safe <> nil);
|
||||
@LZ4_decompress_fast := GetProcAddress(DLLHandle, 'LZ4_decompress_fast');
|
||||
Assert(@LZ4_decompress_fast <> nil);
|
||||
@LZ4_compress_default := GetProcAddress(DLLHandle, 'LZ4_compress_default');
|
||||
Assert(@LZ4_compress_default <> nil);
|
||||
@LZ4_compress_fast := GetProcAddress(DLLHandle, 'LZ4_compress_fast');
|
||||
Assert(@LZ4_compress_fast <> nil);
|
||||
@LZ4_compress_HC := GetProcAddress(DLLHandle, 'LZ4_compress_HC');
|
||||
Assert(@LZ4_compress_HC <> nil);
|
||||
end
|
||||
else
|
||||
DLLLoaded := False;
|
||||
end;
|
||||
|
||||
procedure Deinit;
|
||||
begin
|
||||
if not DLLLoaded then
|
||||
Exit;
|
||||
FreeLibrary(DLLHandle);
|
||||
end;
|
||||
|
||||
initialization
|
||||
|
||||
Init;
|
||||
|
||||
finalization
|
||||
|
||||
Deinit;
|
||||
|
||||
end.
|
171
imports/LZODLL.pas
Normal file
171
imports/LZODLL.pas
Normal file
@@ -0,0 +1,171 @@
|
||||
unit LZODLL;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
WinAPI.Windows,
|
||||
System.SysUtils;
|
||||
|
||||
const
|
||||
Success = 0;
|
||||
GenericError = -1;
|
||||
OutOfMemory = -2;
|
||||
NotCompressible = -3;
|
||||
InputOverrun = -4;
|
||||
OutputOverrun = -5;
|
||||
LookbehindOverrun = -6;
|
||||
EndOfFileNotFound = -7;
|
||||
InputNotConsumed = -8;
|
||||
NotImplemented = -9;
|
||||
InvalidArgument = -10;
|
||||
|
||||
type
|
||||
lzo_free_func_t = procedure(self: Pointer; ptr: Pointer); cdecl;
|
||||
lzo_alloc_func_t = function(self: Pointer; items, size: LongWord)
|
||||
: Pointer; cdecl;
|
||||
lzo_progress_func_t = procedure(self: Pointer; a, b: LongWord;
|
||||
c: integer); cdecl;
|
||||
|
||||
lzo_callback_t = Record
|
||||
nalloc: lzo_alloc_func_t;
|
||||
nfree: lzo_free_func_t;
|
||||
nprogress: lzo_progress_func_t;
|
||||
user1: Pointer;
|
||||
user2: LongWord;
|
||||
user3: LongWord;
|
||||
end;
|
||||
|
||||
var
|
||||
lzo1x_1_compress: function(const src: Pointer; src_len: NativeUInt;
|
||||
dst: Pointer; dst_len: PNativeUInt; wrkmem: Pointer): integer; cdecl;
|
||||
lzo1x_1_11_compress: function(const src: Pointer; src_len: NativeUInt;
|
||||
dst: Pointer; dst_len: PNativeUInt; wrkmem: Pointer): integer; cdecl;
|
||||
lzo1x_1_12_compress: function(const src: Pointer; src_len: NativeUInt;
|
||||
dst: Pointer; dst_len: PNativeUInt; wrkmem: Pointer): integer; cdecl;
|
||||
lzo1x_1_15_compress: function(const src: Pointer; src_len: NativeUInt;
|
||||
dst: Pointer; dst_len: PNativeUInt; wrkmem: Pointer): integer; cdecl;
|
||||
lzo1x_999_compress: function(const src: Pointer; src_len: NativeUInt;
|
||||
dst: Pointer; dst_len: PNativeUInt; wrkmem: Pointer): integer; cdecl;
|
||||
lzo1x_999_compress_level: function(const src: Pointer; src_len: NativeUInt;
|
||||
dst: Pointer; dst_len: PNativeUInt; wrkmem: Pointer; const dict: Pointer;
|
||||
dict_len: Cardinal; cb: Pointer; compression_level: integer)
|
||||
: integer; cdecl;
|
||||
lzo1x_decompress_safe: function(const src: Pointer; src_len: NativeUInt;
|
||||
dst: Pointer; dst_len: PNativeUInt): integer cdecl;
|
||||
lzo1c_999_compress: function(const src: Pointer; src_len: NativeUInt;
|
||||
dst: Pointer; dst_len: PNativeUInt; wrkmem: Pointer): integer; cdecl;
|
||||
lzo1c_decompress_safe: function(const src: Pointer; src_len: NativeUInt;
|
||||
dst: Pointer; dst_len: PNativeUInt): integer cdecl;
|
||||
lzo2a_999_compress: function(const src: Pointer; src_len: NativeUInt;
|
||||
dst: Pointer; dst_len: PNativeUInt; wrkmem: Pointer): integer; cdecl;
|
||||
lzo2a_decompress_safe: function(const src: Pointer; src_len: NativeUInt;
|
||||
dst: Pointer; dst_len: PNativeUInt): integer cdecl;
|
||||
lzopro_lzo1x_w03_15_compress: function(const src: Pointer;
|
||||
src_len: NativeUInt; dst: Pointer; dst_len: PNativeUInt; wrkmem: Pointer)
|
||||
: integer; cdecl;
|
||||
lzopro_lzo1x_99_compress: function(const src; src_len: integer; var dst;
|
||||
var dst_len; var cb; compression_level: integer): integer; cdecl;
|
||||
DLLLoaded: Boolean = False;
|
||||
|
||||
function lzo1x_99_compress(const src: Pointer; src_len: NativeUInt;
|
||||
dst: Pointer; dst_len: PNativeUInt; compression_level: integer): integer;
|
||||
|
||||
implementation
|
||||
|
||||
var
|
||||
DLLHandle: THandle;
|
||||
|
||||
procedure nfree(self: Pointer; ptr: Pointer); cdecl;
|
||||
begin
|
||||
FreeMem(ptr);
|
||||
end;
|
||||
|
||||
function nalloc(self: Pointer; items, size: LongWord): Pointer; cdecl;
|
||||
var
|
||||
p: Pointer;
|
||||
begin
|
||||
GetMem(p, size * items);
|
||||
Result := p;
|
||||
end;
|
||||
|
||||
procedure nprogress(self: Pointer; a, b: LongWord; c: integer); cdecl;
|
||||
begin
|
||||
end;
|
||||
|
||||
function lzo1x_99_compress(const src: Pointer; src_len: NativeUInt;
|
||||
dst: Pointer; dst_len: PNativeUInt; compression_level: integer): integer;
|
||||
var
|
||||
mycb: lzo_callback_t;
|
||||
begin
|
||||
mycb.nalloc := nalloc;
|
||||
mycb.nfree := nfree;
|
||||
mycb.nprogress := nprogress;
|
||||
Result := lzopro_lzo1x_99_compress(src^, src_len, dst^, dst_len^, mycb,
|
||||
compression_level);
|
||||
end;
|
||||
|
||||
procedure Init;
|
||||
begin
|
||||
if DLLLoaded then
|
||||
Exit;
|
||||
DLLHandle := LoadLibrary(PChar(ExtractFilePath(ParamStr(0)) + 'lzo2.dll'));
|
||||
if DLLHandle >= 32 then
|
||||
begin
|
||||
DLLLoaded := True;
|
||||
@lzo1x_1_compress := GetProcAddress(DLLHandle, 'lzo1x_1_compress');
|
||||
Assert(@lzo1x_1_compress <> nil);
|
||||
@lzo1x_1_11_compress := GetProcAddress(DLLHandle, 'lzo1x_1_11_compress');
|
||||
Assert(@lzo1x_1_11_compress <> nil);
|
||||
@lzo1x_1_12_compress := GetProcAddress(DLLHandle, 'lzo1x_1_12_compress');
|
||||
Assert(@lzo1x_1_12_compress <> nil);
|
||||
@lzo1x_1_15_compress := GetProcAddress(DLLHandle, 'lzo1x_1_15_compress');
|
||||
Assert(@lzo1x_1_15_compress <> nil);
|
||||
@lzo1x_999_compress := GetProcAddress(DLLHandle, 'lzo1x_999_compress');
|
||||
Assert(@lzo1x_999_compress <> nil);
|
||||
@lzo1x_999_compress_level := GetProcAddress(DLLHandle,
|
||||
'lzo1x_999_compress_level');
|
||||
Assert(@lzo1x_999_compress_level <> nil);
|
||||
@lzo1x_decompress_safe := GetProcAddress(DLLHandle,
|
||||
'lzo1x_decompress_safe');
|
||||
Assert(@lzo1x_decompress_safe <> nil);
|
||||
@lzo1c_999_compress := GetProcAddress(DLLHandle, 'lzo1c_999_compress');
|
||||
Assert(@lzo1c_999_compress <> nil);
|
||||
@lzo1c_decompress_safe := GetProcAddress(DLLHandle,
|
||||
'lzo1c_decompress_safe');
|
||||
Assert(@lzo1c_decompress_safe <> nil);
|
||||
@lzo2a_999_compress := GetProcAddress(DLLHandle, 'lzo2a_999_compress');
|
||||
Assert(@lzo2a_999_compress <> nil);
|
||||
@lzo2a_decompress_safe := GetProcAddress(DLLHandle,
|
||||
'lzo2a_decompress_safe');
|
||||
Assert(@lzo2a_decompress_safe <> nil);
|
||||
(* if Length(lzoprodll) > 0 then
|
||||
begin
|
||||
MDLLHandle := MemoryLoadLibary(@lzoprodll[0]);
|
||||
@lzopro_lzo1x_w03_15_compress := MemoryGetProcAddress(MDLLHandle,
|
||||
'lzopro_lzo1x_w03_15_compress');
|
||||
Assert(@lzopro_lzo1x_w03_15_compress <> nil);
|
||||
@lzopro_lzo1x_99_compress := MemoryGetProcAddress(MDLLHandle,
|
||||
'lzopro_lzo1x_99_compress');
|
||||
Assert(@lzopro_lzo1x_99_compress <> nil);
|
||||
end; *)
|
||||
end
|
||||
else
|
||||
DLLLoaded := False;
|
||||
end;
|
||||
|
||||
procedure Deinit;
|
||||
begin
|
||||
if not DLLLoaded then
|
||||
Exit;
|
||||
FreeLibrary(DLLHandle);
|
||||
end;
|
||||
|
||||
initialization
|
||||
|
||||
Init;
|
||||
|
||||
finalization
|
||||
|
||||
Deinit;
|
||||
|
||||
end.
|
236
imports/OodleDLL.pas
Normal file
236
imports/OodleDLL.pas
Normal file
@@ -0,0 +1,236 @@
|
||||
unit OodleDLL;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
WinAPI.Windows,
|
||||
System.SysUtils, System.Types, System.IOUtils;
|
||||
|
||||
type
|
||||
POodleLZ_CompressOptions = ^TOodleLZ_CompressOptions;
|
||||
|
||||
TOodleLZ_CompressOptions = record
|
||||
verbosity: Integer;
|
||||
minMatchLen: Integer;
|
||||
seekChunkReset: LongBool;
|
||||
seekChunkLen: Integer;
|
||||
profile: Cardinal;
|
||||
dictionarySize: Integer;
|
||||
spaceSpeedTradeoffBytes: Integer;
|
||||
maxHuffmansPerChunk: Integer;
|
||||
sendQuantumCRCs: LongBool;
|
||||
maxLocalDictionarySize: Integer;
|
||||
makeLongRangeMatcher: LongBool;
|
||||
matchTableSizeLog2: Integer;
|
||||
jobify: Integer;
|
||||
jobifyUserPtr: Pointer;
|
||||
farMatchMinLen: Integer;
|
||||
farMatchOffsetLog2: Integer;
|
||||
reserved: array [0 .. 3] of Integer;
|
||||
end;
|
||||
|
||||
var
|
||||
Oodle_CheckVersion: function(oodle_header_version: Cardinal;
|
||||
pOodleLibVersion: PCardinal = nil): LongBool stdcall;
|
||||
OodleLZ_Compress_1: function(compressor: Integer; rawBuf: Pointer;
|
||||
rawLen: NativeUInt; compBuf: Pointer; compressSelect: Integer = 6;
|
||||
pOptions: POodleLZ_CompressOptions = nil; dictionaryBase: Pointer = nil;
|
||||
lrm: Pointer = nil): NativeUInt stdcall;
|
||||
OodleLZ_Compress_2: function(compressor: Integer; rawBuf: Pointer;
|
||||
rawLen: NativeUInt; compBuf: Pointer; compressSelect: Integer = 6;
|
||||
pOptions: POodleLZ_CompressOptions = nil; dictionaryBase: Pointer = nil;
|
||||
lrm: Pointer = nil; scratchMem: Pointer = nil; scratchSize: NativeUInt = 0)
|
||||
: NativeUInt stdcall;
|
||||
OodleLZ_Decompress: function(const compBuf: Pointer; compBufSize: NativeUInt;
|
||||
rawBuf: Pointer; rawLen: NativeUInt; OodleLZ_FuzzSafe: Integer = 0;
|
||||
OodleLZ_CheckCRC: Integer = 0; OodleLZ_Verbosity: Integer = 0;
|
||||
decBufBase: Pointer = nil; decBufSize: NativeUInt = 0;
|
||||
fpCallback: Pointer = nil; callbackUserData: Pointer = nil;
|
||||
decoderMemory: Pointer = nil; decoderMemorySize: NativeUInt = 0;
|
||||
threadPhase: Integer = 0): NativeUInt stdcall;
|
||||
OodleLZ_CompressOptions_GetDefault_1: function(compressor: Integer;
|
||||
lzLevel: Integer): POodleLZ_CompressOptions stdcall;
|
||||
OodleLZ_CompressOptions_GetDefault_2: function
|
||||
: POodleLZ_CompressOptions stdcall;
|
||||
OodleLZ_GetCompressedBufferSizeNeeded_1: function(rawSize: NativeUInt)
|
||||
: NativeUInt stdcall;
|
||||
OodleLZ_GetCompressedBufferSizeNeeded_2: function(compressor: Integer;
|
||||
rawSize: NativeUInt): NativeUInt stdcall;
|
||||
|
||||
DLLLoaded: Boolean = False;
|
||||
|
||||
function OodleLZ_Compress(compressor: Integer; rawBuf: Pointer;
|
||||
rawLen: NativeUInt; compBuf: Pointer; compressSelect: Integer = 6;
|
||||
pOptions: POodleLZ_CompressOptions = nil; dictionaryBase: Pointer = nil;
|
||||
lrm: Pointer = nil; scratchMem: Pointer = nil; scratchSize: NativeUInt = 0)
|
||||
: NativeUInt;
|
||||
function OodleLZ_CompressOptions_GetDefault(compressor: Integer;
|
||||
lzLevel: Integer): POodleLZ_CompressOptions;
|
||||
function OodleLZ_GetCompressedBufferSizeNeeded(compressor: Byte;
|
||||
rawSize: NativeUInt): NativeUInt;
|
||||
|
||||
implementation
|
||||
|
||||
var
|
||||
DLLHandle: THandle;
|
||||
OldCompress, OldCompressOptions_GetDefault,
|
||||
OldGetCompressedBufferSizeNeeded: Boolean;
|
||||
DLLs: TStringDynArray;
|
||||
|
||||
procedure Init;
|
||||
var
|
||||
I: Integer;
|
||||
C: Cardinal;
|
||||
begin
|
||||
if DLLLoaded then
|
||||
Exit;
|
||||
DLLs := TDirectory.GetFiles(ExtractFilePath(ParamStr(0)), 'oo2core*.dll',
|
||||
TSearchOption.soTopDirectoryOnly);
|
||||
for I := Low(DLLs) to High(DLLs) do
|
||||
begin
|
||||
DLLHandle := LoadLibrary(PChar(DLLs[I]));
|
||||
if DLLHandle >= 32 then
|
||||
break;
|
||||
end;
|
||||
if DLLHandle < 32 then
|
||||
begin
|
||||
DLLs := TDirectory.GetFiles(ExtractFilePath(ParamStr(0)), 'oo2ext*.dll',
|
||||
TSearchOption.soTopDirectoryOnly);
|
||||
for I := Low(DLLs) to High(DLLs) do
|
||||
begin
|
||||
DLLHandle := LoadLibrary(PChar(DLLs[I]));
|
||||
if DLLHandle >= 32 then
|
||||
break;
|
||||
end;
|
||||
end;
|
||||
if DLLHandle < 32 then
|
||||
begin
|
||||
DLLs := TDirectory.GetFiles(ExtractFilePath(ParamStr(0)), 'oodle2*.dll',
|
||||
TSearchOption.soTopDirectoryOnly);
|
||||
SetLength(DLLs, Succ(Length(DLLs)));
|
||||
DLLs[Pred(Length(DLLs))] := ExtractFilePath(ParamStr(0)) + 'oodle.dll';
|
||||
for I := Low(DLLs) to High(DLLs) do
|
||||
begin
|
||||
DLLHandle := LoadLibrary(PChar(DLLs[I]));
|
||||
if DLLHandle >= 32 then
|
||||
break;
|
||||
end;
|
||||
end;
|
||||
if DLLHandle >= 32 then
|
||||
begin
|
||||
DLLLoaded := True;
|
||||
Oodle_CheckVersion := GetProcAddress(DLLHandle, 'Oodle_CheckVersion');
|
||||
if not Assigned(Oodle_CheckVersion) then
|
||||
for I := 0 to 32 do
|
||||
begin
|
||||
@Oodle_CheckVersion := GetProcAddress(DLLHandle,
|
||||
PChar('_Oodle_CheckVersion@' + (I * 2).ToString));
|
||||
if Assigned(Oodle_CheckVersion) then
|
||||
break;
|
||||
end;
|
||||
Assert(@Oodle_CheckVersion <> nil);
|
||||
Oodle_CheckVersion(0, @C);
|
||||
OldCompress := LongRec(C).Hi < $2E06;
|
||||
OldGetCompressedBufferSizeNeeded := LongRec(C).Hi < $2E08;
|
||||
OldCompressOptions_GetDefault := LongRec(C).Hi < $2E08;
|
||||
@OodleLZ_Compress_1 := GetProcAddress(DLLHandle, 'OodleLZ_Compress');
|
||||
if not Assigned(OodleLZ_Compress_1) then
|
||||
for I := 0 to 32 do
|
||||
begin
|
||||
@OodleLZ_Compress_1 := GetProcAddress(DLLHandle,
|
||||
PChar('_OodleLZ_Compress@' + (I * 2).ToString));
|
||||
if Assigned(OodleLZ_Compress_1) then
|
||||
break;
|
||||
end;
|
||||
Assert(@OodleLZ_Compress_1 <> nil);
|
||||
@OodleLZ_Compress_2 := @OodleLZ_Compress_1;
|
||||
OodleLZ_Decompress := GetProcAddress(DLLHandle, 'OodleLZ_Decompress');
|
||||
if not Assigned(OodleLZ_Decompress) then
|
||||
for I := 0 to 32 do
|
||||
begin
|
||||
@OodleLZ_Decompress := GetProcAddress(DLLHandle,
|
||||
PChar('_OodleLZ_Decompress@' + (I * 2).ToString));
|
||||
if Assigned(OodleLZ_Decompress) then
|
||||
break;
|
||||
end;
|
||||
Assert(@OodleLZ_Decompress <> nil);
|
||||
OodleLZ_CompressOptions_GetDefault_1 := GetProcAddress(DLLHandle,
|
||||
'OodleLZ_CompressOptions_GetDefault');
|
||||
if not Assigned(OodleLZ_CompressOptions_GetDefault_1) then
|
||||
for I := 0 to 32 do
|
||||
begin
|
||||
@OodleLZ_CompressOptions_GetDefault_1 :=
|
||||
GetProcAddress(DLLHandle, PChar('_OodleLZ_CompressOptions_GetDefault@'
|
||||
+ (I * 2).ToString));
|
||||
if Assigned(OodleLZ_CompressOptions_GetDefault_1) then
|
||||
break;
|
||||
end;
|
||||
Assert(@OodleLZ_CompressOptions_GetDefault_1 <> nil);
|
||||
@OodleLZ_CompressOptions_GetDefault_2 :=
|
||||
@OodleLZ_CompressOptions_GetDefault_1;
|
||||
OodleLZ_GetCompressedBufferSizeNeeded_1 :=
|
||||
GetProcAddress(DLLHandle, 'OodleLZ_GetCompressedBufferSizeNeeded');
|
||||
if not Assigned(OodleLZ_GetCompressedBufferSizeNeeded_1) then
|
||||
for I := 0 to 32 do
|
||||
begin
|
||||
@OodleLZ_GetCompressedBufferSizeNeeded_1 :=
|
||||
GetProcAddress(DLLHandle,
|
||||
PChar('_OodleLZ_GetCompressedBufferSizeNeeded@' + (I * 2).ToString));
|
||||
if Assigned(OodleLZ_GetCompressedBufferSizeNeeded_1) then
|
||||
break;
|
||||
end;
|
||||
Assert(@OodleLZ_GetCompressedBufferSizeNeeded_1 <> nil);
|
||||
@OodleLZ_GetCompressedBufferSizeNeeded_2 :=
|
||||
@OodleLZ_GetCompressedBufferSizeNeeded_1;
|
||||
end
|
||||
else
|
||||
DLLLoaded := False;
|
||||
end;
|
||||
|
||||
procedure Deinit;
|
||||
begin
|
||||
if not DLLLoaded then
|
||||
Exit;
|
||||
FreeLibrary(DLLHandle);
|
||||
end;
|
||||
|
||||
function OodleLZ_Compress(compressor: Integer; rawBuf: Pointer;
|
||||
rawLen: NativeUInt; compBuf: Pointer; compressSelect: Integer;
|
||||
pOptions: POodleLZ_CompressOptions; dictionaryBase: Pointer; lrm: Pointer;
|
||||
scratchMem: Pointer; scratchSize: NativeUInt): NativeUInt;
|
||||
begin
|
||||
if OldCompress then
|
||||
Result := OodleLZ_Compress_1(compressor, rawBuf, rawLen, compBuf,
|
||||
compressSelect, pOptions, dictionaryBase, lrm)
|
||||
else
|
||||
Result := OodleLZ_Compress_2(compressor, rawBuf, rawLen, compBuf,
|
||||
compressSelect, pOptions, dictionaryBase, lrm, scratchMem, scratchSize);
|
||||
end;
|
||||
|
||||
function OodleLZ_CompressOptions_GetDefault(compressor: Integer;
|
||||
lzLevel: Integer): POodleLZ_CompressOptions;
|
||||
begin
|
||||
if OldCompressOptions_GetDefault then
|
||||
Result := OodleLZ_CompressOptions_GetDefault_1(compressor, lzLevel)
|
||||
else
|
||||
Result := OodleLZ_CompressOptions_GetDefault_2;
|
||||
end;
|
||||
|
||||
function OodleLZ_GetCompressedBufferSizeNeeded(compressor: Byte;
|
||||
rawSize: NativeUInt): NativeUInt;
|
||||
begin
|
||||
if OldGetCompressedBufferSizeNeeded then
|
||||
Result := OodleLZ_GetCompressedBufferSizeNeeded_1(rawSize)
|
||||
else
|
||||
Result := OodleLZ_GetCompressedBufferSizeNeeded_2(compressor, rawSize);
|
||||
end;
|
||||
|
||||
initialization
|
||||
|
||||
Init;
|
||||
|
||||
finalization
|
||||
|
||||
Deinit;
|
||||
|
||||
end.
|
54
imports/PreflateDLL.pas
Normal file
54
imports/PreflateDLL.pas
Normal file
@@ -0,0 +1,54 @@
|
||||
unit PreflateDLL;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
WinAPI.Windows,
|
||||
System.SysUtils, System.Classes;
|
||||
|
||||
var
|
||||
preflate_decode: function(const src: Pointer; srcSize: integer; dst1: Pointer;
|
||||
dst1Capacity: PInteger; dst2: Pointer; dst2Capacity: PInteger)
|
||||
: boolean cdecl;
|
||||
preflate_reencode: function(const src1: Pointer; src1Size: integer;
|
||||
const src2: Pointer; src2Size: integer; dst: Pointer; dstCapacity: PInteger)
|
||||
: boolean cdecl;
|
||||
DLLLoaded: boolean = False;
|
||||
|
||||
implementation
|
||||
|
||||
var
|
||||
DLLHandle: THandle;
|
||||
|
||||
procedure Init;
|
||||
begin
|
||||
DLLHandle := LoadLibrary(PChar(ExtractFilePath(ParamStr(0)) +
|
||||
'preflate_dll.dll'));
|
||||
if DLLHandle >= 32 then
|
||||
begin
|
||||
DLLLoaded := True;
|
||||
@preflate_decode := GetProcAddress(DLLHandle, 'decode');
|
||||
Assert(@preflate_decode <> nil);
|
||||
@preflate_reencode := GetProcAddress(DLLHandle, 'reencode');
|
||||
Assert(@preflate_reencode <> nil);
|
||||
end
|
||||
else
|
||||
DLLLoaded := False;
|
||||
end;
|
||||
|
||||
procedure Deinit;
|
||||
begin
|
||||
if not DLLLoaded then
|
||||
exit;
|
||||
FreeLibrary(DLLHandle);
|
||||
end;
|
||||
|
||||
initialization
|
||||
|
||||
Init;
|
||||
|
||||
finalization
|
||||
|
||||
Deinit;
|
||||
|
||||
end.
|
86
imports/ReflateDLL.pas
Normal file
86
imports/ReflateDLL.pas
Normal file
@@ -0,0 +1,86 @@
|
||||
unit ReflateDLL;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
WinAPI.Windows,
|
||||
System.SysUtils, System.Classes;
|
||||
|
||||
var
|
||||
raw2hif_Alloc: function: Pointer stdcall;
|
||||
raw2hif_Free: procedure(p: Pointer)stdcall;
|
||||
raw2hif_Init: procedure(p: Pointer; level: integer)stdcall;
|
||||
raw2hif_Loop: function(p: Pointer): integer stdcall;
|
||||
raw2hif_getoutlen: function(p: Pointer): integer stdcall;
|
||||
raw2hif_getou2len: function(p: Pointer): integer stdcall;
|
||||
raw2hif_addbuf: procedure(p: Pointer; buf: Pointer; bufsize: integer)stdcall;
|
||||
hif2raw_Alloc: function: Pointer stdcall;
|
||||
hif2raw_Free: procedure(p: Pointer)stdcall;
|
||||
hif2raw_Init: procedure(p: Pointer; level: integer)stdcall;
|
||||
hif2raw_Loop: function(p: Pointer): integer stdcall;
|
||||
hif2raw_getoutlen: function(p: Pointer): integer stdcall;
|
||||
hif2raw_addbuf: procedure(p: Pointer; buf: Pointer; bufsize: integer)stdcall;
|
||||
DLLLoaded: boolean = False;
|
||||
|
||||
implementation
|
||||
|
||||
var
|
||||
DLLHandle1, DLLHandle2: THandle;
|
||||
|
||||
procedure Init;
|
||||
begin
|
||||
DLLHandle1 := LoadLibrary(PChar(ExtractFilePath(ParamStr(0)) +
|
||||
'RAW2HIF_DLL.DLL'));
|
||||
DLLHandle2 := LoadLibrary(PChar(ExtractFilePath(ParamStr(0)) +
|
||||
'HIF2RAW_DLL.DLL'));
|
||||
if (DLLHandle1 >= 32) and (DLLHandle2 >= 32) then
|
||||
begin
|
||||
DLLLoaded := True;
|
||||
@raw2hif_Alloc := GetProcAddress(DLLHandle1, 'raw2hif_Alloc');
|
||||
Assert(@raw2hif_Alloc <> nil);
|
||||
@raw2hif_Free := GetProcAddress(DLLHandle1, 'raw2hif_Free');
|
||||
Assert(@raw2hif_Free <> nil);
|
||||
@raw2hif_Init := GetProcAddress(DLLHandle1, 'raw2hif_Init');
|
||||
Assert(@raw2hif_Init <> nil);
|
||||
@raw2hif_Loop := GetProcAddress(DLLHandle1, 'raw2hif_Loop');
|
||||
Assert(@raw2hif_Loop <> nil);
|
||||
@raw2hif_getoutlen := GetProcAddress(DLLHandle1, 'raw2hif_getoutlen');
|
||||
Assert(@raw2hif_getoutlen <> nil);
|
||||
@raw2hif_getou2len := GetProcAddress(DLLHandle1, 'raw2hif_getou2len');
|
||||
Assert(@raw2hif_getou2len <> nil);
|
||||
@raw2hif_addbuf := GetProcAddress(DLLHandle1, 'raw2hif_addbuf');
|
||||
Assert(@raw2hif_addbuf <> nil);
|
||||
@hif2raw_Alloc := GetProcAddress(DLLHandle2, 'hif2raw_Alloc');
|
||||
Assert(@hif2raw_Alloc <> nil);
|
||||
@hif2raw_Free := GetProcAddress(DLLHandle2, 'hif2raw_Free');
|
||||
Assert(@hif2raw_Free <> nil);
|
||||
@hif2raw_Init := GetProcAddress(DLLHandle2, 'hif2raw_Init');
|
||||
Assert(@hif2raw_Init <> nil);
|
||||
@hif2raw_Loop := GetProcAddress(DLLHandle2, 'hif2raw_Loop');
|
||||
Assert(@hif2raw_Loop <> nil);
|
||||
@hif2raw_getoutlen := GetProcAddress(DLLHandle2, 'hif2raw_getoutlen');
|
||||
Assert(@hif2raw_getoutlen <> nil);
|
||||
@hif2raw_addbuf := GetProcAddress(DLLHandle2, 'hif2raw_addbuf');
|
||||
Assert(@hif2raw_addbuf <> nil);
|
||||
end
|
||||
else
|
||||
DLLLoaded := False;
|
||||
end;
|
||||
|
||||
procedure Deinit;
|
||||
begin
|
||||
if not DLLLoaded then
|
||||
exit;
|
||||
FreeLibrary(DLLHandle1);
|
||||
FreeLibrary(DLLHandle2);
|
||||
end;
|
||||
|
||||
initialization
|
||||
|
||||
Init;
|
||||
|
||||
finalization
|
||||
|
||||
Deinit;
|
||||
|
||||
end.
|
82
imports/XDeltaDLL.pas
Normal file
82
imports/XDeltaDLL.pas
Normal file
@@ -0,0 +1,82 @@
|
||||
unit XDeltaDLL;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
MemoryModule,
|
||||
WinAPI.Windows,
|
||||
System.SysUtils, System.Classes;
|
||||
|
||||
type
|
||||
xd3_flags = (XD3_JUST_HDR = (1 shl 1), XD3_SKIP_WINDOW = (1 shl 2),
|
||||
XD3_SKIP_EMIT = (1 shl 3), XD3_FLUSH = (1 shl 4), XD3_SEC_DJW = (1 shl 5),
|
||||
XD3_SEC_FGK = (1 shl 6), XD3_SEC_LZMA = (1 shl 24),
|
||||
XD3_SEC_TYPE = (XD3_SEC_DJW or XD3_SEC_FGK or XD3_SEC_LZMA),
|
||||
XD3_SEC_NODATA = (1 shl 7), XD3_SEC_NOINST = (1 shl 8),
|
||||
XD3_SEC_NOADDR = (1 shl 9), XD3_SEC_NOALL = (XD3_SEC_NODATA or
|
||||
XD3_SEC_NOINST or XD3_SEC_NOADDR), XD3_ADLER32 = (1 shl 10),
|
||||
XD3_ADLER32_NOVER = (1 shl 11), XD3_NOCOMPRESS = (1 shl 13),
|
||||
XD3_BEGREEDY = (1 shl 14), XD3_ADLER32_RECODE = (1 shl 15),
|
||||
XD3_COMPLEVEL_SHIFT = 20, XD3_COMPLEVEL_MASK = ($F shl XD3_COMPLEVEL_SHIFT),
|
||||
XD3_COMPLEVEL_1 = (1 shl XD3_COMPLEVEL_SHIFT),
|
||||
XD3_COMPLEVEL_2 = (2 shl XD3_COMPLEVEL_SHIFT),
|
||||
XD3_COMPLEVEL_3 = (3 shl XD3_COMPLEVEL_SHIFT),
|
||||
XD3_COMPLEVEL_6 = (6 shl XD3_COMPLEVEL_SHIFT),
|
||||
XD3_COMPLEVEL_9 = (9 shl XD3_COMPLEVEL_SHIFT));
|
||||
|
||||
var
|
||||
xd3_encode: function(const input: PByte; input_size: NativeUInt;
|
||||
source: PByte; source_size: NativeUInt; output_buffer: PByte;
|
||||
output_size: PNativeUInt; avail_output: NativeUInt; flags: Integer)
|
||||
: Integer cdecl;
|
||||
xd3_decode: function(const input: PByte; input_size: NativeUInt;
|
||||
source: PByte; source_size: NativeUInt; output_buf: PByte;
|
||||
output_size: PNativeUInt; avail_output: NativeUInt; flags: Integer)
|
||||
: Integer cdecl;
|
||||
DLLLoaded: boolean = False;
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
Utils;
|
||||
|
||||
var
|
||||
DLLStream: TResourceStream;
|
||||
DLLHandle: TMemoryModule;
|
||||
|
||||
procedure Init;
|
||||
begin
|
||||
{$IFDEF WIN32}
|
||||
DLLStream := TResourceStream.Create(HInstance, 'XDELTA86_DLL', RT_RCDATA);
|
||||
{$ELSE}
|
||||
DLLStream := TResourceStream.Create(HInstance, 'XDELTA64_DLL', RT_RCDATA);
|
||||
{$ENDIF}
|
||||
DLLHandle := MemoryLoadLibary(DLLStream.Memory);
|
||||
if Assigned(DLLHandle) then
|
||||
begin
|
||||
DLLLoaded := True;
|
||||
@xd3_encode := MemoryGetProcAddress(DLLHandle, 'xd3_encode');
|
||||
Assert(@xd3_encode <> nil);
|
||||
@xd3_decode := MemoryGetProcAddress(DLLHandle, 'xd3_decode');
|
||||
Assert(@xd3_decode <> nil);
|
||||
end
|
||||
else
|
||||
DLLLoaded := False;
|
||||
end;
|
||||
|
||||
procedure Deinit;
|
||||
begin
|
||||
if not DLLLoaded then
|
||||
exit;
|
||||
MemoryFreeLibrary(DLLHandle);
|
||||
end;
|
||||
|
||||
initialization
|
||||
|
||||
Init;
|
||||
|
||||
finalization
|
||||
|
||||
Deinit;
|
||||
|
||||
end.
|
215
imports/ZLibDLL.pas
Normal file
215
imports/ZLibDLL.pas
Normal file
@@ -0,0 +1,215 @@
|
||||
unit ZLibDLL;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
WinAPI.Windows,
|
||||
System.SysUtils, System.Types, System.IOUtils, System.ZLib;
|
||||
|
||||
const
|
||||
Z_NO_FLUSH = 0;
|
||||
Z_PARTIAL_FLUSH = 1;
|
||||
Z_SYNC_FLUSH = 2;
|
||||
Z_FULL_FLUSH = 3;
|
||||
Z_FINISH = 4;
|
||||
Z_BLOCK = 5;
|
||||
Z_TREES = 6;
|
||||
|
||||
Z_OK = 0;
|
||||
Z_STREAM_END = 1;
|
||||
Z_NEED_DICT = 2;
|
||||
Z_ERRNO = (-1);
|
||||
Z_STREAM_ERROR = (-2);
|
||||
Z_DATA_ERROR = (-3);
|
||||
Z_MEM_ERROR = (-4);
|
||||
Z_BUF_ERROR = (-5);
|
||||
Z_VERSION_ERROR = (-6);
|
||||
|
||||
Z_FILTERED = 1;
|
||||
Z_HUFFMAN_ONLY = 2;
|
||||
Z_RLE = 3;
|
||||
Z_FIXED = 4;
|
||||
Z_DEFAULT_STRATEGY = 0;
|
||||
|
||||
Z_DEFLATED = 8;
|
||||
|
||||
_z_errmsg: array [0 .. 9] of PAnsiChar = ('need dictionary', 'stream end', '',
|
||||
'file error', 'stream error', 'data error', 'insufficient memory',
|
||||
'buffer error', 'incompatible version', '');
|
||||
|
||||
type
|
||||
alloc_func = function(opaque: Pointer; Items, Size: cardinal): Pointer; cdecl;
|
||||
free_func = procedure(opaque, address: Pointer); cdecl;
|
||||
|
||||
internal_state = record
|
||||
end;
|
||||
|
||||
Pinternal_state = ^internal_state;
|
||||
|
||||
z_stream = System.ZLib.z_stream;
|
||||
z_streamp = ^z_stream;
|
||||
|
||||
EZLibError = class(Exception);
|
||||
EZCompressionError = class(EZLibError);
|
||||
EZDecompressionError = class(EZLibError);
|
||||
|
||||
var
|
||||
_zlibVersion: function: PAnsiChar; stdcall;
|
||||
_zlibCompileFlags: function: LongWord; stdcall;
|
||||
|
||||
s_deflateInit2_: function(var strm: z_stream;
|
||||
level, method, windowBits, memLevel, strategy: integer; version: PAnsiChar;
|
||||
stream_size: integer): integer stdcall;
|
||||
s_deflate: function(var strm: z_stream; flush: integer): integer stdcall;
|
||||
s_deflateEnd: function(var strm: z_stream): integer stdcall;
|
||||
s_deflateReset: function(var strm: z_stream): integer stdcall;
|
||||
|
||||
c_deflateInit2_: function(var strm: z_stream;
|
||||
level, method, windowBits, memLevel, strategy: integer; version: PAnsiChar;
|
||||
stream_size: integer): integer cdecl;
|
||||
c_deflate: function(var strm: z_stream; flush: integer): integer cdecl;
|
||||
c_deflateEnd: function(var strm: z_stream): integer cdecl;
|
||||
c_deflateReset: function(var strm: z_stream): integer cdecl;
|
||||
|
||||
DLLLoaded: boolean = False;
|
||||
|
||||
function deflateInit2(var strm: z_stream; level, method, windowBits, memLevel,
|
||||
strategy: integer): integer;
|
||||
function deflate(var strm: z_stream; flush: integer): integer;
|
||||
function deflateEnd(var strm: z_stream): integer;
|
||||
function deflateReset(var strm: z_stream): integer;
|
||||
function inflateInit2(var strm: z_stream; windowBits: integer): integer;
|
||||
function inflate(var strm: z_stream; flush: integer): integer;
|
||||
function inflateEnd(var strm: z_stream): integer;
|
||||
function inflateReset(var strm: z_stream): integer;
|
||||
|
||||
implementation
|
||||
|
||||
var
|
||||
DLLHandle: THandle;
|
||||
WinAPIDLL: boolean;
|
||||
DLLs: TStringDynArray;
|
||||
|
||||
procedure Init;
|
||||
var
|
||||
I: integer;
|
||||
begin
|
||||
if DLLLoaded then
|
||||
Exit;
|
||||
DLLs := TDirectory.GetFiles(ExtractFilePath(ParamStr(0)), 'zlib*.dll',
|
||||
TSearchOption.soTopDirectoryOnly);
|
||||
Insert(ExtractFilePath(ParamStr(0)) + 'zlib.dll', DLLs, Length(DLLs));
|
||||
for I := Low(DLLs) to High(DLLs) do
|
||||
begin
|
||||
DLLHandle := LoadLibrary(PChar(DLLs[I]));
|
||||
if (DLLHandle >= 32) and Assigned(GetProcAddress(DLLHandle, 'zlibVersion'))
|
||||
then
|
||||
break;
|
||||
end;
|
||||
if DLLHandle >= 32 then
|
||||
begin
|
||||
DLLLoaded := True;
|
||||
@_zlibVersion := GetProcAddress(DLLHandle, 'zlibVersion');
|
||||
Assert(@_zlibVersion <> nil);
|
||||
@_zlibCompileFlags := GetProcAddress(DLLHandle, 'zlibCompileFlags');
|
||||
Assert(@_zlibCompileFlags <> nil);
|
||||
WinAPIDLL := _zlibCompileFlags and $400 = $400;
|
||||
if WinAPIDLL then
|
||||
begin
|
||||
@s_deflateInit2_ := GetProcAddress(DLLHandle, 'deflateInit2_');
|
||||
Assert(@s_deflateInit2_ <> nil);
|
||||
@s_deflate := GetProcAddress(DLLHandle, 'deflate');
|
||||
Assert(@s_deflate <> nil);
|
||||
@s_deflateEnd := GetProcAddress(DLLHandle, 'deflateEnd');
|
||||
Assert(@s_deflateEnd <> nil);
|
||||
@s_deflateReset := GetProcAddress(DLLHandle, 'deflateReset');
|
||||
Assert(@s_deflateReset <> nil);
|
||||
end
|
||||
else
|
||||
begin
|
||||
@c_deflateInit2_ := GetProcAddress(DLLHandle, 'deflateInit2_');
|
||||
Assert(@c_deflateInit2_ <> nil);
|
||||
@c_deflate := GetProcAddress(DLLHandle, 'deflate');
|
||||
Assert(@c_deflate <> nil);
|
||||
@c_deflateEnd := GetProcAddress(DLLHandle, 'deflateEnd');
|
||||
Assert(@c_deflateEnd <> nil);
|
||||
@c_deflateReset := GetProcAddress(DLLHandle, 'deflateReset');
|
||||
Assert(@c_deflateReset <> nil);
|
||||
end;
|
||||
end
|
||||
else
|
||||
DLLLoaded := False;
|
||||
end;
|
||||
|
||||
function deflateInit2(var strm: z_stream; level, method, windowBits, memLevel,
|
||||
strategy: integer): integer;
|
||||
begin
|
||||
if WinAPIDLL then
|
||||
Result := s_deflateInit2_(strm, level, method, windowBits, memLevel,
|
||||
strategy, _zlibVersion, SizeOf(z_stream))
|
||||
else
|
||||
Result := c_deflateInit2_(strm, level, method, windowBits, memLevel,
|
||||
strategy, _zlibVersion, SizeOf(z_stream));
|
||||
end;
|
||||
|
||||
function deflate(var strm: z_stream; flush: integer): integer;
|
||||
begin
|
||||
if WinAPIDLL then
|
||||
Result := s_deflate(strm, flush)
|
||||
else
|
||||
Result := c_deflate(strm, flush);
|
||||
end;
|
||||
|
||||
function deflateEnd(var strm: z_stream): integer;
|
||||
begin
|
||||
if WinAPIDLL then
|
||||
Result := s_deflateEnd(strm)
|
||||
else
|
||||
Result := c_deflateEnd(strm);
|
||||
end;
|
||||
|
||||
function deflateReset(var strm: z_stream): integer;
|
||||
begin
|
||||
if WinAPIDLL then
|
||||
Result := s_deflateReset(strm)
|
||||
else
|
||||
Result := c_deflateReset(strm);
|
||||
end;
|
||||
|
||||
function inflateInit2(var strm: z_stream; windowBits: integer): integer;
|
||||
begin
|
||||
Result := System.ZLib.inflateInit2_(strm, windowBits,
|
||||
System.ZLib.ZLIB_VERSION, SizeOf(z_stream));
|
||||
end;
|
||||
|
||||
function inflate(var strm: z_stream; flush: integer): integer;
|
||||
begin
|
||||
Result := System.ZLib.inflate(strm, flush);
|
||||
end;
|
||||
|
||||
function inflateEnd(var strm: z_stream): integer;
|
||||
begin
|
||||
Result := System.ZLib.inflateEnd(strm);
|
||||
end;
|
||||
|
||||
function inflateReset(var strm: z_stream): integer;
|
||||
begin
|
||||
Result := System.ZLib.inflateReset(strm);
|
||||
end;
|
||||
|
||||
procedure Deinit;
|
||||
begin
|
||||
if not DLLLoaded then
|
||||
Exit;
|
||||
FreeLibrary(DLLHandle);
|
||||
end;
|
||||
|
||||
initialization
|
||||
|
||||
Init;
|
||||
|
||||
finalization
|
||||
|
||||
Deinit;
|
||||
|
||||
end.
|
258
imports/ZSTDDLL.pas
Normal file
258
imports/ZSTDDLL.pas
Normal file
@@ -0,0 +1,258 @@
|
||||
unit ZSTDDLL;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
WinAPI.Windows,
|
||||
System.SysUtils;
|
||||
|
||||
type
|
||||
ZSTD_strategy = (ZSTD_fast = 1, ZSTD_dfast = 2, ZSTD_greedy = 3,
|
||||
ZSTD_lazy = 4, ZSTD_lazy2 = 5, ZSTD_btlazy2 = 6, ZSTD_btopt = 7,
|
||||
ZSTD_btultra = 8, ZSTD_btultra2 = 9);
|
||||
|
||||
ZSTD_ResetDirective = (ZSTD_reset_session_only = 1, ZSTD_reset_parameters = 2,
|
||||
ZSTD_reset_session_and_parameters = 3);
|
||||
|
||||
PZSTD_inBuffer = ^ZSTD_inBuffer;
|
||||
|
||||
ZSTD_inBuffer = record
|
||||
src: Pointer;
|
||||
size: size_t;
|
||||
pos: size_t;
|
||||
end;
|
||||
|
||||
PZSTD_outBuffer = ^ZSTD_outBuffer;
|
||||
|
||||
ZSTD_outBuffer = record
|
||||
dst: Pointer;
|
||||
size: size_t;
|
||||
pos: size_t;
|
||||
end;
|
||||
|
||||
PZSTD_CCtx_params = Pointer;
|
||||
|
||||
ZSTD_cParameter = (ZSTD_c_compressionLevel = 100, ZSTD_c_windowLog = 101,
|
||||
ZSTD_c_hashLog = 102, ZSTD_c_chainLog = 103, ZSTD_c_searchLog = 104,
|
||||
ZSTD_c_minMatch = 105, ZSTD_c_targetLength = 106, ZSTD_c_strategy = 107,
|
||||
ZSTD_c_enableLongDistanceMatching = 160, ZSTD_c_ldmHashLog = 161,
|
||||
ZSTD_c_ldmMinMatch = 162, ZSTD_c_ldmBucketSizeLog = 163,
|
||||
ZSTD_c_ldmHashRateLog = 164, ZSTD_c_contentSizeFlag = 200,
|
||||
ZSTD_c_checksumFlag = 201, ZSTD_c_dictIDFlag = 202, ZSTD_c_nbWorkers = 400,
|
||||
ZSTD_c_jobSize = 401, ZSTD_c_overlapLog = 402,
|
||||
ZSTD_c_experimentalParam1 = 500, ZSTD_c_experimentalParam2 = 10,
|
||||
ZSTD_c_experimentalParam3 = 1000, ZSTD_c_experimentalParam4 = 1001,
|
||||
ZSTD_c_experimentalParam5 = 1002, ZSTD_c_experimentalParam6 = 1003,
|
||||
ZSTD_c_experimentalParam7 = 1004, ZSTD_c_experimentalParam8 = 1005,
|
||||
ZSTD_c_experimentalParam9 = 1006, ZSTD_c_experimentalParam10 = 1007,
|
||||
ZSTD_c_experimentalParam11 = 1008, ZSTD_c_experimentalParam12 = 1009,
|
||||
ZSTD_c_experimentalParam13 = 1010, ZSTD_c_experimentalParam14 = 1011,
|
||||
ZSTD_c_experimentalParam15 = 1012);
|
||||
|
||||
ZSTD_compressionParameters = record
|
||||
windowLog: Cardinal;
|
||||
chainLogg: Cardinal;
|
||||
hashLogg: Cardinal;
|
||||
searchLogg: Cardinal;
|
||||
minMatchg: Cardinal;
|
||||
targetLengthg: Cardinal;
|
||||
strategy: ZSTD_strategy;
|
||||
end;
|
||||
|
||||
ZSTD_frameParameters = record
|
||||
contentSizeFlag: Integer;
|
||||
checksumFlag: Integer;
|
||||
noDictIDFlag: Integer;
|
||||
end;
|
||||
|
||||
ZSTD_parameters = record
|
||||
cParams: ZSTD_compressionParameters;
|
||||
fParams: ZSTD_frameParameters;
|
||||
end;
|
||||
|
||||
var
|
||||
ZSTD_compress: function(dst: Pointer; dstCapacity: size_t; const src: Pointer;
|
||||
srcSize: size_t; compressionLevel: Integer): size_t cdecl;
|
||||
ZSTD_decompress: function(dst: Pointer; dstCapacity: size_t;
|
||||
const src: Pointer; srcSize: size_t): SSIZE_T cdecl;
|
||||
ZSTD_findFrameCompressedSize: function(const src: Pointer; srcSize: size_t)
|
||||
: int64 cdecl;
|
||||
ZSTD_findDecompressedSize: function(const src: Pointer; srcSize: size_t)
|
||||
: int64 cdecl;
|
||||
ZSTD_createCCtx: function: Pointer cdecl;
|
||||
ZSTD_freeCCtx: function(cctx: Pointer): size_t cdecl;
|
||||
ZSTD_compressCCtx: function(cctx: Pointer; dst: Pointer; dstCapacity: size_t;
|
||||
src: Pointer; srcSize: size_t; compressionLevel: Integer): size_t cdecl;
|
||||
ZSTD_createDCtx: function: Pointer cdecl;
|
||||
ZSTD_freeDCtx: function(dctx: Pointer): size_t cdecl;
|
||||
ZSTD_decompressDCtx: function(dctx: Pointer; dst: Pointer;
|
||||
dstCapacity: size_t; src: Pointer; srcSize: size_t): size_t cdecl;
|
||||
ZSTD_createCDict: function(const dict: Pointer; dictSize: size_t;
|
||||
compressionLevel: Integer): Pointer cdecl;
|
||||
ZSTD_freeCDict: function(ddict: Pointer): size_t cdecl;
|
||||
ZSTD_createDDict: function(const dict: Pointer; dictSize: size_t)
|
||||
: Pointer cdecl;
|
||||
ZSTD_freeDDict: function(ddict: Pointer): size_t cdecl;
|
||||
ZSTD_compress_usingCDict: function(cctx: Pointer; dst: Pointer;
|
||||
dstCapacity: size_t; const src: Pointer; srcSize: size_t;
|
||||
const cdict: Pointer): size_t cdecl;
|
||||
ZSTD_decompress_usingDDict: function(dctx: Pointer; dst: Pointer;
|
||||
dstCapacity: size_t; const src: Pointer; srcSize: size_t;
|
||||
const ddict: Pointer): size_t cdecl;
|
||||
|
||||
ZSTD_getParams: function(compressionLevel: Integer; estimatedSrcSize: UInt64;
|
||||
dictSize: size_t): ZSTD_parameters cdecl;
|
||||
ZSTD_initCStream: function(zcs: Pointer; compressionLevel: Integer)
|
||||
: size_t cdecl;
|
||||
ZSTD_initCStream_advanced: function(zcs: Pointer; const dict: Pointer;
|
||||
dictSize: size_t; params: ZSTD_parameters; pledgedSrcSize: UInt64)
|
||||
: size_t cdecl;
|
||||
ZSTD_compressStream: function(zcs: Pointer; output: PZSTD_outBuffer;
|
||||
input: PZSTD_inBuffer): size_t cdecl;
|
||||
ZSTD_flushStream: function(zcs: Pointer; output: PZSTD_outBuffer)
|
||||
: size_t cdecl;
|
||||
ZSTD_endStream: function(zcs: Pointer; output: PZSTD_outBuffer): size_t cdecl;
|
||||
|
||||
ZSTD_createCCtxParams: function: PZSTD_CCtx_params cdecl;
|
||||
ZSTD_freeCCtxParams: function(params: PZSTD_CCtx_params): size_t cdecl;
|
||||
ZSTD_CCtxParams_reset: function(params: PZSTD_CCtx_params): size_t cdecl;
|
||||
ZSTD_CCtxParams_init: function(cctxParams: PZSTD_CCtx_params;
|
||||
compressionLevel: Integer): size_t cdecl;
|
||||
ZSTD_CCtx_setParameter: function(params: PZSTD_CCtx_params;
|
||||
param: ZSTD_cParameter; value: Integer): size_t cdecl;
|
||||
ZSTD_CCtx_setParametersUsingCCtxParams: function(cctx: Pointer;
|
||||
const params: PZSTD_CCtx_params): size_t cdecl;
|
||||
|
||||
ZSTD_CStreamInSize: function: size_t cdecl;
|
||||
ZSTD_CStreamOutSize: function: size_t cdecl;
|
||||
DLLLoaded: Boolean = False;
|
||||
|
||||
function ZSTD_compress_dict(cctx: Pointer; dst: Pointer; dstCapacity: size_t;
|
||||
const src: Pointer; srcSize: size_t; const cdict: Pointer): size_t;
|
||||
function ZSTD_decompress_dict(dctx: Pointer; dst: Pointer; dstCapacity: size_t;
|
||||
const src: Pointer; srcSize: size_t; const ddict: Pointer): size_t;
|
||||
|
||||
implementation
|
||||
|
||||
function ZSTD_compress_dict(cctx: Pointer; dst: Pointer; dstCapacity: size_t;
|
||||
const src: Pointer; srcSize: size_t; const cdict: Pointer): size_t;
|
||||
begin
|
||||
cctx := ZSTD_createDCtx;
|
||||
Result := ZSTD_compress_usingCDict(cctx, dst, dstCapacity, src,
|
||||
srcSize, cdict);
|
||||
ZSTD_freeDCtx(cctx);
|
||||
end;
|
||||
|
||||
function ZSTD_decompress_dict(dctx: Pointer; dst: Pointer; dstCapacity: size_t;
|
||||
const src: Pointer; srcSize: size_t; const ddict: Pointer): size_t;
|
||||
begin
|
||||
dctx := ZSTD_createDCtx;
|
||||
Result := ZSTD_decompress_usingDDict(dctx, dst, dstCapacity, src,
|
||||
srcSize, ddict);
|
||||
ZSTD_freeDCtx(dctx);
|
||||
end;
|
||||
|
||||
var
|
||||
DLLHandle: THandle;
|
||||
|
||||
procedure Init;
|
||||
begin
|
||||
if DLLLoaded then
|
||||
Exit;
|
||||
DLLHandle := LoadLibrary(PChar(ExtractFilePath(ParamStr(0)) + 'libzstd.dll'));
|
||||
if DLLHandle >= 32 then
|
||||
begin
|
||||
DLLLoaded := True;
|
||||
@ZSTD_compress := GetProcAddress(DLLHandle, 'ZSTD_compress');
|
||||
Assert(@ZSTD_compress <> nil);
|
||||
@ZSTD_decompress := GetProcAddress(DLLHandle, 'ZSTD_decompress');
|
||||
Assert(@ZSTD_decompress <> nil);
|
||||
@ZSTD_findFrameCompressedSize := GetProcAddress(DLLHandle,
|
||||
'ZSTD_findFrameCompressedSize');
|
||||
Assert(@ZSTD_findFrameCompressedSize <> nil);
|
||||
@ZSTD_findDecompressedSize := GetProcAddress(DLLHandle,
|
||||
'ZSTD_findDecompressedSize');
|
||||
Assert(@ZSTD_findDecompressedSize <> nil);
|
||||
@ZSTD_createCCtx := GetProcAddress(DLLHandle, 'ZSTD_createCCtx');
|
||||
Assert(@ZSTD_createCCtx <> nil);
|
||||
@ZSTD_freeCCtx := GetProcAddress(DLLHandle, 'ZSTD_freeCCtx');
|
||||
Assert(@ZSTD_freeCCtx <> nil);
|
||||
@ZSTD_createDCtx := GetProcAddress(DLLHandle, 'ZSTD_createDCtx');
|
||||
Assert(@ZSTD_createDCtx <> nil);
|
||||
@ZSTD_freeDCtx := GetProcAddress(DLLHandle, 'ZSTD_freeDCtx');
|
||||
Assert(@ZSTD_freeDCtx <> nil);
|
||||
@ZSTD_createCDict := GetProcAddress(DLLHandle, 'ZSTD_createCDict');
|
||||
Assert(@ZSTD_createCDict <> nil);
|
||||
@ZSTD_freeCDict := GetProcAddress(DLLHandle, 'ZSTD_freeCDict');
|
||||
Assert(@ZSTD_freeCDict <> nil);
|
||||
@ZSTD_compressCCtx := GetProcAddress(DLLHandle, 'ZSTD_compressCCtx');
|
||||
Assert(@ZSTD_compressCCtx <> nil);
|
||||
@ZSTD_createDDict := GetProcAddress(DLLHandle, 'ZSTD_createDDict');
|
||||
Assert(@ZSTD_createDDict <> nil);
|
||||
@ZSTD_freeDDict := GetProcAddress(DLLHandle, 'ZSTD_freeDDict');
|
||||
Assert(@ZSTD_freeDDict <> nil);
|
||||
@ZSTD_decompressDCtx := GetProcAddress(DLLHandle, 'ZSTD_decompressDCtx');
|
||||
Assert(@ZSTD_decompressDCtx <> nil);
|
||||
@ZSTD_compress_usingCDict := GetProcAddress(DLLHandle,
|
||||
'ZSTD_compress_usingCDict');
|
||||
Assert(@ZSTD_compress_usingCDict <> nil);
|
||||
@ZSTD_decompress_usingDDict := GetProcAddress(DLLHandle,
|
||||
'ZSTD_decompress_usingDDict');
|
||||
Assert(@ZSTD_decompress_usingDDict <> nil);
|
||||
|
||||
@ZSTD_getParams := GetProcAddress(DLLHandle, 'ZSTD_getParams');
|
||||
Assert(@ZSTD_getParams <> nil);
|
||||
@ZSTD_initCStream := GetProcAddress(DLLHandle, 'ZSTD_initCStream');
|
||||
Assert(@ZSTD_initCStream <> nil);
|
||||
@ZSTD_initCStream_advanced := GetProcAddress(DLLHandle,
|
||||
'ZSTD_initCStream_advanced');
|
||||
Assert(@ZSTD_initCStream_advanced <> nil);
|
||||
@ZSTD_compressStream := GetProcAddress(DLLHandle, 'ZSTD_compressStream');
|
||||
Assert(@ZSTD_compressStream <> nil);
|
||||
@ZSTD_flushStream := GetProcAddress(DLLHandle, 'ZSTD_flushStream');
|
||||
Assert(@ZSTD_flushStream <> nil);
|
||||
@ZSTD_endStream := GetProcAddress(DLLHandle, 'ZSTD_endStream');
|
||||
Assert(@ZSTD_endStream <> nil);
|
||||
|
||||
@ZSTD_CStreamInSize := GetProcAddress(DLLHandle, 'ZSTD_CStreamInSize');
|
||||
Assert(@ZSTD_CStreamInSize <> nil);
|
||||
@ZSTD_CStreamOutSize := GetProcAddress(DLLHandle, 'ZSTD_CStreamOutSize');
|
||||
Assert(@ZSTD_CStreamOutSize <> nil);
|
||||
|
||||
@ZSTD_createCCtxParams := GetProcAddress(DLLHandle,
|
||||
'ZSTD_createCCtxParams');
|
||||
Assert(@ZSTD_createCCtxParams <> nil);
|
||||
@ZSTD_freeCCtxParams := GetProcAddress(DLLHandle, 'ZSTD_freeCCtxParams');
|
||||
Assert(@ZSTD_freeCCtxParams <> nil);
|
||||
@ZSTD_CCtxParams_reset := GetProcAddress(DLLHandle,
|
||||
'ZSTD_CCtxParams_reset');
|
||||
Assert(@ZSTD_CCtxParams_reset <> nil);
|
||||
@ZSTD_CCtxParams_init := GetProcAddress(DLLHandle, 'ZSTD_CCtxParams_init');
|
||||
Assert(@ZSTD_CCtxParams_init <> nil);
|
||||
@ZSTD_CCtx_setParameter := GetProcAddress(DLLHandle,
|
||||
'ZSTD_CCtx_setParameter');
|
||||
Assert(@ZSTD_CCtx_setParameter <> nil);
|
||||
@ZSTD_CCtx_setParametersUsingCCtxParams :=
|
||||
GetProcAddress(DLLHandle, 'ZSTD_CCtx_setParametersUsingCCtxParams');
|
||||
Assert(@ZSTD_CCtx_setParametersUsingCCtxParams <> nil);
|
||||
end
|
||||
else
|
||||
DLLLoaded := False;
|
||||
end;
|
||||
|
||||
procedure Deinit;
|
||||
begin
|
||||
if not DLLLoaded then
|
||||
Exit;
|
||||
FreeLibrary(DLLHandle);
|
||||
end;
|
||||
|
||||
initialization
|
||||
|
||||
Init;
|
||||
|
||||
finalization
|
||||
|
||||
Deinit;
|
||||
|
||||
end.
|
Reference in New Issue
Block a user