delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
500 Users Online NOW
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback





Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi



Loremo - the 1.5 liter car coming in 2009




Startblatt.de






Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (1)


Using miniLZO in DelphiComponent available for this articleFormat this article printer-friendly!Bookmark function is only available for registered users!
Product:
Delphi all versions
Category:
Algorithm
Skill Level:
Scoring:
Last Update:
02/01/2002
Search Keys:
delphi delphi3000 article borland vcl code-snippet LZO miniLZO compression decompression link obj
Times Scored:
3
Visits:
2553
Uploader: dan strandberg
Company:
Reference: N/A
Component Download: http://danstr.stud.hive.no/delphi/delphi-minilzo.zip
 
Question/Problem/Abstract:
How to use the miniLZO library written in ANSI C in your delphi application without a dll
Answer:



Introduction
LZO is a lossless compression algorithm that offers EXTREMELY fast decompression speed while giving you a decent compression ratio. I've read that LZO is twice as fast as ZLib at decompressing while only have about 5% less compression ratio.

miniLZO
Is a library from the author of LZO that includes LZO1X_1 compression and LZO1x decompression. I've compiled it to an .obj file that can be linked into a delphi unit using the {$LINK}/{$L} compiler directive. Below you'll find the complete unit. miniLZO is distributed under the GNU Public License, so naturally this code is GNU licensed too. Note, for detailed instructions on how to USE these functions please visit the official LZO homepage at http://www.oberhumer.com/opensource/lzo/.

//------------------------- BEGIN UNIT -------------------------//
unit Lzo;

interface

// "C" routines needed by the linked LZO OBJ file
function _memcmp (s1,s2: Pointer; numBytes: LongWord): integer; cdecl;
procedure _memcpy (s1, s2: Pointer; n: Integer); cdecl;
procedure _memmove(dstP, srcP: pointer; numBytes: LongWord); cdecl;
procedure _memset (s: Pointer; c: Byte; n: Integer); cdecl;

{$LINK 'minilzo.obj'}

function lzo1x_1_compress(const Source: Pointer; SourceLength: LongWord; Dest: Pointer; var DestLength: LongWord; WorkMem: Pointer): integer; stdcall; external;
function lzo1x_decompress(const Source: Pointer; SourceLength: LongWord; Dest: Pointer; var DestLength: LongWord; WorkMem: Pointer (* NOT USED! *)): Integer; stdcall; external;
function lzo1x_decompress_safe(const Source: Pointer; SourceLength: LongWord; Dest: Pointer; var DestLength: LongWord; WorkMem: Pointer (* NOT USED! *)): Integer; stdcall; external;
function lzo_adler32(Adler: LongWord; const Buf: Pointer; Len: LongWord): LongWord; stdcall; external;
function lzo_version: word; stdcall; external;
function lzo_version_string: PChar; stdcall; external;
function lzo_version_date: PChar; stdcall; external;

implementation

procedure _memset(s: Pointer; c: Byte; n: Integer); cdecl;
begin
  FillChar(s^, n, c);
end;

procedure _memcpy(s1, s2: Pointer; n: Integer); cdecl;
begin
  Move(s2^, s1^, n);
end;

function _memcmp (s1, s2: Pointer; numBytes: LongWord): integer; cdecl;
var
  i: integer;
  p1, p2: ^byte;
begin
  p1 := s1;
  p2 := s2;
  for i := 0 to numBytes -1 do
  begin
    if p1^ <> p2^ then
    begin
      if p1^ < p2^ then
        Result := -1
      else
        Result := 1;
      exit;
    end;
    inc(p1);
    inc(p2);
  end;
  Result := 0;
end;

procedure _memmove(dstP, srcP: pointer; numBytes: LongWord); cdecl;
begin
  Move(srcP^, dstP^, numBytes);
  FreeMem(srcP, numBytes);
end;

end.

//------------------------- END UNIT -------------------------//


The C miniLZO source, minilzo.obj and this unit can be downloade from here.

That's it! I appologize for my somtimes bad english and writing style.





Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment
the link!!!
    denitsa il (Sep 20 2005 8:34PM)

Please provide a valid link!!!
Respond














 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
I. Siticov
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)