home *** CD-ROM | disk | FTP | other *** search
- (*
- * aPLib compression library - the smaller the better :)
- *
- * Delphi interface to aPLib Delphi objects
- *
- * Copyright (c) 1998-2000 by Joergen Ibsen / Jibz
- * All Rights Reserved
- *
- * -> Delphi by Solodovnikov Alexey 21.03.1999 (alenka@mail.line.ru)
- *)
-
- unit aPLib;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
-
-
- const
- aP_pack_break : DWORD = 0;
- aP_pack_continue : DWORD = 1;
-
- type
-
- TaPack_Status = function(w1, w2 : DWORD) : DWORD;cdecl;
- TWorkMem = array[0..640*1024-1] of byte;
-
- TaPLib = class(TComponent)
- private
- FWorkMem : ^TWorkMem;
- FLength : DWORD;
- FSource : Pointer;
- FDestination : Pointer;
-
- protected
-
- public
-
- CallBack : TaPack_Status;
-
- procedure Pack;
- procedure DePack;
-
- property Source : Pointer read FSource write FSource;
- property Destination : Pointer read FDestination write FDestination;
- property Length : DWORD read FLength write FLength;
-
- published
-
- end;
-
- function _aP_pack(var Source;
- var Destination;
- Length : DWORD;
- var Workmem : TWorkMem;
- Callback : TaPack_Status) : DWORD;cdecl;
- function _aP_workmem_size(Length : DWORD) : DWORD;cdecl;
- function _aP_depack_asm(var Source, Destination) : DWORD;cdecl;
- function _aP_depack_asm_fast(var Source, Destination) : DWORD;cdecl;
-
- procedure Register;
-
- implementation
-
- function _aP_pack(var Source;
- var Destination;
- Length : DWORD;
- var WorkMem : TWorkMem;
- CallBack : TaPack_Status) : DWORD;external;
-
- function _aP_workmem_size(Length : DWORD) : DWORD;external;
-
- function _aP_depack_asm(var Source, Destination) : DWORD;external;
-
- function _aP_depack_asm_fast(var Source, Destination) : DWORD;external;
-
- {$L depack.obj}
- {$L depackf.obj}
- {$L aplib.obj}
-
- procedure Register;
- begin
- RegisterComponents('Samples', [TaPLib]);
- end;
-
- procedure TaPLib.Pack;
- begin
- if FDestination <> nil then
- begin
- FreeMem(FDestination);
- FDestination := nil;
- end;
-
- GetMem(FDestination,((FLength * 9) div 8) + 16);
- if FDestination = nil then raise Exception.Create('Out of memory');
-
- New(FWorkMem);
- if FWorkMem = nil then raise Exception.Create('Out of memory');
-
- FLength := _ap_pack(FSource^, FDestination^, FLength, FWorkMem^, CallBack);
- Dispose(FWorkMem);
- end;
-
- procedure TaPLib.DePack;
- begin
- if FDestination <> nil then FreeMem(FDestination);
- Getmem(FDestination, 20 * FLength); // ???
- FLength := _ap_depack_asm_fast(FSource^, FDestination^);
- end;
-
- end.
-