Lampiran a Listing Program
Total Page:16
File Type:pdf, Size:1020Kb
LAMPIRAN A LISTING PROGRAM Private Sub Command3_Click() If UBound(OriginalArray) = 0 Then Exit Sub End MsgBox "There is nothing to End If compress/Decompress" End Sub Else Exit Sub LastCoder = WichCompressor End If Private Sub compress_Click() End If If AutoDecodeIsOn = False Then m1.Visible = True Call Copy_Orig2Work decompress = True m2.Visible = True LastDeCoded = decompress If CompDecomp = 0 Then Exit Sub End Sub If JustLoaded = True Then If CompDecomp = 1 Then decompress = False JustLoaded = False Else Private Sub d1_Click() ReDim UsedCodecs(0) decompress = True CompDecomp = 2 End If End If Dim wktmulai As Single compression.MousePointer = If decompress = True Then MousePointerConstants.vbHourglass Dim decompress As Boolean LastUsed = wktmulai = Timer Dim Dummy As Boolean UsedCodecs(UBound(UsedCodecs)) Call DeCompress_arithmetic_Dynamic(hasil) Dim StTime As Double If JustLoaded = True Then LastUsed = 0 Label12.Caption = Timer - wktmulai & " detik" Dim Text As String If WichCompressor <> LastUsed Then compression.MousePointer = Dim LastUsed As Integer Text = "This is not compressed with ." & MousePointerConstants.vbDefault Chr(13) Call Show_Statistics(False, hasil) MsgBox Text A-1 Call afterContent(hasil) If AutoDecodeIsOn = False Then End If compression.save.Visible = True decompress = True Call Copy_Orig2Work d1.Visible = False If CompDecomp = 0 Then Exit Sub LastDeCoded = decompress d2.Visible = False If CompDecomp = 1 Then decompress = False If JustLoaded = True Then End Sub Else JustLoaded = False decompress = True ReDim UsedCodecs(0) Private Sub d2_Click() End If End If CompDecomp = 2 If decompress = True Then compression.MousePointer = MousePointerConstants.vbHourglass Dim wktmulai As Single LastUsed = UsedCodecs(UBound(UsedCodecs)) wktmulai = Timer Dim decompress As Boolean If JustLoaded = True Then LastUsed = 0 Call DeCompress_ReducerDynamicGol(hasil) Dim Dummy As Boolean If WichCompressor <> LastUsed Then Label12.Caption = Timer - wktmulai & " detik" Dim StTime As Double Text = "This is not compressed with ." & compression.MousePointer = Dim Text As String Chr(13) MousePointerConstants.vbDefault Dim LastUsed As Integer MsgBox Text Call Show_Statistics(False, hasil) If UBound(OriginalArray) = 0 Then Exit Sub Call afterContent(hasil) MsgBox "There is nothing to End If compression.save.Visible = True compress/Decompress" Else d1.Visible = False Exit Sub LastCoder = WichCompressor d2.Visible = False End If A-2 End Sub Dim Text As String Text = "This is not compressed with ." & Chr(13) Dim LastUsed As Integer MsgBox Text Private Sub Form_Load() If UBound(OriginalArray) = 0 Then Exit Sub Dim X As Integer MsgBox "There is nothing to compress/Decompress" End If Dim Y As Integer Exit Sub Else Dim MaxWidth As Double End If LastCoder = WichCompressor ReDim OriginalArray(0) If AutoDecodeIsOn = False Then End If ReDim hasil(0) decompress = True Call Copy_Orig2Work ReDim UsedCodecs(0) If CompDecomp = 0 Then Exit Sub LastDeCoded = decompress CompDecomp = 0 If CompDecomp = 1 Then decompress = False If JustLoaded = True Then End Sub Else JustLoaded = False decompress = True ReDim UsedCodecs(0) Private Sub m1_Click() End If End If CompDecomp = 1 If decompress = True Then compression.MousePointer = Dim wktmulai As Single MousePointerConstants.vbHourglass LastUsed = Dim decompress As Boolean UsedCodecs(UBound(UsedCodecs)) wktmulai = Timer Dim Dummy As Boolean If JustLoaded = True Then LastUsed = 0 Call Compress_arithmetic_Dynamic(hasil) Dim StTime As Double If WichCompressor <> LastUsed Then Label12.Caption = Timer - wktmulai & " detik" A-3 compression.MousePointer = MsgBox "There is nothing to End If MousePointerConstants.vbDefault compress/Decompress" Else Call Show_Statistics(False, hasil) Exit Sub LastCoder = WichCompressor Call afterContent(hasil) End If End If compression.save.Visible = True If AutoDecodeIsOn = False Then Call Copy_Orig2Work m1.Visible = False decompress = True LastDeCoded = decompress m2.Visible = False If CompDecomp = 0 Then Exit Sub If JustLoaded = True Then End Sub If CompDecomp = 1 Then decompress = False JustLoaded = False Else ReDim UsedCodecs(0) Private Sub m2_Click() decompress = True End If CompDecomp = 1 End If compression.MousePointer = Dim wktmulai As Single If decompress = True Then MousePointerConstants.vbHourglass Dim decompress As Boolean LastUsed = wktmulai = Timer UsedCodecs(UBound(UsedCodecs)) Dim Dummy As Boolean Call Compress_ReducerDynamicGol(hasil) If JustLoaded = True Then LastUsed = 0 Dim StTime As Double Label12.Caption = Timer - wktmulai & " detik" If WichCompressor <> LastUsed Then Dim Text As String compression.MousePointer = Text = "This is not compressed with ." & MousePointerConstants.vbDefault Dim LastUsed As Integer Chr(13) Call Show_Statistics(False, hasil) If UBound(OriginalArray) = 0 Then MsgBox Text Exit Sub A-4 Call afterContent(hasil) Private Sub Decompress_Click() Buffer As Integer compression.save.Visible = True d1.Visible = True BitPos As Integer m1.Visible = False d2.Visible = True End Type m2.Visible = False End Sub Private Stream(1) As BytePos '0=control 1=BitStreams End Sub Private Sub Save_Click() Private CharCount(256) As Long Private Sub open_Click() Call Save_File_As(hasil, False) Private Dictionary As String Dim OldFileName As String End Sub Private BitsForHeader As Integer '1=max 6 chars OldFileName = LoadFileName 2=max 30 chars 3=more then 30 chars Cdlg.DialogTitle = "Select the file you want to Private Golomb(8) As Integer explore" GOLOMB Private RetGolomb(15) As Integer Cdlg.FileName = "" Option Explicit Private BitsToFollow(8) As Integer Cdlg.ShowOpen Public Sub LoadFileName = Cdlg.FileName Compress_ReducerDynamicGol(ByteArray() As 'This is a 1 run method but we have to keep the Byte) Call load_File(LoadFileName) whole contents Dim X As Long If LoadFileName = "" Then LoadFileName = 'in memory until some variables are saved wich are OldFileName needed bij the decompressor Dim Y As Long Call Show_Contents(OriginalArray) Private Type BytePos Dim NoMore As Boolean End Sub Data() As Byte Dim Most As Long Position As Long Dim NewFileLen As Long A-5 Dim Nuchar As Byte ReDim Preserve ByteArray(NewFileLen) = Stream(X).Data(Stream(X).Position - 1) UBound(Stream(X).Data) And &HFF Dim CharCount(255) As Long Next NewFileLen = NewFileLen + 1 Call Init_ReducerDynamicGol 'whe calculate the new length of the new data Next 'whe only read the stream and convert them to bitstreams NewFileLen = 0 For X = 0 To 1 For X = 0 To UBound(ByteArray) For X = 0 To 1 For Y = 0 To UBound(Stream(X).Data) Call AddValueToStream(CInt(ByteArray(X))) NewFileLen = NewFileLen + ByteArray(NewFileLen) = Stream(X).Data(Y) UBound(Stream(X).Data) + 1 Next NewFileLen = NewFileLen + 1 Next 'send the EOF-marker Next ReDim ByteArray(NewFileLen + 3) Call AddValueToStream(256) Next 'here we store the compressed data 'lets fill the leftovers End Sub NewFileLen = 0 For X = 0 To 1 Public Sub For X = 0 To 0 DeCompress_ReducerDynamicGol(ByteArray() As Do While Stream(X).BitPos > 0 Byte) ByteArray(NewFileLen) = Call AddBitsToStream(Stream(X), 0, 1) (UBound(Stream(X).Data) And &HFF0000) / Dim OutStream() As Byte &H10000 Loop Dim OutPos As Long NewFileLen = NewFileLen + 1 Next Dim InposCont As Long ByteArray(NewFileLen) = 'Lets restore the bounderies (UBound(Stream(X).Data) And &HFF00) / &H100 Dim InContBit As Integer For X = 0 To 1 NewFileLen = NewFileLen + 1 Dim InposData As Long Dim InDataBit As Integer A-6 Dim Char As Integer Temp = 0 End Sub Dim NumBits As Integer Temp = Temp * 2 + ReadBitsFromArray(ByteArray, InposCont, Dim X As Long InContBit, 2) Private Sub Init_ReducerDynamicGol() Dim Temp As Byte Do While RetGolomb(Temp) = 0 Dim X As Integer ReDim OutStream(500) Temp = Temp * 2 + Dictionary = "" ReadBitsFromArray(ByteArray, InposCont, Call Init_ReducerDynamicGol InContBit, 1) For X = 0 To 255 InposCont = 0 Loop Dictionary = Dictionary & Chr(X) InposData = 0 NumBits = RetGolomb(Temp) CharCount(X) = 0 For X = 0 To 2 Char = ReadBitsFromArray(ByteArray, Next InposData, InDataBit, NumBits) InposData = CLng(InposData) * 256 + CharCount(256) = 0 ByteArray(InposCont) Char = ExpanderBits(NumBits, Char) BitsForHeader = 3 InposCont = InposCont + 1 If Char = 256 Then Exit Do For X = 0 To 1 Next Call AddCharToArray(OutStream, OutPos, CByte(Char)) ReDim Stream(X).Data(500) InposData = InposData + InposCont + 1 Loop Stream(X).BitPos = 0 InContBit = 0 ReDim ByteArray(OutPos - 1) Stream(X).Buffer = 0 InDataBit = 0 For X = 0 To OutPos - 1 Stream(X).Position = 0 OutPos = 0 ByteArray(X) = OutStream(X) Next Do Next Golomb(1) = 0: BitsToFollow(1) = 2 '00 NumBits = 0 A-7 Golomb(2) = 1: BitsToFollow(2) = 2 '01 End Sub End Function Golomb(3) = 4: BitsToFollow(3) = 3 '100 Golomb(4) = 5: BitsToFollow(4) = 3 '101 Private Function ReducerBits(Char As Integer) As Private Function ExpanderBits(BitsNum As Integer, Integer BytePos As Integer) As Integer Golomb(5) = 12: BitsToFollow(5) = 4 '1100 Dim DiPos As Integer If BitsNum = 8 And BytePos = 255 Then Golomb(6) = 13: BitsToFollow(6) = 4 '1101 ExpanderBits = 256: Exit Function Dim TotPos As Integer Golomb(7) = 14: BitsToFollow(7) = 4 '1110 Dim TotPos As Integer Dim Y As Integer Golomb(8) = 15: BitsToFollow(8) = 4 '1111 Dim Y As Integer If Char = 256 Then ReducerBits = 8: Char = 255: For X = 0 To 15 Exit Function For Y = 1 To BitsNum - 1 RetGolomb(X) = 0 DiPos = InStr(Dictionary, Chr(Char)) - 1 TotPos = TotPos + 2 ^ Y Next Call update_Model(Char) Next RetGolomb(0) = 1 For Y = 1 To 8 TotPos = TotPos + BytePos + 1 RetGolomb(1) = 2 If DiPos >= TotPos And DiPos < TotPos + 2 ^ ExpanderBits