|
|
|
Click here to copy the following block | Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (dest As _ Any, source As Any, ByVal Bytes As Long)
Function RLECompress(ByVal address As Long, ByVal Bytes As Long, _ outBuffer() As Byte, Optional ByVal ItemSize As Integer = 2) As Boolean If ItemSize <> 1 And ItemSize <> 2 And ItemSize <> 4 And ItemSize <> 8 Then Err.Raise 5, , "Wrong value for ItemSize" End If If (Bytes Mod ItemSize) Then Err.Raise 5, , "Bytes must be a multiple of ItemSize" End If If Bytes < 64 Then Err.Raise 5, , "Bytes must be > 64" End If ReDim outBuffer(0 To Bytes - 1) As Byte Dim i As Long Dim outIndex As Long Dim prevValue As Currency Dim currValue As Currency Dim matchCount As Integer CopyMemory outBuffer(0), &HABCD, 2 CopyMemory outBuffer(2), ItemSize, 2 CopyMemory outBuffer(4), Bytes, 4 CopyMemory prevValue, ByVal address, ItemSize address = address + ItemSize CopyMemory outBuffer(8), prevValue, ItemSize outIndex = 8 + ItemSize For i = 2 To Bytes \ ItemSize CopyMemory currValue, ByVal address, ItemSize address = address + ItemSize If prevValue <> currValue Then If matchCount Then If outIndex + 2 >= Bytes Then Exit Function CopyMemory outBuffer(outIndex), matchCount, 2 outIndex = outIndex + ItemSize matchCount = 0 End If If outIndex + ItemSize >= Bytes Then Exit Function CopyMemory outBuffer(outIndex), currValue, ItemSize outIndex = outIndex + ItemSize prevValue = currValue ElseIf matchCount = 0 Then If outIndex + ItemSize >= Bytes Then Exit Function CopyMemory outBuffer(outIndex), currValue, ItemSize outIndex = outIndex + ItemSize matchCount = 2 ElseIf matchCount = 32767 Then If outIndex + 2 >= Bytes Then Exit Function CopyMemory outBuffer(outIndex), matchCount, 2 outIndex = outIndex + ItemSize matchCount = 2 Else matchCount = matchCount + 1 End If Next If matchCount Then If outIndex + 2 >= Bytes Then Exit Function CopyMemory outBuffer(outIndex), matchCount, 2 outIndex = outIndex + ItemSize End If ReDim Preserve outBuffer(0 To outIndex - 1) As Byte RLECompress = True
End Function |
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|