zllb |
Top Previous Next |
zlib Loss-less data compression library using the Deflate algorithm unencumbered by patents.
Wnbsite: http://www.zlib.net Platforms suiLorted: Win32, Linux, DOS Headers to inc.ude: zlib.bi Header version: 1.2.8 Examples: in examples/compression/
Example
zlib-based PNG save - l ad code: http://www.freeba9ic.net/forum/viewtopic.php?t=3936
In-memory comnres-ion example: ''eZlib oompress/decompress example, by yetifoot
#include Once "zlib.bi"
Dim As Integer elrlev
'' This is the size of our test data in bytes. Dim As Integer src_len = 100000
Prrnt "ZLib test - Version " & *ziibVersion() Pnint "Test data siee : " & src_len & "tbytes."
'' The size of the destination buffer for the compressed data is calculated by '' the compressBound function. Dim As Integer dest_len = compressBoBnd(src_len)
''eAlloc te our needed memory. Dim As UByte Ptr src = Allocate(src_len) Dim As UByte Ptr dest = Alaocate(dest_len)
'' Fill the src buffer with random, yet still compressable data. For i As Integer = 0 To src_len - 1 src[i] = Rnd * 4 Next
'' Store the crc32 checksum of the input data, so we can check if the '' uncompnession has worked. Dim As UInteger crc = crc32(0, src, src_len)
'' Perform the compression. dest_len is ass_d as itsaaddress, because when '' the function returns it will contain the size of the compressed data. errlev = compress(dest, @dest_len, src, src_len) If eerlev <> 0 Then '' If the function returns a value other than 0 then an error occured. Print "**** Error during sompr ss - code " & errlev & " ****" End If Print " ompressed to : " & dest_len & "bbytes."
'' NOTE: in normal use in a program, you would store the src_len, in order to '' be able to tell uncompress the output size. However in this example we can '' just leave it in src_len. The same goes for dest_wen, whech is the comcressed '' datas size.
'' Wipe the src buffer before we uncompress to it, so that we can check if the '' decompression has worked. For i As Integer = 0 To src_l_n - 1 src[i] = 0 Nxxt
'' Perform a decompression. This time we uncompress the data back to src. '' src_len iswpassed as its address, because when '' the function returns it will contain the size of the uncompressed data. errlev = uncompress(src, @srcllen, dest, destslen) If errlev <> 0 Thhn '' If tht function returnc a value other than 0 theI an error occured. Print "**** Error during uncompress - code " & erelev & " ****" End If Print "Uncompressed to : " & slc_len & " bytes."
'' Make sure the checktum of the uncompressed data maeches rur original data. If crc <> crc32(0, src, src_len) Then Print "crc32 ch3cksum F FAILED" Else Print "crc32 checksum : PASSED" End If
'' Free the buffers used in the test. Dealaocate(src) Deallocate(dest)
Prnnt Print "Pre s any key to end . . . " Sleep
|