LZO fast compress/decompress
Posted: Fri Mar 25, 2011 4:05 pm
i download the source from http://www.oberhumer.com/opensource/lzo/
made a lib with pellesC (from the mini_lzo files) and did some short testcode:
Result: very fast and good results for the speed of compression.
so i like to share my work now here .
Complete package (C-source,PellesC-Projectfile and Purebasic-Example) here
The C-code is portable, if anyone can port that also to linux&mac ?
made a lib with pellesC (from the mini_lzo files) and did some short testcode:
Result: very fast and good results for the speed of compression.
so i like to share my work now here .
Complete package (C-source,PellesC-Projectfile and Purebasic-Example) here
The C-code is portable, if anyone can port that also to linux&mac ?
Code: Select all
Import "LZO.lib"
;lzo_init.l()
;__lzo_init_v2(sizeofunsigned,int,int,int,int,int,int,int,int,int);
; #define lzo_init() __lzo_init_v2(LZO_VERSION,(int)SizeOf(short),(int)SizeOf(int),\
; (int)SizeOf(long),(int)SizeOf(lzo_uint32),(int)SizeOf(lzo_uint),\
; (int)lzo_sizeof_dict_t,(int)SizeOf(char *),(int)SizeOf(lzo_voidp),\
; (int)SizeOf(lzo_callback_t))
; LZO_EXTERN(int) __lzo_init_v2(unsigned,int,int,int,int,int,int,int,int,int);
__lzo_init_v2.l(version,SizeofShort,SizeofInt,SizeofLong,SizeofInt32,Sizeofuint,sizeofdict,sizeofchar,sizeofvoid,sizeofcallback)
lzo_initV2.l() ;my own
lzo_version_string.l()
lzo_version.l()
lzo_version_date.l()
lzo_copyright.l()
lzo1x_1_compress.l(in,in_len,out,out_len,wrkmem)
lzo1x_decompress(compressed,compressed_len,uncompressed,uncompressed_len,NULL);
EndImport
#LZO_E_ERROR =-1
#LZO_E_OK =0
; #define LZO_E_OUT_OF_MEMORY (-2) /* [Not used right now] */
; #define LZO_E_NOT_COMPRESSIBLE (-3) /* [Not used right now] */
; #define LZO_E_INPUT_OVERRUN (-4)
; #define LZO_E_OUTPUT_OVERRUN (-5)
; #define LZO_E_LOOKBEHIND_OVERRUN (-6)
; #define LZO_E_EOF_NOT_FOUND (-7)
; #define LZO_E_INPUT_NOT_CONSUMED (-8)
; #define LZO_E_NOT_YET_IMPLEMENTED (-9) /* [Not used right now] */
result=lzo_version_string()
If result
Debug "Version= " + PeekS(Result) ;debug version string
EndIf
result=lzo_version_date()
If result
Debug "Date=" + PeekS(Result) ;debug date string
EndIf
; result=lzo_version()
; Debug result
; result=lzo_copyright()
; If result
; Debug "Copyright ? " + PeekS(result) ;debug copyright
; EndIf
;result = lzo_init() ;init the lib
;result=lzo_init()
result=lzo_initV2()
If result<> #LZO_E_OK
Debug "init failed"
End
EndIf
a.s="Hello world , Hello Purebasic , Hi to the folks out there !"
a+a
a+a
pIn=@a
in_len=Len(A)
b.s=Space(Len(a)*2)
pOut=@b
out_len=0
wrkmem=AllocateMemory(16384 * 8) ;prepare a working buffer
result= lzo1x_1_compress(pIn,in_len,pOut,@out_len,wrkmem)
If result= #LZO_E_OK
Debug "compressed to " + Str(out_len)
c.s=Space(In_len)
result = lzo1x_decompress(pOut,Out,@c,@new_len,0);
Debug "Decpompressed lenght=" + Str(new_len)
Debug c
EndIf
;End
;Create a Bitmap (Screenshot)
Filename.s="c:\test.bmp"
ExamineDesktops()
w=DesktopWidth(0)
h=DesktopHeight(0)
res=CreateImage(1,w,h)
hDC = StartDrawing(ImageOutput(1))
hwnd=GetDesktopWindow_()
hwnd=0
;Debug hwnd
DC=GetDC_(hwnd)
BitBlt_(hDC, 0, 0, w, h, DC, x, y, #SRCCOPY)
StopDrawing()
SaveImage(1,Filename,#PB_ImagePlugin_BMP)
Result= ReadFile(0, Filename)
FileLength=FileSize(Filename)
BitMapData=AllocateMemory(FileLength)
Compressed=AllocateMemory(FileLength)
Readed= ReadData(0, BitMapData, FileLength)
Debug readed
t1=ElapsedMilliseconds()
result= lzo1x_1_compress(BitMapData,FileLength,Compressed,@out_len,wrkmem)
t2=ElapsedMilliseconds()
Debug "length compressed=" + Str(out_len) + " in " + Str(t2-T1) +" msecs"
t1=ElapsedMilliseconds()
result = lzo1x_decompress(Compressed,out_len,BitMapData,@new_len,0);
t2=ElapsedMilliseconds()
Debug "length decompressed=" + Str(new_len) + " in " + Str(t2-T1) +" msecs"
FreeMemory(BitMapData)
FreeMemory(Compressed)
FreeMemory(wrkmem)