ZLib Custom Build??

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
csde_rats
Posts: 114
Joined: Jun 02, 2007 21:13
Contact:

ZLib Custom Build??

Postby csde_rats » Sep 20, 2007 15:07

Hello!
I make use of the ZLib in one of my programs, but I only need the following functions:
  • zlibVersion()
  • compress()
  • compressbound()
  • uncompress
  • crc32()

Is it possible to create an custom build, which only contains the needed functions? Or its impossible, because the license does not allow this?
segin
Posts: 126
Joined: Dec 27, 2005 5:22
Contact:

Postby segin » Sep 20, 2007 16:11

It could be done, but it's not very smart. Most modern PCs have megabytes of memory, not kilobytes. zlib has a impact of ~200k, so it's really negligible.
csde_rats
Posts: 114
Joined: Jun 02, 2007 21:13
Contact:

Postby csde_rats » Sep 20, 2007 17:46

So the license allows this?

btw.
Its not because the memory, its because my webspace allows only files smarter than 1,5 MB, when I use another Librarys (like FreeImage or CryptLib), the Filesizelimitation don't allow an upload of the !!compressed!! File...

Ok, I have now downloaded the SourceCode of ZLib, but its too complex to me. :|
The DLL is only 56 KB in size, so I must not too much librarys use...
D.J.Peters
Posts: 7191
Joined: May 28, 2005 3:28

Postby D.J.Peters » Sep 20, 2007 18:04

You can use the LZW En/Decoder from GFXlib too
(the compresion ratio are not so good as zlib but no extra lib/dll are needed)

Joshy

Code: Select all

sub dummy ' it's only to include the en/decoder
 screen 0
end sub
Declare Function Encoder Alias "fb_hEncode" (Byval lpIn  As Any Ptr, Byval size    As Integer, _
                                            Byval lpOut As Any Ptr, Byval newsize As Integer Ptr) As  Integer

Declare Function Decoder Alias "fb_hDecode" (Byval lpIn  As Any Ptr, Byval size    As Integer, _
                                             Byval lpOut As Any Ptr, Byval newsize As Integer Ptr) As  Integer

Declare Function Encode(InFile As String,OutFile As String) As Integer
Declare Function Decode(InFile As String,OutFile As String) As Integer

Const FALSE = 0
Const TRUE  = NOT False

if Encode("Engine32.dll", "Engine32.pak")  then print " Encode ok"
if Decode("Engine32.pak", "2Engine32.dll") then print " Decode ok"
sleep
End

Function Encode(InFile As String,OutFile As String) As Integer
  Dim As Ubyte Ptr lpSrc,lpDes
  Dim As uInteger  des_len,src_len,ret,hFile,crc
  Dim as string    errmsg

  hFile=Freefile
  ret=Open(InFile For Binary Access Read As #hFile)
  if ret then
    ErrMsg = "open [" & InFile & "] !"
    goto CompressExit
  end if

  src_len=Lof(hFile)
  lpSrc  =Allocate(src_len)
  Get #hFile,,*lpSrc,src_len
  Close #hFile
 
  des_len=src_len*1.25
  lpDes  =Allocate(des_len)
  for ret=0 to src_len-1
    crc+=lpSrc[ret]
  next
 
  ret=Encoder(lpSrc, src_len,lpDes, @des_len)
  If ret Then
    errmsg = "can't compress [" & InFile & "] !"
    goto CompressExit
  End If
   
  hFile=Freefile
  ret=Open(OutFile For Binary Access Write As #hFile)
  If ret Then
    ErrMsg = "can't open [" & OutFile & "] !"
    goto CompressExit
  end if

  Put #hFile,,src_len
  Put #hFile,,des_len
  Put #hFile,,crc
  Put #hFile,,*lpDes,des_len
  Close #hFile
 
  CompressExit:
  if lpSrc then deallocate(lpSrc)
  if lpDes then deallocate(lpDes)
  if ret then
    beep:Print "Encode error: " & ErrMsg
    return false
  end if
  return true
End Function

Function Decode(InFile As String,OutFile As String) As Integer
  Dim As Ubyte Ptr lpSrc,lpDes
  Dim As uInteger  des_len,src_len,ret,hFile,crc,crcnew
  Dim as string    ErrMsg
       
  hFile=Freefile
  ret=Open(InFile For Binary Access Read As #hFile)
  If ret Then
    ErrMsg="can't read [" & InFile & "] !"
    goto DecompressExit
  end if

  Get #hFile,,src_len
  Get #hFile,,des_len
  Get #hFile,,crc
  lpSrc=Allocate(src_len)
  lpDes=Allocate(des_len)
  Get #hFile,,*lpDes,des_len
  Close #hFile
   
  ret=Decoder(lpDes,des_len,lpSrc,@src_len)
  If ret Then
    ErrMsg="can't uncompress [" & InFile & "] !"
    goto DecompressExit
  End If
  for ret=0 to src_len-1
    crcNew+=lpSrc[ret]
  next
  If crcNew<>crc Then
    ErrMsg= "crc is wrong " & crcNew & " !"
  end if
   
  hFile=Freefile
  ret=Open(OutFile For Binary Access Write As #hFile)
  If ret Then
    ErrMsg="can't write [" & OutFile & "] !"
    goto DecompressExit
  end if

  Put #hFile,,*lpDes,des_len
  Close #hFile
 
  DecompressExit:
  if lpSrc then Deallocate(lpSrc)
  if lpDes then Deallocate(lpDes)
  If ret Then
    beep:Print "Decode error: " & ErrMsg
    Return false
  End If
  Return true
end function
csde_rats
Posts: 114
Joined: Jun 02, 2007 21:13
Contact:

Postby csde_rats » Sep 20, 2007 18:06

I now about it, but I cannot use it, because I have no fbGFX-Screen or Console...
D.J.Peters
Posts: 7191
Joined: May 28, 2005 3:28

Postby D.J.Peters » Sep 20, 2007 18:08

csde_rats wrote:I now about it, but I cannot use it, because I have no fbGFX-Screen or Console...

you don't need it SCREEN 0 is only a dummy/placeholder to include the en/decoder you know.
csde_rats
Posts: 114
Joined: Jun 02, 2007 21:13
Contact:

Postby csde_rats » Sep 20, 2007 19:08

I now, but I !!cannot!! use the fbGFX Library in this Programm...
...or does a

Code: Select all

#inclib "fbGFX"

it??
D.J.Peters
Posts: 7191
Joined: May 28, 2005 3:28

Postby D.J.Peters » Sep 20, 2007 19:16

csde_rats wrote:...or does a #inclib "fbGFX" it??

yes this works too
(it's the same if fb reads a unused SCREEN or SCREENRES statement it will include the lib too)

Joshy

Code: Select all

#inclib "fbgfx"
Declare Function Encoder Alias "fb_hEncode" (Byval lpIn  As Any Ptr, Byval size    As Integer, _
                                            Byval lpOut As Any Ptr, Byval newsize As Integer Ptr) As  Integer

Declare Function Decoder Alias "fb_hDecode" (Byval lpIn  As Any Ptr, Byval size    As Integer, _
                                             Byval lpOut As Any Ptr, Byval newsize As Integer Ptr) As  Integer

Declare Function Encode(InFile As String,OutFile As String) As Integer
Declare Function Decode(InFile As String,OutFile As String) As Integer

Const FALSE = 0
Const TRUE  = NOT False

if Encode("Engine32.dll", "Engine32.pak")  then print " Encode ok"
if Decode("Engine32.pak", "2Engine32.dll") then print " Decode ok"
sleep
End

Function Encode(InFile As String,OutFile As String) As Integer
  Dim As Ubyte Ptr lpSrc,lpDes
  Dim As uInteger  des_len,src_len,ret,hFile,crc
  Dim as string    errmsg

  hFile=Freefile
  ret=Open(InFile For Binary Access Read As #hFile)
  if ret then
    ErrMsg = "open [" & InFile & "] !"
    goto CompressExit
  end if

  src_len=Lof(hFile)
  lpSrc  =Allocate(src_len)
  Get #hFile,,*lpSrc,src_len
  Close #hFile
 
  des_len=src_len*1.25
  lpDes  =Allocate(des_len)
  for ret=0 to src_len-1
    crc+=lpSrc[ret]
  next
 
  ret=Encoder(lpSrc, src_len,lpDes, @des_len)
  If ret Then
    errmsg = "can't compress [" & InFile & "] !"
    goto CompressExit
  End If

  hFile=Freefile
  ret=Open(OutFile For Binary Access Write As #hFile)
  If ret Then
    ErrMsg = "can't open [" & OutFile & "] !"
    goto CompressExit
  end if

  Put #hFile,,src_len
  Put #hFile,,des_len
  Put #hFile,,crc
  Put #hFile,,*lpDes,des_len
  Close #hFile
 
  CompressExit:
  if lpSrc then deallocate(lpSrc)
  if lpDes then deallocate(lpDes)
  if ret then
    beep:Print "Encode error: " & ErrMsg
    return false
  end if
  return true
End Function

Function Decode(InFile As String,OutFile As String) As Integer
  Dim As Ubyte Ptr lpSrc,lpDes
  Dim As uInteger  des_len,src_len,ret,hFile,crc,crcnew
  Dim as string    ErrMsg
       
  hFile=Freefile
  ret=Open(InFile For Binary Access Read As #hFile)
  If ret Then
    ErrMsg="can't read [" & InFile & "] !"
    goto DecompressExit
  end if

  Get #hFile,,src_len
  Get #hFile,,des_len
  Get #hFile,,crc
  lpSrc=Allocate(src_len)
  lpDes=Allocate(des_len)
  Get #hFile,,*lpDes,des_len
  Close #hFile
   
  ret=Decoder(lpDes,des_len,lpSrc,@src_len)
  If ret Then
    ErrMsg="can't uncompress [" & InFile & "] !"
    goto DecompressExit
  End If
  for ret=0 to src_len-1
    crcNew+=lpSrc[ret]
  next
  If crcNew<>crc Then
    ErrMsg= "crc is wrong " & crcNew & " !"
  end if
   
  hFile=Freefile
  ret=Open(OutFile For Binary Access Write As #hFile)
  If ret Then
    ErrMsg="can't write [" & OutFile & "] !"
    goto DecompressExit
  end if

  Put #hFile,,*lpSrc,src_len
  Close #hFile
 
  DecompressExit:
  if lpSrc then Deallocate(lpSrc)
  if lpDes then Deallocate(lpDes)
  If ret Then
    beep:Print "Decode error: " & ErrMsg
    Return false
  End If
  Return true
end function
Last edited by D.J.Peters on Sep 20, 2007 19:33, edited 1 time in total.
csde_rats
Posts: 114
Joined: Jun 02, 2007 21:13
Contact:

Postby csde_rats » Sep 20, 2007 19:24

Ahh, now I undestand xD.
Hmm, but your code does not work properly: it compresses the file from 227 KB to 203 KB, but the decompressed file is altough 203 KB big, and an exact copy of the compressed file...
D.J.Peters
Posts: 7191
Joined: May 28, 2005 3:28

Postby D.J.Peters » Sep 20, 2007 19:38

looks line 110 was wrong
Put #hFile,,*lpDes,des_len
must be
Put #hFile,,*lpSrc,src_len

but your compression ratio for dll's are bad
use zlib and 50kb extra lib should be not a problem
csde_rats
Posts: 114
Joined: Jun 02, 2007 21:13
Contact:

Postby csde_rats » Sep 20, 2007 20:17

Yes, so I do it with zlib 1.23 :)
Antoni
Posts: 1393
Joined: May 27, 2005 15:40
Location: Barcelona, Spain

Postby Antoni » Nov 01, 2007 11:03

joshy:
The decode function requires more than correcting the PUT line, the Decoder is called before actually reading the packed file. This version works:

Code: Select all

sub dummy ' it's only to include the en/decoder
 Screen 0
End Sub
Declare Function Encoder Alias "fb_hEncode" (Byval lpIn  As Any Ptr, Byval size    As Integer, _
                                            Byval lpOut As Any Ptr, Byval newsize As Integer Ptr) As  Integer

Declare Function Decoder Alias "fb_hDecode" (Byval lpIn  As Any Ptr, Byval size    As Integer, _
                                             Byval lpOut As Any Ptr, Byval newsize As Integer Ptr) As  Integer

Declare Function Encode(InFile As String,OutFile As String) As Integer
Declare Function Decode(InFile As String,OutFile As String) As Integer

Const FALSE = Cast(Integer,0)
Const TRUE  = Cast(Integer,Not FALSE)


If Encode("lzw.bas", "lzw.pak")  Then Print " Encode ok"
If Decode("lzw.pak", "2lzw.bas") Then Print " Decode ok"
Sleep
End

Function Encode(InFile As String,OutFile As String) As Integer
  Dim As Ubyte Ptr lpSrc,lpDes
  Dim As Uinteger  des_len,src_len,ret,hFile,crc
  Dim As String    errmsg

  hFile=Freefile
  ret=Open(InFile For Binary Access Read As #hFile)
  If ret Then
    ErrMsg = "open [" & InFile & "] !"
    Goto CompressExit
  End If

  src_len=Lof(hFile)
  lpSrc  =Allocate(src_len)
  Get #hFile,,*lpSrc,src_len
  Close #hFile
 
  des_len=src_len*1.25
  lpDes  =Allocate(des_len)
  For ret=0 To src_len-1
    crc+=lpSrc[ret]
  Next
 
  ret=Encoder(lpSrc, src_len,lpDes, @des_len)
  If ret Then
    errmsg = "can't compress [" & InFile & "] !"
    Goto CompressExit
  End If
   
  hFile=Freefile
  ret=Open(OutFile For Binary Access Write As #hFile)
  If ret Then
    ErrMsg = "can't open [" & OutFile & "] !"
    Goto CompressExit
  End If

  Put #hFile,,src_len
  Put #hFile,,des_len
  Put #hFile,,crc
  Put #hFile,,*lpDes,des_len
  Close #hFile
 
  CompressExit:
  If lpSrc Then deallocate(lpSrc)
  If lpDes Then deallocate(lpDes)
  If ret Then
    Beep:Print "Encode error: " & ErrMsg
    Return 0
  End If
  Return -1
End Function

Function Decode(InFile As String,OutFile As String) As Integer
  Dim As Ubyte Ptr lpSrc,lpDes
  Dim As Uinteger  des_len,src_len,ret,hFile,crc,crcnew
  Dim As String    ErrMsg
       
  hFile=Freefile
  ret=Open(InFile For Binary Access Read As #hFile)
  If ret Then
    ErrMsg="can't read [" & InFile & "] !"
    Goto DecompressExit
  End If

  Get #hFile,,des_len
  Get #hFile,,src_len
  Get #hFile,,crc
  lpSrc=Allocate(src_len+1)
  lpDes=Allocate(des_len+1)
  Get #hFile,,*lpsrc,src_len
  Close #hFile
   
 
  For ret=0 To src_len-1
    crcNew+=lpSrc[ret]
  Next
  If crcNew<>crc Then
    ErrMsg= "crc is wrong " & crcNew & " !"
  End If
   
  hFile=Freefile
  ret=Open(OutFile For Binary Access Write As #hFile)
  If ret Then
    ErrMsg="can't write [" & OutFile & "] !"
    Goto DecompressExit
  End If
  ?src_len/des_len *100 &"%"

 
  ret=Decoder(lpSrc,src_len,lpDes,@des_len)
  if ret Then
    ErrMsg="can't uncompress [" & InFile & "] !"
    Goto DecompressExit
  End If
 
 
  Put #hFile,,*lpDes,des_len
  Close #hFile
 
  DecompressExit:
  If lpSrc Then Deallocate(lpSrc)
  If lpDes Then Deallocate(lpDes)
  If ret Then
    Beep:Print "Decode error: " & ErrMsg
    Return 0
  End If
  Return -1
End Function
Last edited by Antoni on Nov 16, 2007 14:19, edited 1 time in total.
D.J.Peters
Posts: 7191
Joined: May 28, 2005 3:28

Postby D.J.Peters » Nov 01, 2007 11:15

removed (i was drunken last day of my holyday's)
Last edited by D.J.Peters on Nov 10, 2007 17:37, edited 1 time in total.
marcov
Posts: 2406
Joined: Jun 16, 2005 9:45
Location: Eindhoven, NL
Contact:

Postby marcov » Nov 01, 2007 11:19

segin wrote:It could be done, but it's not very smart. Most modern PCs have megabytes of memory, not kilobytes. zlib has a impact of ~200k, so it's really negligible.


Aside from the fact that unused pages are wired, not loaded and might not even be in memory.

P.s. why not translate zlib to Basic? We have a Pascal version of zlib around for static linking.
Antoni
Posts: 1393
Joined: May 27, 2005 15:40
Location: Barcelona, Spain

Postby Antoni » Nov 01, 2007 11:24

LOL
I guess it sounds bad in german too...

Return to “Libraries”

Who is online

Users browsing this forum: No registered users and 0 guests