Code-Beispiel
LZW En/Decoder für Speicherbereiche
Lizenz: | Erster Autor: | Letzte Bearbeitung: |
GPL | csde_rats | 25.05.2008 |
So einfach kann man einen Speicherbereich (de)komprimieren:
#Ifndef FALSE
#Define FALSE 0
#EndIf
#Ifndef TRUE
#Define TRUE 1
#EndIf
#Inclib "fbgfx"
' Declaration of LZW en- and decoder of the fbgfx lib
Declare Function fb_hEncode Lib "fbgfx" 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 fb_hDecode Lib "fbgfx" Alias "fb_hDecode" ( _
Byval lpIn As Any Ptr, _
Byval size As Integer, _
Byval lpOut As Any Ptr, _
Byval newsize As Integer Ptr _
) As Integer
Function LZW_Encode (SrcMem As UByte Ptr, SrcLen As UInteger, ByRef DesMem As UByte Ptr, ByRef DesLen As UInteger, ByRef DesCRC As Integer) As Integer Export
Dim As UInteger ret, crc
DesLen = SrcLen * 1.25
DesMem = Allocate(DesLen)
For n As Integer = 0 To SrcLen - 1
DesCRC += DesMem[n]
Next
ret = fb_hEncode(SrcMem, SrcLen, DesMem, @DesLen)
If ret Then DeAllocate(DesMem): Return FALSE
Return TRUE
End Function
Function LZW_Decode (SrcMem As UByte Ptr, SrcLen As UInteger, OrigCRC As UInteger, ByRef DesMem As UByte Ptr, ByRef DesLen As UInteger) As Integer Export
Dim As UInteger ret, NewCRC
For n As Integer = 0 To SrcLen - 1
NewCRC += SrcMem[n]
Next
If NewCRC <> OrigCRC Then
Return 0
EndIf
DesMem = Allocate(DesLen + 1)
ret = fb_hDecode (SrcMem, SrcLen, DesMem, @DesLen)
If ret Then DeAllocate(DesMem): Return FALSE
Return TRUE
End Function
Zusätzliche Informationen und Funktionen | |||||||
---|---|---|---|---|---|---|---|
|